[ { "hash": "50878542380ce58b3cbdc52edac980eee5d885ce", "msg": "Fixed docstring (line-break problem)", "author": { "name": "edschofield", "email": "edschofield@localhost" }, "committer": { "name": "edschofield", "email": "edschofield@localhost" }, "author_date": "2005-10-25T19:26:26+00:00", "author_timezone": 0, "committer_date": "2005-10-25T19:26:26+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "5defd06d9d40ea13fecadc9bbcd91cc1d7be6324" ], "project_name": "repo_copy", "project_path": "/tmp/tmpn4cqam_6/repo_copy", "deletions": 11, "insertions": 11, "lines": 22, "files": 1, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "scipy/base/src/arrayobject.c", "new_path": "scipy/base/src/arrayobject.c", "filename": "arrayobject.c", "extension": "c", "change_type": "MODIFY", "diff": "@@ -627,9 +627,9 @@ PyArray_CopyInto(PyArrayObject *dest, PyArrayObject *src)\n \tif (ssize == 0) return 0;\n if (dsize % ssize != 0) {\n PyErr_SetString(PyExc_ValueError, \n- \"destination number of elements must be\"\\\n- \"an integer multiple of the source number of\"\\\n- \"elements\");\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@@ -1097,8 +1097,8 @@ PyArray_ToList(PyArrayObject *self)\n v=(PyArrayObject *)array_item(self, i);\n \t\tif (v->nd >= 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+\t\t\t\t\t\"array_item not returning smaller-\" \\\n+\t\t\t\t\t\"dimensional array\");\n \t\t\tPy_DECREF(lp);\n \t\t\treturn NULL;\n \t\t}\n@@ -3167,8 +3167,8 @@ PyArray_New(PyTypeObject *subtype, int nd, intp *dims, int type_num,\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\t\t\t\"negative dimensions \"\t\\\n+\t\t\t\t\t\"are not allowed\");\n \t\t\treturn NULL;\n \t\t}\n \t}\n@@ -3649,7 +3649,7 @@ array_flags_set(PyArrayObject *self, PyObject *obj)\n else {\n \t\t\t\tself->flags = flagback;\n PyErr_SetString(PyExc_ValueError, \n- \"cannot set UPDATEIFCOPY\" \\\n+ \"cannot set UPDATEIFCOPY \" \\\n \"flag to True\");\n return -1;\n }\n@@ -3838,7 +3838,7 @@ array_data_set(PyArrayObject *self, PyObject *op)\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\"object does not have single-segment \" \\\n \t\t\t\t\t\"buffer interface\");\n \t\t\treturn -1;\n \t\t}\n@@ -5280,8 +5280,8 @@ array_frominterface(PyObject *input, PyArray_Typecode *intype, int flags)\n \t\tif (PyTuple_GET_SIZE(attr) != 2) {\n \t\t\tPy_DECREF(attr);\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\"__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\treturn NULL;\n \t\t}\n", "added_lines": 11, "deleted_lines": 11, "source_code": " /*\n Provide multidimensional arrays as a basic object type in python. \n\nBased on Original Numeric implementation\nCopyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\nwith contributions from many Numeric Python developers 1995-2004 *\n\nHeavily modified in 2005 with inspiration from Numarray \n\nby\n\nTravis Oliphant\nAssistant Professor at\nBrigham Young University \n\nmaintainer email: oliphant.travis@ieee.org\n\nNumarray design (which provided guidance) by \nSpace Science Telescope Institute \n (J. Todd Miller, Perry Greenfield, Rick White)\n\n*/\n\n/* $Id: arrayobject.c,v 1.59 2005/09/14 00:14:00 teoliphant Exp $ */\n\n/*\n#include \"Python.h\"\n#include \"structmember.h\"\n\n#define _MULTIARRAYMODULE\n#include \"Numeric3/arrayobject.h\"\n*/\n\n/* Helper functions */\n\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\n\nstatic intp\nPyArray_PyIntAsIntp(PyObject *o)\n{\n\tlonglong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr=NULL;\n\tPyArray_Typecode typecode = {PyArray_INTP, 0, 0};\n\tintp ret;\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\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\tarr = PyArray_CastToType((PyArrayObject *)o, &typecode);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tarr = PyArray_FromScalar(o, &typecode);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((intp *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\t\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONGLONG != SIZEOF_PY_INTPTR_T)\n\tif ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C intp\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (intp) long_value;\n}\n\n\nstatic PyObject *array_int(PyArrayObject *v);\n\nstatic int\nPyArray_PyIntAsInt(PyObject *o)\n{\n\tlong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr=NULL;\n\tPyArray_Typecode typecode = {PyArray_INT, 0, 0};\n\tint ret;\n\t\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\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\tarr = PyArray_CastToType((PyArrayObject *)o, &typecode);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tarr = PyArray_FromScalar(o, &typecode);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((int *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONG != SIZEOF_INT)\n\tif ((long_value < INT_MIN) || (long_value > INT_MAX)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C int\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (int) long_value;\n}\n\n\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\nstatic char *\nPyArray_Zero(PyArrayObject *arr)\n{\n char *zeroval;\n char *buf;\n int buf_len;\n PyObject *obj, *ret;\n\n zeroval = PyDataMem_NEW(arr->itemsize);\n if (zeroval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n if (PyArray_ISOBJECT(arr)) {\n obj=PyInt_FromLong((long) 0);\n memcpy(zeroval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return zeroval;\n }\n ret = PyObject_GetAttrString((PyObject *)arr, \"_zero\");\n if (ret != NULL) {\n if (PyObject_AsReadBuffer(ret, (const void **)&buf, \n &buf_len) < 0) {\n PyErr_SetString(PyExc_ValueError, \n \"_zero not returning \" \\\n \"writeable buffer\");\n Py_DECREF(ret);\n return NULL;\n }\n memcpy(zeroval, buf, buf_len);\n Py_DECREF(ret);\n }\n if (PyErr_Occurred()) PyErr_Clear();\n memset(zeroval, 0, arr->itemsize);\n return zeroval;\n}\n\nstatic char *\nPyArray_One(PyArrayObject *arr)\n{\n char *oneval;\n char *buf;\n int buf_len, ret2;\n PyObject *obj, *ret;\n\n oneval = PyDataMem_NEW(arr->itemsize);\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 ret = PyObject_GetAttrString((PyObject *)arr, \"_one\");\n if (ret != NULL) {\n if (PyObject_AsReadBuffer(ret, (const void **)&buf, \n &buf_len) < 0) {\n PyErr_SetString(PyExc_ValueError, \n \"_one not returning \" \\\n \"writeable buffer\");\n Py_DECREF(ret);\n PyDataMem_FREE(oneval);\n return NULL;\n }\n memcpy(oneval, buf, buf_len);\n Py_DECREF(ret);\n }\n if (PyErr_Occurred()) PyErr_Clear();\n\n ret2 = arr->descr->setitem(obj, oneval, arr);\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->itemsize;\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 *)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 { free(new_data); return NULL; }\n}\n\n/* end Helper functions */\n\n\nstatic PyObject *PyArray_New(PyTypeObject *, int nd, intp *, \n int, intp *, char *, 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. */\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/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\n\nstatic char *\nindex2ptr(PyArrayObject *mp, int i) \n{\n\tif (i==0 && (mp->nd == 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\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\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->copyswap;\n\tcopyswapn = dest->descr->copyswapn;\n\n elsize = dest->itemsize;\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->itemsize;\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\tPyArray_Typecode typecode;\n\n\n\ttypecode.type_num = dest->descr->type_num;\n\ttypecode.itemsize = dest->itemsize;\n\ttypecode.fortran = PyArray_ISFORTRAN(dest);\n\t\t\t\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n\t\t\t\t\t &typecode, 0,\n\t\t\t\t\t dest->nd, 0);\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\nstatic PyObject *\nPyArray_FromDimsAndDataAndDescr(int nd, int *d, \n PyArray_Descr *descr,\n char *data) {\n\tPyObject *ret;\n\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\n\tintp newd[MAX_DIMS];\n\t\n\tfor (i=0; itype_num, NULL, data, descr->elsize, \n\t\t\t CARRAY_FLAGS, NULL);\n#else\n\tret = PyArray_New(&PyArray_Type, nd, (intp *)d, \n descr->type_num, NULL, data, descr->elsize, \n\t\t\t CARRAY_FLAGS, NULL);\n#endif\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_FromDimsAndData(int nd, int *d, int type, char *data) \n{\n\tPyObject *ret;\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\t\n\tintp newd[MAX_DIMS];\n\n\tfor (i=0; iob_type, m1->nd, \n\t\t\t\t\t m1->dimensions,\n\t\t\t\t\t m1->descr->type_num,\n\t\t\t\t\t NULL, NULL, m1->itemsize,\n\t\t\t\t\t 0, (PyObject *)m1);\n\t\n if (PyArray_CopyInto(ret, m1) == -1) return NULL;\n\t\n return (PyObject *)ret;\n}\n\n\nstatic PyObject *array_item(PyArrayObject *, int);\n\nstatic PyObject *\nPyArray_Scalar(char *data, int type_num, int itemsize, int swap)\n{\n PyArray_Descr *descr;\n\tPyTypeObject *type;\n\tPyObject *obj;\t\n\tchar *destptr;\n PyArray_CopySwapFunc *copyswap;\n\n descr = PyArray_DescrFromType(type_num);\n if (descr == NULL) return NULL;\n type = descr->typeobj;\n copyswap = descr->copyswap;\n\tif (type_num == PyArray_STRING) \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_ISFLEXIBLE(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 {\n\t\t\tdestptr = PyDataMem_NEW(itemsize);\n\t\t\tif (destptr == NULL) {\n\t\t\t\tPyObject_Del(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tif (type_num == PyArray_UNICODE) {\n\t\t\t\tPyUnicode_AS_UNICODE(obj) = \\\n\t\t\t\t\t(Py_UNICODE *)destptr;\n\t\t\t\t((PyUnicodeObject*)obj)->length = itemsize / \\\n\t\t\t\t\tsizeof(Py_UNICODE);\n\t\t\t\t((PyUnicodeObject*)obj)->hash = -1;\n\t\t\t}\n\t\t\telse {\n\t\t\t\t((PyVoidScalarObject *)obj)->obval = destptr;\n\t\t\t\t((PyVoidScalarObject *)obj)->ob_size = itemsize;\n\t\t\t}\n\t\t}\n\t}\n\telse {\n\t\tdestptr = &(((PyScalarObject*)obj)->obval);\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*/\nstatic PyObject *\nPyArray_ToScalar(char *data, PyArrayObject *arr)\n{\n\tint type_num = arr->descr->type_num;\n\tint itemsize = arr->itemsize;\n int swap = !(PyArray_ISNOTSWAPPED(arr));\n\n\treturn PyArray_Scalar(data, type_num, itemsize, swap);\n}\n\n\n/* Return Python scalar if 0-d array object is encountered */\n\nstatic PyObject *\nPyArray_Return(PyArrayObject *mp) \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((PyObject *)mp) && 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*/\nstatic int \nPyArray_RegisterDataType(PyTypeObject *type)\n{\n\tPyArray_Descr *descr;\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 = malloc(sizeof(PyArray_Descr));\n\tmemcpy(descr, PyArray_DescrFromType(PyArray_VOID), \n\t sizeof(PyArray_Descr));\n\ttypenum = PyArray_USERDEF + PyArray_NUMUSERTYPES;\n\tdescr->type_num = typenum;\n\tdescr->typeobj = 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 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 frees the copy of the Descr_table already there.\n places a pointer to the new one into the slot.\n*/\nstatic int\nPyArray_RegisterDescrForType(int typenum, PyArray_Descr *descr)\n{\n\tPyArray_Descr *old;\n\tint i;\n\n\tif (!PyTypeNum_ISUSERDEF(typenum)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"data type not registered\");\n\t\treturn -1;\n\t}\n\told = userdescrs[typenum-PyArray_USERDEF];\n\tdescr->typeobj = old->typeobj;\n\tdescr->type_num = typenum;\n\n#define _NULL_CHECK(member) \\\n\tif (descr->member == NULL) descr->member = old->member\n\n\tfor (i=0; imember == 0) descr->member = old->member\n\n\t_ZERO_CHECK(kind);\n\t_ZERO_CHECK(type);\n\t_ZERO_CHECK(elsize);\n\t_ZERO_CHECK(alignment);\n#undef _ZERO_CHECK\n\n\tfree(old);\n\tuserdescrs[typenum-PyArray_USERDEF] = descr;\n\treturn 0;\n}\n\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 n3 = strlen((const char *)sep);\n if (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 \"\\\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->itemsize,\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->itemsize,\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 = strlen((const char *)format);\n while(it->index < it->size) {\n obj = self->descr->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\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->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\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 if (PyArray_TYPE(self) == PyArray_OBJECT) {\n PyErr_SetString(PyExc_ValueError, \"a string for the data\"\\\n\t\t\t\t\"in an object array is not appropriate\");\n return NULL;\n }\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->itemsize;\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 != NULL)) {\n\t\t/* Free internal references if an Object array */\n\t\tPyArray_XDECREF(self);\n\n PyDataMem_FREE(self->data);\n }\n\t\n if (self->dimensions != NULL) {\n PyDimMem_FREE(self->dimensions); \n\t}\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\n\nstatic PyObject *\narray_item(PyArrayObject *self, int i) \n{\n char *item;\n PyArrayObject *r;\n\n\n\tif(self->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n if ((item = index2ptr(self, i)) == NULL) return NULL;\n\n\tr = (PyArrayObject *)PyArray_New(self->ob_type, \n\t\t\t\t\t self->nd-1, self->dimensions+1, \n\t\t\t\t\t self->descr->type_num, \n\t\t\t\t\t self->strides+1, item, \n\t\t\t\t\t self->itemsize, self->flags,\n\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_item(self, i));\n}\n\n\nstatic int \narray_ass_item(PyArrayObject *self, int 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\n if (i < 0) i = i+self->dimensions[0];\n\n if (self->nd > 1) {\n if((tmp = (PyArrayObject *)array_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->setitem(v, item, self) == -1) return -1;\n return 0;\n}\n\n/* -------------------------------------------------------------- */\nstatic int\nslice_coerce_index(PyObject *o, int *v)\n{\n\t*v = PyArray_PyIntAsInt(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, int length,\n int *start, int *stop, int *step,\n intp *slicelength)\n{\n\tint 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 int\nparse_subindex(PyObject *op, int *step_size, intp *n_steps, int max)\n{\n\tint 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\tint 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_PyIntAsInt(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, start, offset, n_add, n_pseudo;\n int step_size;\n\tintp n_steps;\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, *tup;\n\tint n1, n2, n3, val;\n\tint i;\n\n\ttup = PyTuple_New(mit->nd);\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\tPyTuple_SET_ITEM(tup, i++, PyInt_FromLong((long)val++));\n\tval = 0;\n\twhile(val < n1)\n\t\tPyTuple_SET_ITEM(tup, i++, PyInt_FromLong((long)val++));\n\tval = n1+n2;\n\twhile(val < n3)\n\t\tPyTuple_SET_ITEM(tup, i++, PyInt_FromLong((long)val++));\n\n\tnew = PyArray_Transpose(*ret, tup);\n\tPy_DECREF(tup);\n\tPy_DECREF(*ret);\n\t*ret = (PyArrayObject *)new;\n}\n\n\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\tret = (PyArrayObject *)\\\n\t\tPyArray_New(temp->ob_type, mit->nd, mit->dimensions, \n\t\t\t temp->descr->type_num, NULL, NULL, \n\t\t\t temp->itemsize, \n\t\t\t PyArray_ISFORTRAN(temp),\n\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\treturn NULL;\n\tindex = it->size;\n\tswap = ((temp->flags & NOTSWAPPED) != (ret->flags & NOTSWAPPED));\n copyswap = ret->descr->copyswap;\n\tPyArray_MapIterReset(mit);\n\twhile (index--) {\n copyswap(it->dataptr, mit->dataptr, swap, ret->itemsize);\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\tPyArray_Typecode typecode = {0, 0, 0};\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Unbound Map Iterator */\n\tif (mit->ait == NULL) return -1;\n\n\ttypecode.type_num = mit->ait->ao->descr->type_num;\n\ttypecode.itemsize = mit->ait->ao->itemsize;\n\n\tarr = PyArray_FromAny(op, &typecode, \n\t\t\t 0, 0, FORCECAST);\n\tif (arr == NULL) return -1;\n\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, (PyArrayObject **)&arr);\n\t\t}\n\t}\n\t\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) \n\t\treturn -1;\n\n\tindex = mit->size;\n\tswap = ((mit->ait->ao->flags & NOTSWAPPED) != \\\n\t\t(PyArray_FLAGS(arr) & NOTSWAPPED));\n\n copyswap = PyArray_DESCR(arr)->copyswap;\n\tPyArray_MapIterReset(mit);\n /* Need to decref OBJECT arrays */\n if (PyTypeNum_ISOBJECT(typecode.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 copyswap(mit->dataptr, NULL, swap, \n sizeof(PyObject *));\n PyArray_MapIterNext(mit);\n PyArray_ITER_NEXT(it);\n if (it->index == it->size)\n PyArray_ITER_RESET(it);\n }\n return 0;\n }\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\treturn 0;\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 0-dimensional arrays */\n\nstatic PyObject *\narray_subscript(PyArrayObject *self, PyObject *op) \n{\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n\tintp offset;\n int nd, i;\n PyArrayObject *other;\n\tPyArrayMapIterObject *mit;\n\n if (PyArray_IsScalar(op, Integer) || PyInt_Check(op) || \\\n PyLong_Check(op)) {\n intp value;\n value = PyArray_PyIntAsIntp(op);\n if (PyErr_Occurred())\n PyErr_Clear();\n else if (value >= 0) {\n if (value <= MAX_INT)\n return array_item(self, (int) value);\n }\n else if (value < 0) {\n if (value >= -MAX_INT) {\n if (self->nd > 0) value += self->dimensions[0];\n return array_item(self, (int) value);\n }\n }\n }\n\n\tif (PyArrayMapIter_Check(op)) {\n\t\tmit = (PyArrayMapIterObject *)op;\n\t\t/* bind to current array */\n\t\tPyArray_MapIterBind(mit, self);\n\t\t\n\t\t/* If the mapiterator was created with standard indexing\n\t\t behavior, fall through to view-based code */\n\t\tif (!mit->view) return PyArray_GetMap(mit);\n\t\top = mit->indexobj;\n\t}\n\telse { /* wrap arguments into a mapiter object */\n\t\tmit = (PyArrayMapIterObject *)PyArray_MapIterNew(op);\n\t\tif (mit == NULL) return NULL;\n\t\tif (!mit->view) { /* fancy indexing */\n\t\t\tPyArray_MapIterBind(mit, self);\n\t\t\tother = (PyArrayObject *)PyArray_GetMap(mit);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn (PyObject *)other;\n\t\t}\n\t\tPy_DECREF(mit);\n\t}\n\n\ti = PyArray_PyIntAsInt(op);\n\tif (!error_converting(i)) {\n\t\tif (i < 0 && self->nd > 0) i = i+self->dimensions[0];\n\t\treturn array_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\tif ((other = (PyArrayObject *)\t\t\t\t\t\\\n\t PyArray_New(self->ob_type, nd, dimensions, self->descr->type_num,\n\t\t\t strides, self->data+offset, \n\t\t\t self->itemsize, self->flags,\n\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 \narray_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op) \n{\n int ret, 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\n\tif (PyArrayMapIter_Check(index)) {\n\t\tmit = (PyArrayMapIterObject *)index;\n\t\t/* bind behavior to current array */\n\t\tPyArray_MapIterBind(mit, self);\n\t\t\t\n\t\t/* fall through if standard view-based map iterator */\n\t\tif (!mit->view) return PyArray_SetMap(mit, op);\n\t\tindex = mit->indexobj;\n\t}\n\telse {\n\t\tmit = (PyArrayMapIterObject *)PyArray_MapIterNew(index);\n\t\tif (mit == NULL) return -1;\n\t\tif (!mit->view) {\n\t\t\tPyArray_MapIterBind(mit, self);\n\t\t\tret = PyArray_SetMap(mit, op);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn ret;\n\t\t}\n\t\tPy_DECREF((PyObject*)mit);\n\t}\n\n\ti = PyArray_PyIntAsInt(index);\n\tif (!error_converting(i)) {\n\t\treturn array_ass_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 ret = PyArray_CopyObject(tmp, op);\n Py_DECREF(tmp);\n\t\n return ret;\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 \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\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}\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}\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 PyObject *args, *ret;\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n args = Py_BuildValue(\"(OO)\", m1, m2);\n ret = PyObject_Call(op, args, NULL);\n Py_DECREF(args);\n return ret;\n}\n\nstatic PyObject *\nPyArray_GenericUnaryFunction(PyArrayObject *m1, PyObject *op) \n{\n PyObject *args, *ret;\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n args = Py_BuildValue(\"(O)\", m1);\n ret = PyObject_Call(op, args, NULL);\n Py_DECREF(args);\n return ret;\n}\n\nstatic PyObject *\nPyArray_GenericInplaceBinaryFunction(PyArrayObject *m1, \n\t\t\t\t PyObject *m2, PyObject *op) \n{\n PyObject *args, *ret;\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n args = Py_BuildValue(\"(OOO)\", m1, m2, m1);\n ret = PyObject_Call(op, args, NULL);\n Py_DECREF(args);\n return ret;\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_all_nonzero(PyArrayObject *mp) \n{\n\tintp index;\n\tPyArrayIterObject *it;\n\tBool anyTRUE = 0;\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->nonzero(it->dataptr, mp)) {\n\t\t\tanyTRUE = 1;\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 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->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->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->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->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->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_all_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 r = (PyArrayObject *)\\\n\t\tPyArray_New(self->ob_type, self->nd, self->dimensions, \n\t\t\t self->descr->type_num, self->strides, data,\n\t\t\t self->itemsize, 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 any(self == el) */\n\n return PyObject_RichCompareBool((PyObject *)self, el, Py_EQ);\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 *)realloc(*string, *max_n); }\n\t\n if (nd == 0) {\n\t\t\n if ((op = descr->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\tfree(string); return NULL; \n\t}\n\t\n\tif (PyArray_ISFLEXIBLE(self)) {\n\t\tchar buf[100];\n\t\tsnprintf(buf, sizeof(buf), \"%d\", self->itemsize);\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 free(string);\n return ret;\n}\n\nstatic PyObject *PyArray_StrFunction=NULL;\nstatic PyObject *PyArray_ReprFunction=NULL;\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\n\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) \n{\n PyObject *array_other, *result;\n\n switch (cmp_op) \n {\n case Py_LT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less);\n case Py_LE:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less_equal);\n case Py_EQ:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then return the integer\n\t\t\t object 0. This fixes code that used to\n\t\t\t allow equality comparisons between arrays\n\t\t\t and other objects which would give a result\n\t\t\t of 0\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n result = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.equal);\n /* If the comparison results in NULL, then the \n\t\t\t two array objects can not be compared together so \n\t\t\t return zero \n */\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n return result;\n case Py_NE:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then objects cannot be \n\t\t\t compared and cannot be equal, therefore, \n\t\t\t return True;\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n result = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.not_equal);\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n return result;\n case Py_GT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.greater);\n case Py_GE:\n return PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t other, \n\t\t\t\t\t \t n_ops.greater_equal);\n }\n return NULL;\n}\n\nstatic PyObject *\n_check_axis(PyArrayObject *arr, int *axis, int flags)\n{\n\tPyObject *temp;\n\tint n = arr->nd;\n\n\tif ((*axis >= MAX_DIMS) || (n==0)) {\n\t\ttemp = PyArray_Ravel(arr,0);\n\t\t*axis = 0;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_FromAny((PyObject *)arr, NULL, \n\t\t\t\t\t 0, 0, flags);\n\t\t\tif (temp == NULL) return NULL;\n\t\t}\n\t\telse {\n\t\t\tPy_INCREF(arr);\n\t\t\ttemp = (PyObject *)arr;\n\t\t}\n\t}\n\tif (*axis < 0) *axis += n;\n\tif ((*axis < 0) || (*axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", *axis);\n\t\tPy_DECREF(temp);\n\t\treturn NULL;\n\t}\n\treturn temp;\n}\n\n#include \"arraymethods.c\"\n\n/* Lifted from numarray */\nstatic PyObject *\nPyArray_IntTupleFromIntp(int len, intp *vals)\n{\n\tint i;\n PyObject *intTuple = PyTuple_New(len);\n if (!intTuple) goto fail;\n for(i=0; ind == 0) return 1;\n\tsd = ap->itemsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\n\t}\n\treturn 1;\n}\n\n\nstatic int \n_IsFortranContiguous(PyArrayObject *ap) \n{\n\tint sd;\n\tint i;\n\t\n\tif (ap->nd == 0) return 1;\n\tsd = ap->itemsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i=0; i< ap->nd; ++i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\n\t}\n\treturn 1;\n}\n\nstatic int\n_IsAligned(PyArrayObject *ap) \n{\n\tint i, alignment, aligned=1;\n\tintp ptr;\n\tint type = ap->descr->type_num;\n\n\tif ((type == PyArray_STRING) || (type == PyArray_VOID))\n\t\treturn 1;\n\n\talignment = ap->descr->alignment;\n\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\tPyBufferProcs *pb;\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\tpb = base->ob_type->tp_as_buffer;\n\tif (pb == NULL || pb->bf_getwritebuffer == NULL)\n\t\treturn FALSE;\n\t\n\treturn TRUE;\n}\n\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\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not \n walk outside of the memory implied by either numbytes or\n a single segment array of the provided dimensions and element size if\n numbytes is 0 */\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, \n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\t\n\tif (numbytes == 0) \n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\t\n\tfor (i=0; i numbytes) {\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\treturn TRUE;\n\t\n}\n\n\n/* This is the main array creation routine. */\n\n/* Flags argument has multiple related meanings \n depending on data and strides: \n\n If data is given, then flags is flags associated with data. \n If strides is not given, then a contiguous strides array will be created\n and the CONTIGUOUS bit will be set. If the flags argument \n has the FORTRAN bit set, then a FORTRAN-style strides array will be\n created (and of course the FORTRAN flag bit will be set). \n\n If data is not given but created here, then flags will be DEFAULT_FLAGS\n and a non-zero flags argument can be used to indicate a FORTRAN style\n array is desired. \n*/\n\nstatic intp\n_array_fill_strides(intp *strides, intp *dims, int nd, intp itemsize, \n\t\t int inflag, int *objflags) \n{\n\tint i;\n\t/* Only make Fortran strides if not contiguous as well */\n\tif ((inflag & FORTRAN) && !(inflag & CONTIGUOUS)) {\n\t\tfor (i=0; i 1) *objflags &= ~CONTIGUOUS;\n\t\telse *objflags |= CONTIGUOUS;\n\t}\n\telse {\n\t\tfor (i=nd-1;i>=0;i--) {\n\t\t\tstrides[i] = itemsize;\n\t\t\titemsize *= dims[i] ? dims[i] : 1;\n\t\t}\n\t\t*objflags |= CONTIGUOUS;\n\t\tif (nd > 1) *objflags &= ~FORTRAN;\n\t\telse *objflags |= FORTRAN;\n\t}\n\treturn itemsize;\n}\n\n\t\nstatic PyObject *\nPyArray_New(PyTypeObject *subtype, int nd, intp *dims, int type_num,\n intp *strides, char *data, int itemsize, int flags,\n\t PyObject *obj)\n{\n\tPyArrayObject *self;\n\tPyArray_Descr *descr;\n\tregister int i;\n\tintp sd, temp=-1;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\tif (descr == NULL) return NULL;\n\n\tif (nd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"number of dimensions must be >=0\");\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 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\treturn NULL;\n\t\t}\n\t}\n\t\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) return NULL;\t\n\tself->descr = descr;\n\tself->dimensions = 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\n\tif (PyTypeNum_ISFLEXIBLE(type_num)) {\n\t\tif (itemsize < 1) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"type must provide an itemsize\");\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn NULL;\n\t\t}\n\t\tself->itemsize = itemsize;\n\t\t/* Guarantee that these kind of arrays are never byteswapped\n\t\t unknowingly. \n\t\t*/\n\t\tif (type_num != PyArray_UNICODE)\n\t\t\tself->flags |= NOTSWAPPED;\n\t}\n\telse self->itemsize = descr->elsize; \n\t\t\n\tsd = self->itemsize;\n\t\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn PyErr_NoMemory();\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\tPyDimMem_FREE(self->dimensions);\n\t\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\t\treturn NULL;\n\t\t\t}\t\t\t\t\n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t}\n \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 (a.data) doesn't work\n\t\t as it should. */\n\n\t\tif (sd==0) sd = sizeof(intp);\n\n\t\tif ((data = PyDataMem_NEW(sd))==NULL) {\n\t\t\tPyDimMem_FREE(self->dimensions);\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn PyErr_NoMemory();\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\n\t\t/* It is bad to have unitialized OBJECT pointers */\n\t\t/* We shouldn't need to check for the OBJECT Letter\n\t\t but perhaps it's best. */\n\t\tif (type_num == PyArray_OBJECT || \\\n\t\t type_num == PyArray_OBJECTLTR) {\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\tself->nd = nd;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\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;\n\t\tif (temp==-1) { /* 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\tres = PyObject_CallMethod((PyObject *)self, \n\t\t\t\t\t \"__array_finalize__\",\n\t\t\t\t\t \"O\", obj);\n\t\tif (res == NULL) {\n\t\t\tPyDimMem_FREE(self->dimensions);\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn NULL;\n\t\t}\n\t\telse Py_DECREF(res);\n\t}\n\n\treturn (PyObject *)self;\n}\n\n\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\n newsize = PyArray_MultiplyList(new_dimensions, new_nd);\n\n if (newsize == 0) {\n PyErr_SetString(PyExc_ValueError, \n \"newsize is zero; cannot delete an array \"\\\n \"in this way\");\n return NULL;\n }\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 = (((PyObject *)self)->ob_refcnt);\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\n\t\t/* Reallocate space if needed */\n\t\tnew_data = PyDataMem_RENEW(self->data, \n\t\t\t\t\t newsize*(self->itemsize));\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->itemsize;\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->itemsize;\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 */\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; idataptr, fromptr, itemsize);\n\t\t\tPyArray_ITER_NEXT(iter);\n\t\t}\n\n\t\tPy_DECREF(iter);\n\t\tPy_DECREF(behaved);\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\", \"strides\", \n \"swap\", \"fortran\", NULL};\n\tint itemsize = 0;\n\tPyArray_Typecode typecode = {PyArray_NOTYPE, 0, 0};\n\tint type_num = PyArray_NOTYPE;\n PyArray_Dims dims = {NULL, 0};\n PyArray_Dims strides = {NULL, 0};\n PyArray_Chunk buffer;\n\tint fortran = 0;\n int swapped = 0;\n\tPyArrayObject *ret;\n\n\tbuffer.ptr = NULL; \n /* Usually called with shape and type\n but can also be called with buffer, strides, and swapped info\n */\n\n\t/* For now, let's just use this to create an empty, contiguous \n\t array of a specific type and shape. \n\t*/\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&O&ii\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &dims, \n PyArray_TypecodeConverter,\n\t\t\t\t\t &typecode, \n PyArray_BufferConverter,\n &buffer,\n &PyArray_IntpConverter, \n &strides,\n &swapped, &fortran)) \n\t\treturn NULL;\n\t\n if (typecode.type_num ==PyArray_NOTYPE) {\n\t\ttypecode.type_num = PyArray_DOUBLE;\n\t\ttypecode.itemsize = sizeof(double);\n\t}\n\ttype_num = typecode.type_num;\n\titemsize = typecode.itemsize;\n\n\n if (dims.ptr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"need to give a \"\\\n \"valid shape as the first argument\");\n goto fail;\n }\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)PyArray_New(subtype, (int)dims.len, \n dims.ptr, type_num,\n NULL, NULL, itemsize, \n fortran, NULL);\n \n if (ret == NULL) goto fail;\n if (type_num == PyArray_OBJECT) { /* place Py_None */\n PyArray_FillObjectArray(ret, Py_None);\n }\n }\n else { /* buffer given -- use it */\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = buffer.len / itemsize;\n }\n else if (buffer.len < itemsize* \\\n PyArray_MultiplyList(dims.ptr, dims.len)) {\n PyErr_SetString(PyExc_TypeError, \n \"buffer is too small for \" \\\n \"requested array\");\n goto fail;\n }\n if (strides.ptr != NULL) {\n\t\t\tif (strides.len != dims.len) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides, if given, must be \"\\\n\t\t\t\t\t\t\"the same length as shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CheckStrides(itemsize, strides.len, \n\t\t\t\t\t\t buffer.len,\n\t\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides is incompatible \"\\\n\t\t\t\t\t\t\"with shape of requested\"\\\n\t\t\t\t\t\t\"array and size of buffer\");\n\t\t\t\tgoto fail;\n\t\t\t}\n }\n if (type_num == PyArray_OBJECT) {\n PyErr_SetString(PyExc_TypeError, \"cannot construct \"\\\n \"an object array from buffer data\");\n goto fail;\n }\n /* get writeable and aligned */\n if (fortran) buffer.flags |= FORTRAN;\n if (!(swapped)) buffer.flags |= NOTSWAPPED;\n ret = (PyArrayObject *)PyArray_New(subtype, dims.len, \n dims.ptr, type_num,\n strides.ptr,\n (char *)buffer.ptr, \n itemsize, \n buffer.flags, NULL); \n if (ret == 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 PyArray_Return(ret);\n \n fail:\n if (dims.ptr) PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return NULL;\n}\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 static PyObject *module=NULL;\n\n if (module==NULL) {\n module = PyImport_ImportModule(\"scipy.base._internal\");\n if (module == NULL) return NULL;\n }\n return PyObject_CallMethod(module, \"flagsobj\", \"Oii\", \n self, self->flags, 0);\n}\n\n/*\nstatic int\narray_flags_set(PyArrayObject *self, PyObject *obj) \n{\n\tint flagback = self->flags;\n\n if (PyDict_Check(obj)) {\n PyObject *new;\n\t\tnew = PyDict_GetItemString(obj, \"ALIGNED\");\n\t\tif (new) {\n\t\t\tif (PyObject_Not(new)) self->flags &= ~ALIGNED;\n\t\t\telse if (_IsAligned(self)) self->flags |= ALIGNED;\n\t\t\telse {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"cannot set aligned flag of \" \\\n\t\t\t\t\t\t\"mis-aligned array to True\");\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t}\n new = PyDict_GetItemString(obj, \"UPDATEIFCOPY\");\n if (new) {\n if (PyObject_Not(new)) {\n self->flags &= ~UPDATEIFCOPY;\n Py_DECREF(self->base);\n self->base = NULL;\n }\n else {\n\t\t\t\tself->flags = flagback;\n PyErr_SetString(PyExc_ValueError, \n \"cannot set UPDATEIFCOPY \" \\\n \"flag to True\");\n return -1;\n }\n }\n new = PyDict_GetItemString(obj, \"WRITEABLE\");\n if (new) {\n\t\t\tif (PyObject_IsTrue(new)) {\n\t\t\t\tif (_IsWriteable(self)) {\n\t\t\t\t\tself->flags |= WRITEABLE;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tself->flags = flagback;\n\t\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\t\"cannot set \"\t\\\n\t\t\t\t\t\t\t\"WRITEABLE \"\t\\\n\t\t\t\t\t\t\t\"flag to True of \"\\\n\t\t\t\t\t\t\t\"this array \");\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n else\n self->flags &= ~WRITEABLE;\n }\n new = PyDict_GetItemString(obj, \"NOTSWAPPED\");\n if (new) {\n if (PyObject_IsTrue(new))\n self->flags |= NOTSWAPPED;\n else {\n self->flags &= ~NOTSWAPPED;\n\t\t\t}\n\t\t}\n return 0;\n }\n PyErr_SetString(PyExc_ValueError, \n \"object must be a dictionary\");\n return -1;\n}\n*/\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\tif (!PyTuple_Check(val)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"shape must be a tuple\");\n\t\treturn -1;\n\t}\n\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\n\t\n\tif (self->nd > 0) { /* Free old dimensions and strides */\n\t\tPyDimMem_FREE(self->dimensions);\n\t}\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;\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\treturn -1;\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->itemsize;\n\t\n\tif (!PyArray_CheckStrides(self->itemsize, self->nd, numbytes, \n\t\t\t\t self->dimensions, newstrides.ptr)) {\n\t\tPyErr_SetString(PyExc_ValueError, \"strides is not \"\\\n\t\t\t\t\"compatible with available memory\");\n\t\treturn -1;\n\t}\n\tmemcpy(self->strides, newstrides.ptr, sizeof(intp)*newstrides.len);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\treturn 0;\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->itemsize);\n}\n\nstatic PyObject *\narray_size_get(PyArrayObject *self)\n{\n\tlonglong size=PyArray_SIZE(self);\n\tif (size > MAX_INT || size < MIN_INT)\n\t\treturn PyLong_FromLongLong((longlong) size);\n\telse \n\t\treturn PyInt_FromLong((long) size);\n}\n\n\nstatic PyObject *\narray_typechar_get(PyArrayObject *self)\n{\n\tif PyArray_ISFLEXIBLE(self) \n\t\treturn PyString_FromFormat(\"%c%d\", (self->descr->type),\n\t\t\t\t\t self->itemsize);\n\telse \n\t\treturn PyString_FromStringAndSize(&(self->descr->type), 1);\n}\n\nstatic PyObject *\narray_typestr_get(PyArrayObject *self)\n{\n\tstatic char endians[] = \"<>\";\n\tchar endian;\n\tint which;\n\tunsigned long val = 1;\n\tchar *s;\n\tchar basic_=self->descr->kind;\n\n\ts = (char *)&val; /* s[0] == 0 implies big-endian */\n\twhich = (PyArray_ISNOTSWAPPED(self) ? 0 : 1);\n\tif (s[0] == 0) which = 1 - which;\n\tendian = endians[which]; \n\t\n\tif ((basic_==PyArray_VOIDLTR) || (basic_==PyArray_STRINGLTR) || \\\n\t (basic_==PyArray_OBJECTLTR) || (self->itemsize == 1))\n\t\treturn PyString_FromFormat(\"|%c%d\", basic_, self->itemsize);\n\telse\n\t\treturn PyString_FromFormat(\"%c%c%d\", endian, basic_,\n\t\t\t\t\t self->itemsize);\n}\n\nstatic PyObject *\narray_descr_get(PyArrayObject *self)\n{\n\tPyObject *res;\n\tPyObject *dobj;\n\n\t/* hand this off to the typeobject */\n\t/* or give default */\n\tif (PyArray_ISUSERDEF(self)) {\n\t\tres = PyObject_GetAttrString((PyObject *)self->descr->typeobj, \n\t\t\t\t\t \"__array_descr__\");\n\t\tif (res) return res;\n\t\tPyErr_Clear();\n\t}\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\n\nstatic PyObject *\narray_type_get(PyArrayObject *self)\n{\n\treturn PyArray_TypeObjectFromType(self->descr->type_num);\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*/\n\nstatic int\narray_type_set(PyArrayObject *self, PyObject *arg)\n{\n PyArray_Typecode newtype = {PyArray_NOTYPE, 0, 0};\n intp newdim;\n int index;\n char *msg = \"new type not compatible with array.\";\n\n if ((PyArray_TypecodeConverter(arg, &newtype) < 0) ||\n newtype.type_num == PyArray_NOTYPE) {\n PyErr_SetString(PyExc_TypeError, \"invalid type for array\");\n return -1;\n }\n if (!(PyArray_ISONESEGMENT(self) ||\t\t\\\n\t (newtype.itemsize != self->itemsize))) {\n PyErr_SetString(PyExc_ValueError, msg);\n return -1; \n }\n\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\n if (newtype.itemsize < self->itemsize) {\n /* if it is compatible increase the size of the dimension\n at end (or at the front for FORTRAN)\n */\n if (self->itemsize % newtype.itemsize != 0) {\n PyErr_SetString(PyExc_ValueError, msg);\n return -1;\n }\n newdim = self->itemsize / newtype.itemsize;\n\t\tself->dimensions[index] *= newdim;\n self->strides[index] = newtype.itemsize;\n\t}\n \n else if (newtype.itemsize > self->itemsize) {\n \n /* Determine if last (or first if FORTRAN) dimension\n is compatible */\n\n\t\tnewdim = self->dimensions[index] * self->itemsize;\n if ((newdim % newtype.itemsize) != 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, msg);\n return -1;\n }\n\t\t\n self->dimensions[index] = newdim / newtype.itemsize;\n self->strides[index] = newtype.itemsize;\n\t\t\n }\n\t\n \n /* fall through -- adjust type*/\n\n self->descr = PyArray_DescrFromType(newtype.type_num);\n self->itemsize = newtype.itemsize;\n PyArray_UpdateFlags(self, ALIGNED);\n return 0;\n\n}\n\n\n\nstatic PyObject *\narray_base_get(PyArrayObject *self)\n{\n\tif (self->base == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\telse {\n\t\tPy_INCREF(self->base);\n\t\treturn self->base;\n\t}\n}\n\n\nstatic PyObject *\narray_real_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *)ret;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n}\n\n\nstatic int\narray_real_set(PyArrayObject *self, PyObject *val)\n{\n\tPyArrayObject *ret;\n\tPyArrayObject *new;\n\tint rint;\n\n\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0);\n\tif (new == NULL) return -1;\n\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) 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\treturn rint;\n}\n\nstatic PyObject *\narray_imag_get(PyArrayObject *self)\n{\t\n\tPyArrayObject *ret;\n\tint itemsize;\n\tint typenum;\n PyArray_Typecode type;\n\t\n\ttype.type_num = self->descr->type_num;\n\ttype.itemsize = self->itemsize;\n\ttype.fortran = PyArray_ISFORTRAN(self);\n\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\titemsize = self->itemsize >> 1;\n\t\ttypenum = self->descr->type_num - PyArray_NUM_FLOATTYPE;\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 typenum,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data + itemsize,\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\tret = (PyArrayObject *)PyArray_Zeros(self->nd, \n\t\t\t\t\t\t self->dimensions, &type);\n\t\tret->flags &= ~WRITEABLE;\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic int\narray_imag_set(PyArrayObject *self, PyObject *val)\n{\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyArrayObject *ret;\n\t\tPyArrayObject *new;\n\t\tint rint;\n\n\t\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0); \n\t\tif (new == NULL) return -1;\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides+ \\\n\t\t\t\t\t\t (self->itemsize >> 1) ,\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) {\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_Typecode typecode;\n int swap;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode.type_num = self->descr->type_num;\n\ttypecode.itemsize = self->itemsize;\n\ttypecode.fortran = PyArray_ISFORTRAN(self);\n\t\n\tarr = PyArray_FromAny(val, &typecode, \n\t\t\t 0, 0, FORCECAST);\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->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 copyswap(selfit->dataptr, NULL, swap, \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->itemsize);\n copyswap(selfit->dataptr, NULL, swap, self->itemsize);\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\t{\"base\",\n\t (getter)array_base_get,\n\t NULL,\n\t \"base object\"},\n {\"dtype\", \n\t (getter)array_type_get, \n\t (setter)array_type_set,\n\t \"get array type class\"},\n\t{\"dtypechar\",\n\t (getter)array_typechar_get,\n\t NULL,\n\t \"get array type character code\"},\n\t{\"dtypestr\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"get array type string\"},\n {\"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_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\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\n\nstatic char Arraytype__doc__[] = \n \"A array object represents a multidimensional, homogeneous array\\n\"\n\t\" of basic values. Arrays are sequence, mapping and numeric\\n\"\n\t\" objects. More information is available in the scipy module and\\n\"\n\t\" by looking at the methods and attributes of an array.\";\n\nstatic PyTypeObject PyBigArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"scipy.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 \n offsetof(PyArrayObject, weakreflist), /*tp_weaklistoffset */\n\n /* Iterator support (use standard) */\n\n (getiterfunc)0, \t\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 0,\t /* tp_alloc */ \n (newfunc)array_new,\t\t /* tp_new */\n 0,\t \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 \"scipy.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) \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 if (PySequence_Length(s) == 0) \n\t\treturn 1;\n\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);\n\t\tif(d >= 0) d++;\n\t}\n Py_DECREF(e);\n return d;\n}\n\nstatic int\ndiscover_itemsize(PyObject *s, int nd, int *itemsize) \n{\n\tint n, r, i;\n\tPyObject *e;\n\t\n\tn = PyObject_Length(s);\n\n\tif ((nd == 0) || PyString_Check(s) ||\t\t\\\n\t PyUnicode_Check(s) || PyBuffer_Check(s)) {\n\t\tif PyUnicode_Check(s) \n\t\t\t*itemsize = MAX(*itemsize, sizeof(Py_UNICODE)*n);\n\t\telse\n\t\t\t*itemsize = MAX(*itemsize, n);\n\t\treturn 0;\n\t}\n\tfor (i=0; i n_lower) n_lower = d[1];\n }\n d[1] = n_lower;\n\t\n return 0;\n}\n\nstatic void\n_array_small_type(int chktype, int mintype, int chksize, int minsize, \n\t\t PyArray_Typecode *outtype)\n{\n\touttype->type_num = MAX(chktype, mintype);\n\tif (PyTypeNum_ISFLEXIBLE(outtype->type_num) &&\t\\\n\t PyTypeNum_ISFLEXIBLE(mintype)) {\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 == PyArray_STRING) {\n\t\t\touttype->itemsize = MAX(chksize, 2*minsize);\n\t\t}\n\t\telse {\n\t\t\touttype->itemsize = MAX(chksize, minsize);\n\t\t}\n\t}\n\telse {\n\t\touttype->itemsize = chksize;\n\t}\n\treturn;\t\n}\n\nstatic void\n_array_find_type(PyObject *op, PyArray_Typecode *minitype, \n\t\t PyArray_Typecode *outtype, int max)\n{\n int l;\n PyObject *ip;\n\tint chktype=0;\n\tint chksize=0;\n\tint mintype, minsize;\n\n\tif (minitype == NULL) {\n\t\tmintype = PyArray_BOOL;\n\t\tminsize = sizeof(Bool);\n\t}\n\telse {\n\t\tmintype = minitype->type_num;\n\t\tminsize = minitype->itemsize;\n\t}\n\n \n if (max < 0 || mintype == -1) goto deflt;\n\t\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_TYPE(op);\n\t\tchksize = PyArray_ITEMSIZE(op);\n\t\tgoto finish;\n\t}\n\t\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tPyArray_TypecodeFromScalar(op, outtype);\n\t\tchktype = outtype->type_num;\n\t\tchksize = outtype->itemsize;\n\t\tgoto finish;\n\t}\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_TYPE(ip);\n\t\t\tchksize = PyArray_ITEMSIZE(ip);\n\t\t\tgoto finish;\n\t\t}\n } \n\t\n\tif (PyObject_HasAttrString(op, \"__array_typestr__\")) {\n\t\tint swap=0, res;\n\t\tip = PyObject_GetAttrString(op, \"__array_typestr__\");\n\t\tif (ip && PyString_Check(ip)) {\n\t\t\tres = _array_typecode_fromstr(PyString_AS_STRING(ip), \n\t\t\t\t\t\t &swap, outtype); \n\t\t\tif (res >= 0) {\n\t\t\t\tPy_DECREF(ip);\n\t\t\t\tchktype = outtype->type_num;\n\t\t\t\tchksize = outtype->itemsize;\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t}\n\t\tPy_XDECREF(ip);\n\t}\n\n if (PyString_Check(op)) {\n\t\tchktype = PyArray_STRING;\n\t\tchksize = PyString_GET_SIZE(op);\n\t\tgoto finish;\n }\n\n\tif (PyUnicode_Check(op)) {\n\t\tchktype = PyArray_UNICODE;\n\t\tchksize = PyUnicode_GET_DATA_SIZE(op);\n\t\tgoto finish;\n\t}\n\n\tif (PyBuffer_Check(op)) {\n\t\tchktype = PyArray_VOID;\n\t\tchksize = op->ob_type->tp_as_sequence->sq_length(op);\n\t\tPyErr_Clear();\n\t\tgoto finish;\n\t}\n\n\tif (PyInstance_Check(op)) goto deflt;\n\t\n if (PySequence_Check(op)) {\n\t\tPyArray_Typecode newtype;\n\t\tnewtype.type_num = mintype;\n\t\tnewtype.itemsize = minsize;\n\t\tnewtype.fortran = 0;\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 && mintype == 0) {\n\t\t\tnewtype.type_num = PyArray_INTP;\n\t\t\tnewtype.itemsize = sizeof(intp);\n\t\t}\n while (--l >= 0) {\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\t_array_find_type(ip, &newtype, outtype, max-1);\n\t\t\t_array_small_type(outtype->type_num,\n\t\t\t\t\t newtype.type_num, \n\t\t\t\t\t outtype->itemsize,\n\t\t\t\t\t newtype.itemsize,\n\t\t\t\t\t &newtype);\n Py_DECREF(ip);\n }\n\t\tchktype = newtype.type_num;\n\t\tchksize = newtype.itemsize;\n\t\tgoto finish;\n }\n\t\n\tif (PyBool_Check(op)) {\n\t\tchktype = PyArray_BOOL;\n\t\tchksize = sizeof(Bool);\n\t\tgoto finish;\t\t\n\t}\n else if (PyInt_Check(op)) {\n\t\tchktype = PyArray_LONG;\n\t\tchksize = sizeof(long);\n\t\tgoto finish;\n } else if (PyFloat_Check(op)) {\n\t\tchktype = PyArray_DOUBLE;\n\t\tchksize = sizeof(double);\n\t\tgoto finish;\n\t} else if (PyComplex_Check(op)) {\n\t\tchktype = PyArray_CDOUBLE;\n\t\tchksize = sizeof(cdouble);\n\t\tgoto finish;\n\t}\n\n deflt:\n\tchktype = PyArray_OBJECT;\n\tchksize = sizeof(void *);\n\n finish:\n\t_array_small_type(chktype, mintype, chksize, minsize, \n\t\t\t outtype);\n\treturn;\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\" */ \nstatic PyObject *\nArray_FromScalar(PyObject *op, PyArray_Typecode *typecode) \n{\n PyArrayObject *ret;\n\tint itemsize = 0;\n\tint type = typecode->type_num;\n\n\tif PyTypeNum_ISFLEXIBLE(type) {\n\t\titemsize = PyObject_Length(op);\n\t}\n\n\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, 0, NULL, type,\n\t\t\t\t\t NULL, NULL, itemsize, 0, NULL);\n\n\tif (ret == NULL) return NULL;\n\n ret->descr->setitem(op, ret->data, ret);\n\t\n if (PyErr_Occurred()) {\n array_dealloc(ret);\n return NULL;\n } else {\n return (PyObject *)ret;\n }\n}\n\n\nstatic PyObject *\nArray_FromSequence(PyObject *s, PyArray_Typecode *typecode, int min_depth, \n\t\t int max_depth)\n{\n PyArrayObject *r;\n int nd;\n\tintp *d;\n\tint stop_at_string;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->itemsize;\n\t\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 if (!((nd=discover_depth(s, MAX_DIMS+1, stop_at_string)) > 0)) {\n\t\tif (nd==0)\n\t\t\treturn Array_FromScalar(s, typecode);\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid input sequence\");\n return NULL;\n }\n\t\n if ((max_depth && nd > max_depth) ||\t\\\n\t (min_depth && nd < min_depth)) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid number of dimensions\");\n return NULL;\n }\n\t\n\tif ((d=PyDimMem_NEW(nd)) == NULL) {\n\t\treturn PyErr_NoMemory();\n }\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) {\n\t\tPyDimMem_FREE(d);\n\t\treturn NULL;\n\t}\n\tif (itemsize == 0 && PyTypeNum_ISFLEXIBLE(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) {\n\t\t\tPyDimMem_FREE(d);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n r=(PyArrayObject*)PyArray_New(&PyArray_Type, nd, d, \n\t\t\t\t type, NULL, NULL,\n\t\t\t\t itemsize, \n\t\t\t\t typecode->fortran, NULL);\n\n PyDimMem_FREE(d);\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\n\nstatic int \nPyArray_ValidType(int type) \n{\n\tPyArray_Descr *descr;\n\t\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr==NULL) return 0;\n\treturn 1;\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->itemsize;\n\tint nels = PyArray_BUFSIZE;\n\tint el;\n\tint inswap, outswap=0;\n\tint obuf=!PyArray_ISCARRAY(out);\n\tint oelsize = out->itemsize;\n\tPyArray_VectorUnaryFunc *castfunc;\n PyArray_CopySwapFunc *in_csn;\n PyArray_CopySwapFunc *out_csn;\n\tint retval = -1;\n\n\tcastfunc = in->descr->cast[out->descr->type_num];\n in_csn = in->descr->copyswap;\n out_csn = out->descr->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\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\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->itemsize * 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\n/* For backward compatibility */\n\nstatic PyObject *\nPyArray_Cast(PyArrayObject *mp, int type_num) \n{\n\tPyArray_Typecode type;\n\tPyArray_Descr *descr;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\ttype.itemsize = descr->elsize;\n\ttype.type_num = descr->type_num;\n\ttype.fortran = 0;\n\t\n\treturn PyArray_CastToType(mp, &type);\n}\n\nstatic PyObject * \nPyArray_CastToType(PyArrayObject *mp, PyArray_Typecode *at) \n{\n\tPyObject *out;\n\tint ret;\n\n\tif ((mp->descr->type_num == at->type_num) && \\\n\t (at->itemsize==0 || mp->itemsize == at->itemsize) &&\n\t PyArray_ISBEHAVED_RO(mp)) {\n\t\tPy_INCREF(mp);\n\t\treturn (PyObject *)mp;\n\t}\n\t\t\n\tif (at->itemsize == 0) {\n\t\tif (mp->descr->type_num == PyArray_STRING &&\t\\\n\t\t at->type_num == PyArray_UNICODE)\n\t\t\tat->itemsize = mp->itemsize*sizeof(Py_UNICODE);\n\t\tif (mp->descr->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING) \n\t\t\tat->itemsize = mp->itemsize/sizeof(Py_UNICODE);\n\t\tif (at->type_num == PyArray_VOID)\n\t\t\tat->itemsize = mp->itemsize;\n\t}\n\n\tout = PyArray_New(mp->ob_type, mp->nd, \n\t\t\t mp->dimensions, \n\t\t\t at->type_num,\n\t\t\t NULL, NULL, at->itemsize, \n\t\t\t at->fortran, (PyObject *)mp);\n\tif (out == NULL) return NULL;\n\tret = PyArray_CastTo((PyArrayObject *)out, mp);\n\tif (ret != -1) return out;\n\n\tPy_DECREF(out);\n\treturn NULL;\n\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\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\tsimple = ((PyArray_ISCARRAY(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY(mp) && PyArray_ISFARRAY(out)));\n\t\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->itemsize * outsize;\n\t\tintp ncopies = outsize / mpsize;\n\n\t\twhile(ncopies--) {\n\t\t\tinptr = mp->data;\n\t\t\tmp->descr->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\nstatic PyObject *\narray_fromarray(PyArrayObject *arr, PyArray_Typecode *typecode, int flags) \n{\n\t\n\tPyArrayObject *ret=NULL;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->itemsize;\n\tint copy = 0;\n\tint arrflags;\n\tPyArray_Typecode oldtype;\n\tchar *msg = \"cannot copy back to a read-only array\";\n PyTypeObject *subtype;\n\n\toldtype.type_num = PyArray_TYPE(arr);\n\toldtype.itemsize = PyArray_ITEMSIZE(arr);\n\toldtype.fortran = 0;\n\n subtype = arr->ob_type;\n\n\tif (type == PyArray_NOTYPE) type = arr->descr->type_num;\n\tif (itemsize == 0) itemsize = arr->itemsize;\n\ttypecode->type_num = type;\n\ttypecode->itemsize = itemsize;\n\n\t/* Don't copy if sizes are compatible */\n\tif (PyArray_EquivalentTypes(&oldtype, typecode)) {\n\t\tarrflags = arr->flags;\n\n\t\tcopy = (flags & ENSURECOPY) || \\\n\t\t\t((flags & CONTIGUOUS) && (!(arrflags & CONTIGUOUS))) \\\n\t\t\t|| (PyArray_ITEMSIZE(arr) != itemsize) || \\\n\t\t\t((flags & ALIGNED) && (!(arrflags & ALIGNED))) || \\\n\t\t\t((flags & NOTSWAPPED) && (!(arrflags & NOTSWAPPED))) \\\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 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_New(subtype, \n\t\t\t\t\t arr->nd, \n\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t arr->descr->type_num,\n\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t itemsize,\n\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t (PyObject *)arr);\n\t\t\tif (PyArray_CopyInto(ret, arr) == -1) 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 ret = (PyArrayObject *) \\\n PyArray_New(&PyArray_Type,\n arr->nd,\n arr->dimensions,\n arr->descr->type_num,\n arr->strides,\n arr->data,\n arr->itemsize,\n arr->flags,NULL);\n if (ret == NULL) return NULL;\n ret->base = (PyObject *)arr;\n ret->flags &= ~UPDATEIFCOPY;\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_CanCastSafely(PyArray_TYPE(arr), type)) {\n if ((flags & UPDATEIFCOPY) && \\\n (!PyArray_ISWRITEABLE(arr))) {\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_New(subtype, arr->nd,\n arr->dimensions, typecode->type_num,\n NULL, NULL, typecode->itemsize,\n typecode->fortran, \n (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\nstatic int\n_array_typecode_fromstr(char *str, int *swap, PyArray_Typecode *type)\n{\n int type_num;\n char typechar;\n int size;\n unsigned long number = 1;\n char *s;\n char msg[] = \"unsupported typestring\";\n \n s = (char *)&number; /* s[0] == 0 implies big-endian */\n\n *swap = 0;\n\n if (str[0] == '<' || str[0] == '>') {\n\tif ((str[0] == '<') && (s[0] == 0)) *swap = 1;\n\telse if ((str[0] == '>') && (s[0] != 0)) *swap = 1;\n }\n str += 1;\n \n#define _MY_FAIL {\t\t\t\t \\\n\t PyErr_SetString(PyExc_ValueError, msg); \\\n\t return -1;\t\t\t \\\n }\t\t\n\n typechar = str[0];\n size = atoi(str + 1);\n switch (typechar) {\n case 'b':\n\t if (size == sizeof(Bool))\n\t\t type_num = PyArray_BOOL;\t \n\t else _MY_FAIL \n\t break;\t\t \n case 'u':\n if (size == sizeof(uintp))\n type_num = PyArray_UINTP;\n\t else if (size == sizeof(char))\n\t\t type_num = PyArray_UBYTE;\n\t else if (size == sizeof(short)) \n\t\t type_num = PyArray_USHORT;\n\t else if (size == sizeof(int)) \n\t\t type_num = PyArray_UINT;\n\t else if (size == sizeof(ulong)) \n\t\t type_num = PyArray_ULONG;\n\t else if (size == sizeof(ulonglong))\n\t\t type_num = PyArray_ULONGLONG;\n\t else _MY_FAIL\n\t break;\t\t \n case 'i':\n if (size == sizeof(intp))\n type_num = PyArray_INTP;\n\t else if (size == sizeof(char)) \n\t\t type_num = PyArray_BYTE;\n\t else if (size == sizeof(short)) \n\t\t type_num = PyArray_SHORT;\n\t else if (size == sizeof(int))\n\t\t type_num = PyArray_INT;\n\t else if (size == sizeof(long)) \n\t\t type_num = PyArray_LONG;\n\t else if (size == sizeof(longlong))\n\t\t type_num = PyArray_LONGLONG;\n\t else _MY_FAIL\n\t break;\t\t \n case 'f':\n\t if (size == sizeof(float))\n\t\t type_num = PyArray_FLOAT;\n\t else if (size == sizeof(double))\n\t\t type_num = PyArray_DOUBLE;\n\t else if (size == sizeof(longdouble))\n\t\t type_num = PyArray_LONGDOUBLE;\n\t else _MY_FAIL\n\t break;\n case 'c':\n\t if (size == sizeof(float)*2)\n\t\t type_num = PyArray_CFLOAT;\n\t else if (size == sizeof(double)*2)\n\t\t type_num = PyArray_CDOUBLE;\n\t else if (size == sizeof(longdouble)*2)\n\t\t type_num = PyArray_CLONGDOUBLE;\n\t else _MY_FAIL\n\t break;\n case 'O':\n\t if (size == sizeof(PyObject *))\n\t\t type_num = PyArray_OBJECT;\n\t else _MY_FAIL\n\t break;\n case 'S':\n\t type_num = PyArray_STRING;\n\t break;\n case 'U':\n\t type_num = PyArray_UNICODE;\n\t size *= sizeof(Py_UNICODE);\n\t break;\t \n case 'V':\n\t type_num = PyArray_VOID;\n\t break;\n default:\n\t _MY_FAIL\n }\n\n#undef _MY_FAIL\n\n type->type_num = type_num;\n type->itemsize = size;\n type->fortran = 0;\n return 0;\n}\n\nstatic PyObject *\narray_frominterface(PyObject *input, PyArray_Typecode *intype, int flags)\n{\n\tPyObject *attr=NULL, *item=NULL, *r;\n\tPyArrayObject *ret=NULL;\n\tPyArray_Typecode type;\n\tchar *data;\n\tint buffer_len;\n\tint res, i, n;\n\tintp dims[MAX_DIMS], strides[MAX_DIMS];\n\tint swap;\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\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) {Py_XDECREF(attr); return NULL;}\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t}\n\telse {\n\t\tif (PyTuple_GET_SIZE(attr) != 2) {\n\t\t\tPy_DECREF(attr);\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\treturn NULL;\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\tPy_DECREF(attr);\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\treturn NULL;\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 = PyObject_GetAttrString(input, \"__array_typestr__\");\n\tif (!PyString_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_typestr__ must be a string\");\n\t\tPy_DECREF(attr);\n\t\treturn NULL;\t\n\t}\n\tres = _array_typecode_fromstr(PyString_AS_STRING(attr), &swap, &type);\n\tPy_DECREF(attr);\n\tif (res < 0) return NULL;\n \n\tattr = PyObject_GetAttrString(input, \"__array_shape__\");\n\tif (!PyTuple_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_shape__ must be a tuple\");\n\t\tPy_DECREF(attr);\n\t\treturn NULL;\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\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\treturn NULL;\n\t\t}\n\t\tfor (i=0; istrides, strides, n*sizeof(intp));\n\t}\n\n\tif (swap) {\n\t\tPyObject *tmp;\n tmp = PyArray_Byteswap(ret, TRUE);\n\t\tPy_DECREF(tmp);\n\t}\n\n\tPyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n\tr = array_fromarray(ret, intype, flags);\n\tPy_DECREF(ret);\n\treturn r;\n}\n\nstatic PyObject *\narray_fromattr(PyObject *op, PyArray_Typecode *typecode, int flags) \n{\n PyObject *new, *r;\n\t \n if (typecode->type_num == PyArray_NOTYPE) {\n new = PyObject_CallMethod(op, \"__array__\", NULL);\n } else {\n\t\tPyArray_Descr *descr;\n\t\tPyObject *obj;\n\n\t\tdescr = PyArray_DescrFromType(typecode->type_num);\n\t\tif (PyTypeNum_ISFLEXIBLE(typecode->type_num)) {\n\t\t\tobj = PyString_FromFormat(\"%c%d\", descr->type,\n\t\t\t\t\t\t typecode->itemsize);\n\t\t}\n\t\telse { \n\t\t\tobj = (PyObject *)(descr->typeobj); Py_INCREF(obj);\n\t\t}\n\t\tnew = PyObject_CallMethod(op, \"__array__\", \"N\", obj);\n }\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 r = array_fromarray((PyArrayObject *)new, typecode, flags);\n Py_DECREF(new);\n return r;\n} \n\n\nstatic PyObject *\narray_fromobject(PyObject *op, PyArray_Typecode *typecode, int min_depth, \n\t\t int max_depth, int flags) \n{\n /* This is the main code to make a NumPy array from a Python\n Object. It is called from lot's of different places which\n is why there are so many checks. The comments try to\n explain some of the checks. */\n\n\tint type = typecode->type_num;\n PyObject *r=NULL;\n\n\t/* Is input object already an array? */\n\t/* This is where the flags are used */\n if (PyArray_Check(op)) \n\t\tr = array_fromarray((PyArrayObject *)op, typecode, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, typecode);\n\t}\n\telse if (PyObject_HasAttrString(op, \"__array__\")) {\n\t\t/* Code that returns the object to convert for a non\n\t\t multiarray input object from the __array__ attribute of the\n\t\t object. */\n r = array_fromattr(op, typecode, flags);\n\t}\n\telse if (PyObject_HasAttrString(op, \"__array_shape__\") &&\n\t\t PyObject_HasAttrString(op, \"__array_typestr__\")) {\n\t\tr = array_frominterface(op, typecode, flags);\n\t}\n\telse {\n\t\tif (type == PyArray_NOTYPE) {\n\t\t\t_array_find_type(op, NULL, typecode, MAX_DIMS);\n\t\t}\n\t\tif (PySequence_Check(op))\n\t\t\tr = Array_FromSequence(op, typecode, \n\t\t\t\t\t min_depth, max_depth);\n\t\telse\n\t\t\tr = Array_FromScalar(op, typecode);\n\t}\n\n /* If we didn't succed return NULL */\n if (r == NULL) return NULL;\n\t\n\t/* Be sure we succeed here */\n\t\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"internal error: array_fromobject \"\\\n\t\t\t\t\"not producing an array\");\n\t\tPy_DECREF(r);\n return NULL;\n }\n\n if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {\n Py_DECREF(r);\n PyErr_SetString(PyExc_ValueError, \n \"object of too small depth for desired array\");\n return NULL;\n }\n if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {\n Py_DECREF(r);\n PyErr_SetString(PyExc_ValueError, \n \"object too deep for desired array\");\n return NULL;\n }\n return r;\n}\n\nstatic void\nPyArray_ArrayType(PyObject *op, PyArray_Typecode *intype, \n\t\t PyArray_Typecode *outtype) \n{\n\t_array_find_type(op, intype, outtype, MAX_DIMS);\n\treturn;\n}\n\nstatic int \nPyArray_ObjectType(PyObject *op, int minimum_type) \n{\n\tPyArray_Typecode intype, outtype;\n\tintype.type_num = minimum_type;\n\t_array_find_type(op, &intype, &outtype, MAX_DIMS);\n\treturn outtype.type_num;\n}\n\n\n\n/* flags is any of \n CONTIGUOUS, \n FORTRAN, (or set typecode->fortran=1)\n ALIGNED, \n NOTSWAPPED, \n WRITEABLE, \n ENSURECOPY, \n UPDATEIFCOPY,\n FORCECAST,\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, NOTSWAPPED, and WRITEABLE\n and therefore it is redundant to include those as well. \n\n BEHAVED_FLAGS == ALIGNED | NOTSWAPPED | WRITEABLE\n BEHAVED_FLAGS_RO == ALIGNED | NOTSWAPPED\n CARRAY_FLAGS = CONTIGUOUS | BEHAVED_FLAGS\n FARRAY_FLAGS = FORTRAN | BEHAVED_FLAGS\n \n By default, the returned array will be a copy of the object, \n (C) contiguous in memory, aligned, notswapped, and writeable.\n \n So CONTIGUOUS | ENSURECOPY passed in means that the returned\n array does not have to be CONTIGUOUS or a COPY but should be\n ALIGNED, NOTSWAPPED and WRITEABLE. \n\n typecode->fortran can be set to request a\n fortran-contiguous array. Fortran arrays are always behaved (aligned, \n notswapped, and writeable) and not (C) CONTIGUOUS. Note that either\n FORTRAN in the flag or typecode->fortran = 1 is enough to request\n a FORTRAN-style array. \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\nstatic PyObject *\nPyArray_FromAny(PyObject *op, PyArray_Typecode *typecode, int min_depth, \n\t\tint max_depth, int requires) \n{\n \tPyArray_Typecode mine = {PyArray_NOTYPE, 0, 0};\n\tPyArray_Typecode *type;\n\t\n\tif (typecode == NULL) type = &mine;\n\telse type = typecode;\n\t\t\n\tif (requires & ENSURECOPY) {\n\t\trequires |= DEFAULT_FLAGS;\n\t}\n\t/* Ensure that type->fortran and flags & FORTRAN are the\n\t same */\n\tif (requires & FORTRAN) typecode->fortran = 1;\n\tif (type->fortran == 1) {\n\t\trequires |= FARRAY_FLAGS;\n\t\tif (min_depth > 2) requires &= ~CONTIGUOUS;\n\t}\n\n\t/* make sure itemsize is not 0 unless warranted. */\n\tif ((type->itemsize == 0) && (type->type_num != PyArray_NOTYPE)) {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(type->type_num);\n\t\tif (descr != NULL) type->itemsize = descr->elsize;\n\t\telse return NULL;\n\t}\n\t\n\treturn array_fromobject(op, type, min_depth, max_depth, \n\t\t\t\trequires);\t\n}\n\n/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0, 0) */\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\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);\n Py_DECREF(op);\n return new;\n}\n\n/* These are all compressed into a single API */\n/* Deprecated calls -- Use PyArray_FromAny */\n\nstatic PyObject *\nPyArray_FromObject(PyObject *op, int type, int min_depth, int max_depth) \n{\n\tPyArray_Typecode typecode = {0, 0, 0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth,\n\t\t\t max_depth, BEHAVED_FLAGS | ENSUREARRAY);\n}\n\nstatic PyObject *\nPyArray_ContiguousFromObject(PyObject *op, int type, int min_depth, \n\t\t\t int max_depth) \n{\n\tPyArray_Typecode typecode = {0, 0, 0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth,\n\t\t\t max_depth, DEFAULT_FLAGS | ENSUREARRAY);\n}\n\nstatic PyObject *\nPyArray_CopyFromObject(PyObject *op, int type, int min_depth, \n\t\t int max_depth) \n{\n\tPyArray_Typecode typecode = {0, 0, 0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth, max_depth,\n\t\t\t ENSURECOPY | ENSUREARRAY);\n}\n\n/* End of deprecated */\n\nstatic PyObject *\nPyArray_ContiguousFromAny(PyObject *op, int type, int min_depth, \n\t\t\t int max_depth)\n{\n\tPyArray_Typecode typecode = {0,0,0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth,\n\t\t\t max_depth, DEFAULT_FLAGS);\n}\t\n\nstatic int \nPyArray_CanCastSafely(int fromtype, int totype) \n{\n\tPyArray_Descr *from, *to;\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\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 (to->elsize > from->elsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (to->elsize >= from->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (from->elsize < 8)\n return (to->elsize > from->elsize);\n else\n return (to->elsize >= from->elsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (from->elsize < 8)\n return ((to->elsize >> 1) > from->elsize);\n else\n return ((to->elsize >> 1) >= from->elsize);\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 (to->elsize > from->elsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (to->elsize >= from->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (from->elsize < 8)\n return (to->elsize > from->elsize);\n else\n return (to->elsize >= from->elsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (from->elsize < 8)\n return ((to->elsize >> 1) > from->elsize);\n else\n return ((to->elsize >> 1) >= from->elsize);\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 ((to->elsize >> 1) >= from->elsize);\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\nstatic Bool\nPyArray_CanCastTo(PyArray_Typecode *from, PyArray_Typecode *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->itemsize <= to->itemsize);\n\t\t\t}\n\t\t\telse if (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->itemsize * sizeof(Py_UNICODE)\\\n\t\t\t\t <= to->itemsize);\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->itemsize <= to->itemsize);\n\t\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 scipy's arraymap ****/\n/* and Python's array iterator ***/\n \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 = PyObject_GC_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 PyObject_GC_Track(it);\n return (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 PyObject_GC_UnTrack(it);\n Py_XDECREF(it->ao);\n PyObject_GC_Del(it);\n }\n\nstatic int\narrayiter_traverse(PyArrayIterObject *it, visitproc visit, void *arg)\n{\n if (it->ao != NULL)\n return visit((PyObject *)(it->ao), arg);\n return 0;\n}\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->itemsize;\n\tr = PyArray_New(self->ao->ob_type, 1, &count, \n\t\t\tself->ao->descr->type_num, NULL, NULL,\n\t\t\titemsize, 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->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->itemsize;\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\tr = PyArray_New(self->ao->ob_type, ind->nd, ind->dimensions,\n\t\t\tself->ao->descr->type_num, NULL, \n\t\t\tNULL, self->ao->itemsize, \n\t\t\t0, (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)->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\tint i;\n\tPyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tint 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\t\t\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\n\t/* Tuples 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\tr = PyArray_New(self->ao->ob_type, 1, &ii, \n\t\t\t\t\tself->ao->descr->type_num, NULL, \n\t\t\t\t\tNULL, self->ao->itemsize, 0,\n\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 */\n\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->itemsize;\n\t\tr = PyArray_New(self->ao->ob_type, 1, &n_steps, \n\t\t\t\tself->ao->descr->type_num, NULL, NULL,\n\t\t\t\tsize, 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)->copyswap;\n\t\twhile(n_steps--) {\n copyswap(dptr, self->dataptr, swap, size);\n\t\t\tfor(i=0; i< step_size; i++) \n\t\t\t\tPyArray_ITER_NEXT(self);\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\tif (PyArray_IsScalar(ind, Integer) || PyList_Check(ind)) {\n\t\tobj = PyArray_FromAny(ind, &indtype, 0, 0, FORCECAST);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tr = iter_subscript_Bool(self, (PyArrayObject *)obj);\n\t\t} \n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, &indtype, 0, 0, \n\t\t\t\t\t FORCECAST | BEHAVED_FLAGS);\n\t\t\tif (new==NULL) goto fail;\n\t\t\tobj = new;\n\t\t\tr = iter_subscript_int(self, (PyArrayObject *)obj);\n\t\t}\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\t\"unsupported iterator index\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPy_DECREF(obj);\n\t\treturn r;\n\t}\n\n\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\n fail:\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->itemsize;\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->copyswap;\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(self->dataptr, val->dataptr, swap,\n itemsize);\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t\tPyArray_ITER_NEXT(val);\n\t\tif (val->index==val->size) \n\t\t\tPyArray_ITER_RESET(val);\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_Typecode typecode;\n\tintp num;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\titemsize = typecode.itemsize = self->ao->itemsize;\n\ttypecode.type_num = self->ao->descr->type_num;\n copyswap = self->ao->descr->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\n\nstatic int\niter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val) \n{\n\tint i;\n\tPyObject *arrval=NULL;\n\tPyArrayIterObject *val_it=NULL;\n\tPyArray_Typecode type;\n\tPyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tint swap;\n\tint itemsize;\n\tint start, step_size;\n\tintp n_steps;\n\tPyObject *obj;\n PyArray_CopySwapFunc *copyswap;\n\t\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\ti = iter_ass_subscript(self, ind, val);\n\t\tPy_DECREF(ind);\n\t\treturn i;\n\t}\n\t\n\ttype.type_num = self->ao->descr->type_num;\n\titemsize = type.itemsize = self->ao->itemsize;\n\t\n\tarrval = PyArray_FromAny(val, &type, 0, 0, 0);\n\tif (arrval==NULL) return -1;\n\tval_it = (PyArrayIterObject *)PyArray_IterNew(arrval);\n\tif (val_it==NULL) goto fail;\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\n copyswap = PyArray_DESCR(arrval)->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\tgoto succeed;\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 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 copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, itemsize);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\tgoto succeed;\n\t\t}\n\t\twhile(n_steps--) {\n copyswap(self->dataptr, val_it->dataptr,\n swap, itemsize);\n\t\t\tfor(i=0; i < step_size; i++) \n\t\t\t\tPyArray_ITER_NEXT(self);\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\tgoto succeed;\n\t} \n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tif (PyArray_IsScalar(ind, Integer))\n\t\tobj = PyArray_FromScalar(ind, &indtype);\n\telse if (PyList_Check(ind)) {\n\t\tobj = PyArray_FromAny(ind, &indtype, 0, 0, FORCECAST);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tif (iter_ass_sub_Bool(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto fail;\n\t\t} \n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, &indtype, 0, 0, \n\t\t\t\t\t FORCECAST | BEHAVED_FLAGS);\n\t\t\tif (new==NULL) goto fail;\n\t\t\tPy_DECREF(obj);\n\t\t\tobj = new;\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 fail;\n\t\t}\n\t\telse goto fail;\n\t\tPy_DECREF(obj);\n\t\tgoto succeed;\n\t}\n\n\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\tgoto fail;\n\n succeed:\n\tPy_DECREF(val_it);\n\tPy_DECREF(arrval);\n\treturn 0;\n\n fail:\n\tPy_XDECREF(val_it);\n\tPy_XDECREF(arrval);\n\treturn -1;\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 if (PyArray_ISCONTIGUOUS(it->ao)) {\n r = PyArray_New(it->ao->ob_type, 1, &size, \n\t\t\t\tit->ao->descr->type_num,\n NULL, it->ao->data, it->ao->itemsize, \n\t\t\t\tit->ao->flags,\n (PyObject *)it->ao); \n\t\tif (r==NULL) return NULL;\n }\n else {\n r = PyArray_New(it->ao->ob_type, 1, &size, \n\t\t\t\tit->ao->descr->type_num,\n NULL, NULL, it->ao->itemsize, 0, \n (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\n\nstatic PyTypeObject PyArrayIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"scipy.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 | Py_TPFLAGS_HAVE_GC,/* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)arrayiter_traverse,\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)arrayiter_next,\t\t/* tp_iternext */\n iter_methods,\t\t\t\t/* tp_methods */\n};\n\n/** END of Array Iterator **/\n\n\n\n/*********************** Subscript Array Iterator *************************\n * *\n * This object handles subscript behavior for array objects. *\n * It is an iterator object with a next method *\n * It abstracts the n-dimensional mapping behavior to make the looping *\n * code more understandable (maybe) *\n * and so that indexing can be set up ahead of time *\n */ \n\n/* This checks the args for any fancy indexing objects */\n\n#define SOBJ_NOTFANCY 0 \n#define SOBJ_ISFANCY 1\n#define SOBJ_BADARRAY 2\n#define SOBJ_TOOMANY 3\n#define SOBJ_LISTTUP 4\n\nstatic int\nfancy_indexing_check(PyObject *args)\n{\n\tint i, n;\n\tPyObject *obj;\n\tint retval = SOBJ_NOTFANCY;\n\n\tif (PyTuple_Check(args)) {\n\t\tn = PyTuple_GET_SIZE(args);\n\t\tif (n >= MAX_DIMS) return SOBJ_TOOMANY;\n\t\tfor (i=0; i=MAX_DIMS) return SOBJ_ISFANCY;\n\t\tfor (i=0; i SOBJ_ISFANCY) return retval;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* convert an indexing object to an INTP indexing array iterator\n if possible -- otherwise, it is a Slice or Ellipsis object\n and has to be interpreted on bind to a particular \n array so leave it NULL for now.\n */\nstatic int\n_convert_obj(PyObject *obj, PyArrayIterObject **iter)\n{\n\tPyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tPyObject *arr;\n\n\tif (PySlice_Check(obj) || (obj == Py_Ellipsis))\n\t\t*iter = NULL;\n\telse {\n\t\tarr = PyArray_FromAny(obj, &indtype, 0, 0, FORCECAST);\n\t\tif (arr == NULL) return -1;\n\t\t*iter = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (*iter == NULL) return -1;\n\t}\n\treturn 0;\n}\n\n/* Adjust dimensionality and strides for index object iterators \n --- i.e. broadcast\n */\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->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->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=NULL, *obj=NULL;\n\tint i, j, n, curraxis, ellipexp, noellip;\n\tPyArrayIterObject *it;\n\tintp dimsize;\n\tintp *indptr;\n\n\t/* Remove old binding if any */\n\tPy_XDECREF(mit->ait);\n\tmit->ait = NULL;\n\n\tPy_XDECREF(mit->subspace);\n\tmit->subspace = NULL;\n\t\n\tsubnd = arr->nd - mit->numiter;\n\tif (subnd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"too many indices for array\");\n\t\treturn;\n\t}\n\n\tmit->ait = (PyArrayIterObject *)PyArray_IterNew((PyObject *)arr);\n\tif (mit->ait == NULL) return;\n\n\t/* If this is just a view, then do nothing more */\n\t/* views are handled by just adjusting the strides\n\t and dimensions of the object.\n\t*/\n\t \n\tif (mit->view) return;\n\n\t/* no subspace iteration needed. 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\tif (mit->subspace == NULL) goto fail;\n\tPy_DECREF(sub);\n\n\t/* Expand dimensions of result */\n\tn = mit->subspace->ao->nd;\n\tfor (i=0; idimensions[mit->nd+i] = mit->subspace->ao->dimensions[i];\n\tmit->nd += n;\n\n\t/* Now, we still need to interpret the ellipsis and slice objects \n\t to determine which axes the indexing arrays are referring to\n\t*/\n\tn = PyTuple_GET_SIZE(mit->indexobj);\n\n\t/* The number of dimensions an ellipsis takes up */\n\tellipexp = arr->nd - n + 1;\n\t/* Now fill in iteraxes -- remember indexing arrays have been \n converted to 0's in mit->indexobj */\n\tcurraxis = 0;\n\tj = 0;\n\tnoellip = 1; /* Only expand the first ellipsis */\n\tmemset(mit->bscoord, 0, sizeof(intp)*arr->nd);\n\tfor (i=0; iindexobj, i);\n\t\tif (PyInt_Check(obj) || PyLong_Check(obj)) \n\t\t\tmit->iteraxes[j++] = curraxis++;\n\t\telse if (noellip && obj == Py_Ellipsis) {\n\t\t\tcurraxis += ellipexp;\n\t\t\tnoellip = 0;\n\t\t}\n\t\telse {\n\t\t\tint start=0;\n\t\t\tint 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}\t\t\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn;\n\n fail:\n\tPy_XDECREF(sub);\n\tPy_XDECREF(mit->ait);\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_Typecode typecode = {PyArray_BOOL, 0, 0};\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\tba = (PyArrayObject *)PyArray_FromAny(myBool, &typecode, 0, 0, \n\t\t\t\t\t CARRAY_FLAGS);\n\tif (ba == NULL) return -1;\n\tnd = ba->nd;\n\tfor (j=0; jdata;\n\tcount = 0;\n\n\t/* pre-determine how many nonzero entries there are */\n\tfor (i=0; iao->data;\n\t\tcoords[j] = 0;\n\t\tdims_m1[j] = ba->dimensions[j]-1;\n\t}\n\n\tptr = (Bool *)ba->data;\n\n\tif (count == 0) return nd;\n\n\t/* Loop through the Boolean array and copy coordinates\n\t for non-zero entries */\n\tfor (i=0; i=0; j--) {\n\t\t\tif (coords[j] < dims_m1[j]) {\n\t\t\t\tcoords[j]++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcoords[j] = 0;\n\t\t\t}\n\t\t}\n\t}\n\treturn nd;\n\n fail:\n\tfor (j=0; jiters[i] = NULL;\n \tmit->view = 0;\n \tmit->index = 0;\n \tmit->ait = NULL;\n \tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tfancy = fancy_indexing_check(indexobj);\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\tif (fancy == SOBJ_NOTFANCY) { /* bail out */\n\t\tmit->view = 1;\n\t\tgoto ret;\n\t}\n\n\tif (fancy == SOBJ_BADARRAY) {\n\t\tPyErr_SetString(PyExc_TypeError,\t\t\t\\\n\t\t\t\t\"arrays used as indexes must be of \" \\\n\t\t\t\t\"integer type\");\n\t\tgoto fail;\n\t}\n\tif (fancy == SOBJ_TOOMANY) {\n\t\tPyErr_SetString(PyExc_TypeError, \"too many indicies\");\n\t\tgoto fail;\n\t}\n\n\tif (fancy == SOBJ_LISTTUP) {\n\t\tPyObject *newobj;\n\t\tnewobj = PySequence_Tuple(indexobj);\n\t\tif (newobj == NULL) goto fail;\n\t\tPy_DECREF(indexobj);\n\t\tindexobj = newobj;\n\t\tmit->indexobj = indexobj;\n\t}\n\n#undef SOBJ_NOTFANCY \n#undef SOBJ_ISFANCY \n#undef SOBJ_BADARRAY \n#undef SOBJ_TOOMANY \n#undef SOBJ_LISTTUP \n\n\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\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 (PyList_Check(indexobj) || PyArray_Check(indexobj)) {\n\t\tmit->numiter = 1;\n\t\tarr = PyArray_FromAny(indexobj, &indtype, 0, 0, FORCECAST);\n\t\tif (arr == NULL) goto fail;\n\t\tmit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (mit->iters[0] == NULL) 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(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\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = new;\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\t/* Store the number of iterators actually converted */\n\t\t/* These will be mapped to actual axes at bind time */\n\t\tif (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)\n\t\t\tgoto fail;\n\t}\n\n ret:\n PyObject_GC_Track(mit);\n return (PyObject *)mit;\n \n fail:\n\tPy_XDECREF(arr);\n\tPy_XDECREF(mit->indexobj);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n PyObject_GC_Del(mit);\n\treturn NULL;\n}\n\n\n/* return unbound mapiter object */\n\nstatic PyObject *\narraymapiter_new(PyTypeObject *type, PyObject *args, PyObject *kwds) \n{\n\tPyObject *newtup, *res;\n\tint n;\n\n\tif (!PyTuple_Check(args)) {\n\t\tPyErr_BadInternalCall();\n\t\treturn NULL;\n\t}\n\n\tn = PyTuple_GET_SIZE(args);\n\t\n\tif (n < 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"must be initialized with >= 1 argument\");\n\t\treturn NULL;\n\t}\n\t\n\tif (n > 1) {\n\t\tnewtup = PyTuple_GetSlice(args, 0, n);\n\t\tif (newtup == NULL) return NULL;\n\t\tres = PyArray_MapIterNew(newtup);\n\t\tPy_DECREF(newtup);\n\t}\n\telse { /* n == 1 */\n\t\tnewtup = PyTuple_GET_ITEM(args, 0);\n\t\tres = PyArray_MapIterNew(newtup);\n\t}\n\n\treturn res; \t\n}\n\n\n/* Returns a 0-dim array holding the element desired */\n/*\nstatic PyObject *\narraymapiter_next(PyArrayMapIterObject *mit)\n{\n\tPyObject *ret;\n\tif (mit->ait == NULL) return NULL;\n\tif (mit->view) return NULL;\n\tif (mit->index < mit->size) {\n\t\tret = PyArray_ToScalar(mit->dataptr, mit->ait->ao);\n\t\tPyArray_MapIterNext(mit);\n\t\treturn ret;\n\t}\n return NULL;\n}\n*/\n\nstatic void\narraymapiter_dealloc(PyArrayMapIterObject *mit)\n{\n\tint i;\n PyObject_GC_UnTrack(mit);\n Py_XDECREF(mit->ait);\n\tPy_XDECREF(mit->indexobj);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n PyObject_GC_Del(mit);\n}\n\nstatic int\narraymapiter_traverse(PyArrayMapIterObject *mit, visitproc visit, void *arg)\n{\n\tint ret, i;\n if (mit->ait != NULL)\n if ((ret = visit((PyObject *)(mit->ait), arg)) != 0) \n\t\t\treturn ret;\t\n\n\tif (mit->iters != NULL) \n\t\tfor (i=0; inumiter; i++) \n\t\t\tif (mit->iters[i] != NULL) \n\t\t\t\tif ((ret=visit((PyObject *)mit->iters[i], \n\t\t\t\t\t arg)) != 0)\n\t\t\t\t\treturn ret;\n\n\tif (mit->indexobj != NULL)\n\t\tif ((ret = visit(mit->indexobj, arg)) != 0) return ret;\n\t\n return 0;\n}\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 MapIterNew must be \n that does not work. 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 char doc_mapiter_bind[] = \"obj.bind(a)\\n Bind an array to the \"\\\n\t\"mapiter object\";\n\nstatic PyObject *\nmapiter_bind(PyArrayMapIterObject *mit, PyObject *args)\n{\n\tPyArrayObject *arr;\n\n if (!PyArg_ParseTuple(args, \"O!\", &PyArray_Type, &arr)) return NULL;\n\n \tPyArray_MapIterBind(mit, arr);\n\n\tif (mit->ait == NULL) return NULL;\n\t\n \tPyArray_MapIterReset(mit);\n\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyMethodDef mapiter_methods[] = {\n\t{\"bind\", (PyCFunction)mapiter_bind, 1, doc_mapiter_bind},\n {NULL,\t\tNULL}\t\t\n};\n*/\n\n\nstatic PyTypeObject PyArrayMapIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"scipy.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 | Py_TPFLAGS_HAVE_GC,/* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)arraymapiter_traverse,\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, /*arraymapiter_next,*/\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 (newfunc)arraymapiter_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n\n};\n\n/** END of Subscript Iterator **/\n\n\n\n", "source_code_before": " /*\n Provide multidimensional arrays as a basic object type in python. \n\nBased on Original Numeric implementation\nCopyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\nwith contributions from many Numeric Python developers 1995-2004 *\n\nHeavily modified in 2005 with inspiration from Numarray \n\nby\n\nTravis Oliphant\nAssistant Professor at\nBrigham Young University \n\nmaintainer email: oliphant.travis@ieee.org\n\nNumarray design (which provided guidance) by \nSpace Science Telescope Institute \n (J. Todd Miller, Perry Greenfield, Rick White)\n\n*/\n\n/* $Id: arrayobject.c,v 1.59 2005/09/14 00:14:00 teoliphant Exp $ */\n\n/*\n#include \"Python.h\"\n#include \"structmember.h\"\n\n#define _MULTIARRAYMODULE\n#include \"Numeric3/arrayobject.h\"\n*/\n\n/* Helper functions */\n\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\n\nstatic intp\nPyArray_PyIntAsIntp(PyObject *o)\n{\n\tlonglong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr=NULL;\n\tPyArray_Typecode typecode = {PyArray_INTP, 0, 0};\n\tintp ret;\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\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\tarr = PyArray_CastToType((PyArrayObject *)o, &typecode);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tarr = PyArray_FromScalar(o, &typecode);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((intp *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\t\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONGLONG != SIZEOF_PY_INTPTR_T)\n\tif ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C intp\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (intp) long_value;\n}\n\n\nstatic PyObject *array_int(PyArrayObject *v);\n\nstatic int\nPyArray_PyIntAsInt(PyObject *o)\n{\n\tlong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr=NULL;\n\tPyArray_Typecode typecode = {PyArray_INT, 0, 0};\n\tint ret;\n\t\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\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\tarr = PyArray_CastToType((PyArrayObject *)o, &typecode);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tarr = PyArray_FromScalar(o, &typecode);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((int *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONG != SIZEOF_INT)\n\tif ((long_value < INT_MIN) || (long_value > INT_MAX)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C int\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (int) long_value;\n}\n\n\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\nstatic char *\nPyArray_Zero(PyArrayObject *arr)\n{\n char *zeroval;\n char *buf;\n int buf_len;\n PyObject *obj, *ret;\n\n zeroval = PyDataMem_NEW(arr->itemsize);\n if (zeroval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n if (PyArray_ISOBJECT(arr)) {\n obj=PyInt_FromLong((long) 0);\n memcpy(zeroval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return zeroval;\n }\n ret = PyObject_GetAttrString((PyObject *)arr, \"_zero\");\n if (ret != NULL) {\n if (PyObject_AsReadBuffer(ret, (const void **)&buf, \n &buf_len) < 0) {\n PyErr_SetString(PyExc_ValueError, \n \"_zero not returning \" \\\n \"writeable buffer\");\n Py_DECREF(ret);\n return NULL;\n }\n memcpy(zeroval, buf, buf_len);\n Py_DECREF(ret);\n }\n if (PyErr_Occurred()) PyErr_Clear();\n memset(zeroval, 0, arr->itemsize);\n return zeroval;\n}\n\nstatic char *\nPyArray_One(PyArrayObject *arr)\n{\n char *oneval;\n char *buf;\n int buf_len, ret2;\n PyObject *obj, *ret;\n\n oneval = PyDataMem_NEW(arr->itemsize);\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 ret = PyObject_GetAttrString((PyObject *)arr, \"_one\");\n if (ret != NULL) {\n if (PyObject_AsReadBuffer(ret, (const void **)&buf, \n &buf_len) < 0) {\n PyErr_SetString(PyExc_ValueError, \n \"_one not returning \" \\\n \"writeable buffer\");\n Py_DECREF(ret);\n PyDataMem_FREE(oneval);\n return NULL;\n }\n memcpy(oneval, buf, buf_len);\n Py_DECREF(ret);\n }\n if (PyErr_Occurred()) PyErr_Clear();\n\n ret2 = arr->descr->setitem(obj, oneval, arr);\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->itemsize;\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 *)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 { free(new_data); return NULL; }\n}\n\n/* end Helper functions */\n\n\nstatic PyObject *PyArray_New(PyTypeObject *, int nd, intp *, \n int, intp *, char *, 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. */\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/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\n\nstatic char *\nindex2ptr(PyArrayObject *mp, int i) \n{\n\tif (i==0 && (mp->nd == 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\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\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 \"destination number of elements must be\"\\\n \"an integer multiple of the source number of\"\\\n \"elements\");\n return -1;\n }\n ncopies = (dsize / ssize);\n\n\tswap = PyArray_ISNOTSWAPPED(dest) != PyArray_ISNOTSWAPPED(src);\n\tcopyswap = dest->descr->copyswap;\n\tcopyswapn = dest->descr->copyswapn;\n\n elsize = dest->itemsize;\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->itemsize;\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\tPyArray_Typecode typecode;\n\n\n\ttypecode.type_num = dest->descr->type_num;\n\ttypecode.itemsize = dest->itemsize;\n\ttypecode.fortran = PyArray_ISFORTRAN(dest);\n\t\t\t\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n\t\t\t\t\t &typecode, 0,\n\t\t\t\t\t dest->nd, 0);\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\nstatic PyObject *\nPyArray_FromDimsAndDataAndDescr(int nd, int *d, \n PyArray_Descr *descr,\n char *data) {\n\tPyObject *ret;\n\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\n\tintp newd[MAX_DIMS];\n\t\n\tfor (i=0; itype_num, NULL, data, descr->elsize, \n\t\t\t CARRAY_FLAGS, NULL);\n#else\n\tret = PyArray_New(&PyArray_Type, nd, (intp *)d, \n descr->type_num, NULL, data, descr->elsize, \n\t\t\t CARRAY_FLAGS, NULL);\n#endif\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_FromDimsAndData(int nd, int *d, int type, char *data) \n{\n\tPyObject *ret;\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\t\n\tintp newd[MAX_DIMS];\n\n\tfor (i=0; iob_type, m1->nd, \n\t\t\t\t\t m1->dimensions,\n\t\t\t\t\t m1->descr->type_num,\n\t\t\t\t\t NULL, NULL, m1->itemsize,\n\t\t\t\t\t 0, (PyObject *)m1);\n\t\n if (PyArray_CopyInto(ret, m1) == -1) return NULL;\n\t\n return (PyObject *)ret;\n}\n\n\nstatic PyObject *array_item(PyArrayObject *, int);\n\nstatic PyObject *\nPyArray_Scalar(char *data, int type_num, int itemsize, int swap)\n{\n PyArray_Descr *descr;\n\tPyTypeObject *type;\n\tPyObject *obj;\t\n\tchar *destptr;\n PyArray_CopySwapFunc *copyswap;\n\n descr = PyArray_DescrFromType(type_num);\n if (descr == NULL) return NULL;\n type = descr->typeobj;\n copyswap = descr->copyswap;\n\tif (type_num == PyArray_STRING) \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_ISFLEXIBLE(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 {\n\t\t\tdestptr = PyDataMem_NEW(itemsize);\n\t\t\tif (destptr == NULL) {\n\t\t\t\tPyObject_Del(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tif (type_num == PyArray_UNICODE) {\n\t\t\t\tPyUnicode_AS_UNICODE(obj) = \\\n\t\t\t\t\t(Py_UNICODE *)destptr;\n\t\t\t\t((PyUnicodeObject*)obj)->length = itemsize / \\\n\t\t\t\t\tsizeof(Py_UNICODE);\n\t\t\t\t((PyUnicodeObject*)obj)->hash = -1;\n\t\t\t}\n\t\t\telse {\n\t\t\t\t((PyVoidScalarObject *)obj)->obval = destptr;\n\t\t\t\t((PyVoidScalarObject *)obj)->ob_size = itemsize;\n\t\t\t}\n\t\t}\n\t}\n\telse {\n\t\tdestptr = &(((PyScalarObject*)obj)->obval);\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*/\nstatic PyObject *\nPyArray_ToScalar(char *data, PyArrayObject *arr)\n{\n\tint type_num = arr->descr->type_num;\n\tint itemsize = arr->itemsize;\n int swap = !(PyArray_ISNOTSWAPPED(arr));\n\n\treturn PyArray_Scalar(data, type_num, itemsize, swap);\n}\n\n\n/* Return Python scalar if 0-d array object is encountered */\n\nstatic PyObject *\nPyArray_Return(PyArrayObject *mp) \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((PyObject *)mp) && 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*/\nstatic int \nPyArray_RegisterDataType(PyTypeObject *type)\n{\n\tPyArray_Descr *descr;\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 = malloc(sizeof(PyArray_Descr));\n\tmemcpy(descr, PyArray_DescrFromType(PyArray_VOID), \n\t sizeof(PyArray_Descr));\n\ttypenum = PyArray_USERDEF + PyArray_NUMUSERTYPES;\n\tdescr->type_num = typenum;\n\tdescr->typeobj = 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 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 frees the copy of the Descr_table already there.\n places a pointer to the new one into the slot.\n*/\nstatic int\nPyArray_RegisterDescrForType(int typenum, PyArray_Descr *descr)\n{\n\tPyArray_Descr *old;\n\tint i;\n\n\tif (!PyTypeNum_ISUSERDEF(typenum)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"data type not registered\");\n\t\treturn -1;\n\t}\n\told = userdescrs[typenum-PyArray_USERDEF];\n\tdescr->typeobj = old->typeobj;\n\tdescr->type_num = typenum;\n\n#define _NULL_CHECK(member) \\\n\tif (descr->member == NULL) descr->member = old->member\n\n\tfor (i=0; imember == 0) descr->member = old->member\n\n\t_ZERO_CHECK(kind);\n\t_ZERO_CHECK(type);\n\t_ZERO_CHECK(elsize);\n\t_ZERO_CHECK(alignment);\n#undef _ZERO_CHECK\n\n\tfree(old);\n\tuserdescrs[typenum-PyArray_USERDEF] = descr;\n\treturn 0;\n}\n\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 n3 = strlen((const char *)sep);\n if (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 \"\\\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->itemsize,\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->itemsize,\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 = strlen((const char *)format);\n while(it->index < it->size) {\n obj = self->descr->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\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->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\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 if (PyArray_TYPE(self) == PyArray_OBJECT) {\n PyErr_SetString(PyExc_ValueError, \"a string for the data\"\\\n\t\t\t\t\"in an object array is not appropriate\");\n return NULL;\n }\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->itemsize;\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 != NULL)) {\n\t\t/* Free internal references if an Object array */\n\t\tPyArray_XDECREF(self);\n\n PyDataMem_FREE(self->data);\n }\n\t\n if (self->dimensions != NULL) {\n PyDimMem_FREE(self->dimensions); \n\t}\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\n\nstatic PyObject *\narray_item(PyArrayObject *self, int i) \n{\n char *item;\n PyArrayObject *r;\n\n\n\tif(self->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n if ((item = index2ptr(self, i)) == NULL) return NULL;\n\n\tr = (PyArrayObject *)PyArray_New(self->ob_type, \n\t\t\t\t\t self->nd-1, self->dimensions+1, \n\t\t\t\t\t self->descr->type_num, \n\t\t\t\t\t self->strides+1, item, \n\t\t\t\t\t self->itemsize, self->flags,\n\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_item(self, i));\n}\n\n\nstatic int \narray_ass_item(PyArrayObject *self, int 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\n if (i < 0) i = i+self->dimensions[0];\n\n if (self->nd > 1) {\n if((tmp = (PyArrayObject *)array_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->setitem(v, item, self) == -1) return -1;\n return 0;\n}\n\n/* -------------------------------------------------------------- */\nstatic int\nslice_coerce_index(PyObject *o, int *v)\n{\n\t*v = PyArray_PyIntAsInt(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, int length,\n int *start, int *stop, int *step,\n intp *slicelength)\n{\n\tint 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 int\nparse_subindex(PyObject *op, int *step_size, intp *n_steps, int max)\n{\n\tint 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\tint 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_PyIntAsInt(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, start, offset, n_add, n_pseudo;\n int step_size;\n\tintp n_steps;\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, *tup;\n\tint n1, n2, n3, val;\n\tint i;\n\n\ttup = PyTuple_New(mit->nd);\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\tPyTuple_SET_ITEM(tup, i++, PyInt_FromLong((long)val++));\n\tval = 0;\n\twhile(val < n1)\n\t\tPyTuple_SET_ITEM(tup, i++, PyInt_FromLong((long)val++));\n\tval = n1+n2;\n\twhile(val < n3)\n\t\tPyTuple_SET_ITEM(tup, i++, PyInt_FromLong((long)val++));\n\n\tnew = PyArray_Transpose(*ret, tup);\n\tPy_DECREF(tup);\n\tPy_DECREF(*ret);\n\t*ret = (PyArrayObject *)new;\n}\n\n\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\tret = (PyArrayObject *)\\\n\t\tPyArray_New(temp->ob_type, mit->nd, mit->dimensions, \n\t\t\t temp->descr->type_num, NULL, NULL, \n\t\t\t temp->itemsize, \n\t\t\t PyArray_ISFORTRAN(temp),\n\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\treturn NULL;\n\tindex = it->size;\n\tswap = ((temp->flags & NOTSWAPPED) != (ret->flags & NOTSWAPPED));\n copyswap = ret->descr->copyswap;\n\tPyArray_MapIterReset(mit);\n\twhile (index--) {\n copyswap(it->dataptr, mit->dataptr, swap, ret->itemsize);\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\tPyArray_Typecode typecode = {0, 0, 0};\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Unbound Map Iterator */\n\tif (mit->ait == NULL) return -1;\n\n\ttypecode.type_num = mit->ait->ao->descr->type_num;\n\ttypecode.itemsize = mit->ait->ao->itemsize;\n\n\tarr = PyArray_FromAny(op, &typecode, \n\t\t\t 0, 0, FORCECAST);\n\tif (arr == NULL) return -1;\n\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, (PyArrayObject **)&arr);\n\t\t}\n\t}\n\t\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) \n\t\treturn -1;\n\n\tindex = mit->size;\n\tswap = ((mit->ait->ao->flags & NOTSWAPPED) != \\\n\t\t(PyArray_FLAGS(arr) & NOTSWAPPED));\n\n copyswap = PyArray_DESCR(arr)->copyswap;\n\tPyArray_MapIterReset(mit);\n /* Need to decref OBJECT arrays */\n if (PyTypeNum_ISOBJECT(typecode.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 copyswap(mit->dataptr, NULL, swap, \n sizeof(PyObject *));\n PyArray_MapIterNext(mit);\n PyArray_ITER_NEXT(it);\n if (it->index == it->size)\n PyArray_ITER_RESET(it);\n }\n return 0;\n }\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\treturn 0;\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 0-dimensional arrays */\n\nstatic PyObject *\narray_subscript(PyArrayObject *self, PyObject *op) \n{\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n\tintp offset;\n int nd, i;\n PyArrayObject *other;\n\tPyArrayMapIterObject *mit;\n\n if (PyArray_IsScalar(op, Integer) || PyInt_Check(op) || \\\n PyLong_Check(op)) {\n intp value;\n value = PyArray_PyIntAsIntp(op);\n if (PyErr_Occurred())\n PyErr_Clear();\n else if (value >= 0) {\n if (value <= MAX_INT)\n return array_item(self, (int) value);\n }\n else if (value < 0) {\n if (value >= -MAX_INT) {\n if (self->nd > 0) value += self->dimensions[0];\n return array_item(self, (int) value);\n }\n }\n }\n\n\tif (PyArrayMapIter_Check(op)) {\n\t\tmit = (PyArrayMapIterObject *)op;\n\t\t/* bind to current array */\n\t\tPyArray_MapIterBind(mit, self);\n\t\t\n\t\t/* If the mapiterator was created with standard indexing\n\t\t behavior, fall through to view-based code */\n\t\tif (!mit->view) return PyArray_GetMap(mit);\n\t\top = mit->indexobj;\n\t}\n\telse { /* wrap arguments into a mapiter object */\n\t\tmit = (PyArrayMapIterObject *)PyArray_MapIterNew(op);\n\t\tif (mit == NULL) return NULL;\n\t\tif (!mit->view) { /* fancy indexing */\n\t\t\tPyArray_MapIterBind(mit, self);\n\t\t\tother = (PyArrayObject *)PyArray_GetMap(mit);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn (PyObject *)other;\n\t\t}\n\t\tPy_DECREF(mit);\n\t}\n\n\ti = PyArray_PyIntAsInt(op);\n\tif (!error_converting(i)) {\n\t\tif (i < 0 && self->nd > 0) i = i+self->dimensions[0];\n\t\treturn array_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\tif ((other = (PyArrayObject *)\t\t\t\t\t\\\n\t PyArray_New(self->ob_type, nd, dimensions, self->descr->type_num,\n\t\t\t strides, self->data+offset, \n\t\t\t self->itemsize, self->flags,\n\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 \narray_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op) \n{\n int ret, 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\n\tif (PyArrayMapIter_Check(index)) {\n\t\tmit = (PyArrayMapIterObject *)index;\n\t\t/* bind behavior to current array */\n\t\tPyArray_MapIterBind(mit, self);\n\t\t\t\n\t\t/* fall through if standard view-based map iterator */\n\t\tif (!mit->view) return PyArray_SetMap(mit, op);\n\t\tindex = mit->indexobj;\n\t}\n\telse {\n\t\tmit = (PyArrayMapIterObject *)PyArray_MapIterNew(index);\n\t\tif (mit == NULL) return -1;\n\t\tif (!mit->view) {\n\t\t\tPyArray_MapIterBind(mit, self);\n\t\t\tret = PyArray_SetMap(mit, op);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn ret;\n\t\t}\n\t\tPy_DECREF((PyObject*)mit);\n\t}\n\n\ti = PyArray_PyIntAsInt(index);\n\tif (!error_converting(i)) {\n\t\treturn array_ass_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 ret = PyArray_CopyObject(tmp, op);\n Py_DECREF(tmp);\n\t\n return ret;\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 \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\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}\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}\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 PyObject *args, *ret;\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n args = Py_BuildValue(\"(OO)\", m1, m2);\n ret = PyObject_Call(op, args, NULL);\n Py_DECREF(args);\n return ret;\n}\n\nstatic PyObject *\nPyArray_GenericUnaryFunction(PyArrayObject *m1, PyObject *op) \n{\n PyObject *args, *ret;\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n args = Py_BuildValue(\"(O)\", m1);\n ret = PyObject_Call(op, args, NULL);\n Py_DECREF(args);\n return ret;\n}\n\nstatic PyObject *\nPyArray_GenericInplaceBinaryFunction(PyArrayObject *m1, \n\t\t\t\t PyObject *m2, PyObject *op) \n{\n PyObject *args, *ret;\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n args = Py_BuildValue(\"(OOO)\", m1, m2, m1);\n ret = PyObject_Call(op, args, NULL);\n Py_DECREF(args);\n return ret;\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_all_nonzero(PyArrayObject *mp) \n{\n\tintp index;\n\tPyArrayIterObject *it;\n\tBool anyTRUE = 0;\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->nonzero(it->dataptr, mp)) {\n\t\t\tanyTRUE = 1;\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 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->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->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->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->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->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_all_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 r = (PyArrayObject *)\\\n\t\tPyArray_New(self->ob_type, self->nd, self->dimensions, \n\t\t\t self->descr->type_num, self->strides, data,\n\t\t\t self->itemsize, 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 any(self == el) */\n\n return PyObject_RichCompareBool((PyObject *)self, el, Py_EQ);\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 *)realloc(*string, *max_n); }\n\t\n if (nd == 0) {\n\t\t\n if ((op = descr->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\tfree(string); return NULL; \n\t}\n\t\n\tif (PyArray_ISFLEXIBLE(self)) {\n\t\tchar buf[100];\n\t\tsnprintf(buf, sizeof(buf), \"%d\", self->itemsize);\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 free(string);\n return ret;\n}\n\nstatic PyObject *PyArray_StrFunction=NULL;\nstatic PyObject *PyArray_ReprFunction=NULL;\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\n\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) \n{\n PyObject *array_other, *result;\n\n switch (cmp_op) \n {\n case Py_LT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less);\n case Py_LE:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less_equal);\n case Py_EQ:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then return the integer\n\t\t\t object 0. This fixes code that used to\n\t\t\t allow equality comparisons between arrays\n\t\t\t and other objects which would give a result\n\t\t\t of 0\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n result = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.equal);\n /* If the comparison results in NULL, then the \n\t\t\t two array objects can not be compared together so \n\t\t\t return zero \n */\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n return result;\n case Py_NE:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then objects cannot be \n\t\t\t compared and cannot be equal, therefore, \n\t\t\t return True;\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n result = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.not_equal);\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n return result;\n case Py_GT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.greater);\n case Py_GE:\n return PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t other, \n\t\t\t\t\t \t n_ops.greater_equal);\n }\n return NULL;\n}\n\nstatic PyObject *\n_check_axis(PyArrayObject *arr, int *axis, int flags)\n{\n\tPyObject *temp;\n\tint n = arr->nd;\n\n\tif ((*axis >= MAX_DIMS) || (n==0)) {\n\t\ttemp = PyArray_Ravel(arr,0);\n\t\t*axis = 0;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_FromAny((PyObject *)arr, NULL, \n\t\t\t\t\t 0, 0, flags);\n\t\t\tif (temp == NULL) return NULL;\n\t\t}\n\t\telse {\n\t\t\tPy_INCREF(arr);\n\t\t\ttemp = (PyObject *)arr;\n\t\t}\n\t}\n\tif (*axis < 0) *axis += n;\n\tif ((*axis < 0) || (*axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", *axis);\n\t\tPy_DECREF(temp);\n\t\treturn NULL;\n\t}\n\treturn temp;\n}\n\n#include \"arraymethods.c\"\n\n/* Lifted from numarray */\nstatic PyObject *\nPyArray_IntTupleFromIntp(int len, intp *vals)\n{\n\tint i;\n PyObject *intTuple = PyTuple_New(len);\n if (!intTuple) goto fail;\n for(i=0; ind == 0) return 1;\n\tsd = ap->itemsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\n\t}\n\treturn 1;\n}\n\n\nstatic int \n_IsFortranContiguous(PyArrayObject *ap) \n{\n\tint sd;\n\tint i;\n\t\n\tif (ap->nd == 0) return 1;\n\tsd = ap->itemsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i=0; i< ap->nd; ++i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\n\t}\n\treturn 1;\n}\n\nstatic int\n_IsAligned(PyArrayObject *ap) \n{\n\tint i, alignment, aligned=1;\n\tintp ptr;\n\tint type = ap->descr->type_num;\n\n\tif ((type == PyArray_STRING) || (type == PyArray_VOID))\n\t\treturn 1;\n\n\talignment = ap->descr->alignment;\n\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\tPyBufferProcs *pb;\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\tpb = base->ob_type->tp_as_buffer;\n\tif (pb == NULL || pb->bf_getwritebuffer == NULL)\n\t\treturn FALSE;\n\t\n\treturn TRUE;\n}\n\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\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not \n walk outside of the memory implied by either numbytes or\n a single segment array of the provided dimensions and element size if\n numbytes is 0 */\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, \n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\t\n\tif (numbytes == 0) \n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\t\n\tfor (i=0; i numbytes) {\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\treturn TRUE;\n\t\n}\n\n\n/* This is the main array creation routine. */\n\n/* Flags argument has multiple related meanings \n depending on data and strides: \n\n If data is given, then flags is flags associated with data. \n If strides is not given, then a contiguous strides array will be created\n and the CONTIGUOUS bit will be set. If the flags argument \n has the FORTRAN bit set, then a FORTRAN-style strides array will be\n created (and of course the FORTRAN flag bit will be set). \n\n If data is not given but created here, then flags will be DEFAULT_FLAGS\n and a non-zero flags argument can be used to indicate a FORTRAN style\n array is desired. \n*/\n\nstatic intp\n_array_fill_strides(intp *strides, intp *dims, int nd, intp itemsize, \n\t\t int inflag, int *objflags) \n{\n\tint i;\n\t/* Only make Fortran strides if not contiguous as well */\n\tif ((inflag & FORTRAN) && !(inflag & CONTIGUOUS)) {\n\t\tfor (i=0; i 1) *objflags &= ~CONTIGUOUS;\n\t\telse *objflags |= CONTIGUOUS;\n\t}\n\telse {\n\t\tfor (i=nd-1;i>=0;i--) {\n\t\t\tstrides[i] = itemsize;\n\t\t\titemsize *= dims[i] ? dims[i] : 1;\n\t\t}\n\t\t*objflags |= CONTIGUOUS;\n\t\tif (nd > 1) *objflags &= ~FORTRAN;\n\t\telse *objflags |= FORTRAN;\n\t}\n\treturn itemsize;\n}\n\n\t\nstatic PyObject *\nPyArray_New(PyTypeObject *subtype, int nd, intp *dims, int type_num,\n intp *strides, char *data, int itemsize, int flags,\n\t PyObject *obj)\n{\n\tPyArrayObject *self;\n\tPyArray_Descr *descr;\n\tregister int i;\n\tintp sd, temp=-1;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\tif (descr == NULL) return NULL;\n\n\tif (nd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"number of dimensions must be >=0\");\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 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\treturn NULL;\n\t\t}\n\t}\n\t\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) return NULL;\t\n\tself->descr = descr;\n\tself->dimensions = 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\n\tif (PyTypeNum_ISFLEXIBLE(type_num)) {\n\t\tif (itemsize < 1) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"type must provide an itemsize\");\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn NULL;\n\t\t}\n\t\tself->itemsize = itemsize;\n\t\t/* Guarantee that these kind of arrays are never byteswapped\n\t\t unknowingly. \n\t\t*/\n\t\tif (type_num != PyArray_UNICODE)\n\t\t\tself->flags |= NOTSWAPPED;\n\t}\n\telse self->itemsize = descr->elsize; \n\t\t\n\tsd = self->itemsize;\n\t\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn PyErr_NoMemory();\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\tPyDimMem_FREE(self->dimensions);\n\t\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\t\treturn NULL;\n\t\t\t}\t\t\t\t\n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t}\n \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 (a.data) doesn't work\n\t\t as it should. */\n\n\t\tif (sd==0) sd = sizeof(intp);\n\n\t\tif ((data = PyDataMem_NEW(sd))==NULL) {\n\t\t\tPyDimMem_FREE(self->dimensions);\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn PyErr_NoMemory();\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\n\t\t/* It is bad to have unitialized OBJECT pointers */\n\t\t/* We shouldn't need to check for the OBJECT Letter\n\t\t but perhaps it's best. */\n\t\tif (type_num == PyArray_OBJECT || \\\n\t\t type_num == PyArray_OBJECTLTR) {\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\tself->nd = nd;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\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;\n\t\tif (temp==-1) { /* 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\tres = PyObject_CallMethod((PyObject *)self, \n\t\t\t\t\t \"__array_finalize__\",\n\t\t\t\t\t \"O\", obj);\n\t\tif (res == NULL) {\n\t\t\tPyDimMem_FREE(self->dimensions);\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn NULL;\n\t\t}\n\t\telse Py_DECREF(res);\n\t}\n\n\treturn (PyObject *)self;\n}\n\n\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\n newsize = PyArray_MultiplyList(new_dimensions, new_nd);\n\n if (newsize == 0) {\n PyErr_SetString(PyExc_ValueError, \n \"newsize is zero; cannot delete an array \"\\\n \"in this way\");\n return NULL;\n }\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 = (((PyObject *)self)->ob_refcnt);\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\n\t\t/* Reallocate space if needed */\n\t\tnew_data = PyDataMem_RENEW(self->data, \n\t\t\t\t\t newsize*(self->itemsize));\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->itemsize;\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->itemsize;\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 */\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; idataptr, fromptr, itemsize);\n\t\t\tPyArray_ITER_NEXT(iter);\n\t\t}\n\n\t\tPy_DECREF(iter);\n\t\tPy_DECREF(behaved);\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\", \"strides\", \n \"swap\", \"fortran\", NULL};\n\tint itemsize = 0;\n\tPyArray_Typecode typecode = {PyArray_NOTYPE, 0, 0};\n\tint type_num = PyArray_NOTYPE;\n PyArray_Dims dims = {NULL, 0};\n PyArray_Dims strides = {NULL, 0};\n PyArray_Chunk buffer;\n\tint fortran = 0;\n int swapped = 0;\n\tPyArrayObject *ret;\n\n\tbuffer.ptr = NULL; \n /* Usually called with shape and type\n but can also be called with buffer, strides, and swapped info\n */\n\n\t/* For now, let's just use this to create an empty, contiguous \n\t array of a specific type and shape. \n\t*/\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&O&ii\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &dims, \n PyArray_TypecodeConverter,\n\t\t\t\t\t &typecode, \n PyArray_BufferConverter,\n &buffer,\n &PyArray_IntpConverter, \n &strides,\n &swapped, &fortran)) \n\t\treturn NULL;\n\t\n if (typecode.type_num ==PyArray_NOTYPE) {\n\t\ttypecode.type_num = PyArray_DOUBLE;\n\t\ttypecode.itemsize = sizeof(double);\n\t}\n\ttype_num = typecode.type_num;\n\titemsize = typecode.itemsize;\n\n\n if (dims.ptr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"need to give a \"\\\n \"valid shape as the first argument\");\n goto fail;\n }\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)PyArray_New(subtype, (int)dims.len, \n dims.ptr, type_num,\n NULL, NULL, itemsize, \n fortran, NULL);\n \n if (ret == NULL) goto fail;\n if (type_num == PyArray_OBJECT) { /* place Py_None */\n PyArray_FillObjectArray(ret, Py_None);\n }\n }\n else { /* buffer given -- use it */\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = buffer.len / itemsize;\n }\n else if (buffer.len < itemsize* \\\n PyArray_MultiplyList(dims.ptr, dims.len)) {\n PyErr_SetString(PyExc_TypeError, \n \"buffer is too small for \" \\\n \"requested array\");\n goto fail;\n }\n if (strides.ptr != NULL) {\n\t\t\tif (strides.len != dims.len) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides, if given, must be \"\\\n\t\t\t\t\t\t\"the same length as shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CheckStrides(itemsize, strides.len, \n\t\t\t\t\t\t buffer.len,\n\t\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides is incompatible \"\\\n\t\t\t\t\t\t\"with shape of requested\"\\\n\t\t\t\t\t\t\"array and size of buffer\");\n\t\t\t\tgoto fail;\n\t\t\t}\n }\n if (type_num == PyArray_OBJECT) {\n PyErr_SetString(PyExc_TypeError, \"cannot construct \"\\\n \"an object array from buffer data\");\n goto fail;\n }\n /* get writeable and aligned */\n if (fortran) buffer.flags |= FORTRAN;\n if (!(swapped)) buffer.flags |= NOTSWAPPED;\n ret = (PyArrayObject *)PyArray_New(subtype, dims.len, \n dims.ptr, type_num,\n strides.ptr,\n (char *)buffer.ptr, \n itemsize, \n buffer.flags, NULL); \n if (ret == 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 PyArray_Return(ret);\n \n fail:\n if (dims.ptr) PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return NULL;\n}\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 static PyObject *module=NULL;\n\n if (module==NULL) {\n module = PyImport_ImportModule(\"scipy.base._internal\");\n if (module == NULL) return NULL;\n }\n return PyObject_CallMethod(module, \"flagsobj\", \"Oii\", \n self, self->flags, 0);\n}\n\n/*\nstatic int\narray_flags_set(PyArrayObject *self, PyObject *obj) \n{\n\tint flagback = self->flags;\n\n if (PyDict_Check(obj)) {\n PyObject *new;\n\t\tnew = PyDict_GetItemString(obj, \"ALIGNED\");\n\t\tif (new) {\n\t\t\tif (PyObject_Not(new)) self->flags &= ~ALIGNED;\n\t\t\telse if (_IsAligned(self)) self->flags |= ALIGNED;\n\t\t\telse {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"cannot set aligned flag of \" \\\n\t\t\t\t\t\t\"mis-aligned array to True\");\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t}\n new = PyDict_GetItemString(obj, \"UPDATEIFCOPY\");\n if (new) {\n if (PyObject_Not(new)) {\n self->flags &= ~UPDATEIFCOPY;\n Py_DECREF(self->base);\n self->base = NULL;\n }\n else {\n\t\t\t\tself->flags = flagback;\n PyErr_SetString(PyExc_ValueError, \n \"cannot set UPDATEIFCOPY\" \\\n \"flag to True\");\n return -1;\n }\n }\n new = PyDict_GetItemString(obj, \"WRITEABLE\");\n if (new) {\n\t\t\tif (PyObject_IsTrue(new)) {\n\t\t\t\tif (_IsWriteable(self)) {\n\t\t\t\t\tself->flags |= WRITEABLE;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tself->flags = flagback;\n\t\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\t\"cannot set \"\t\\\n\t\t\t\t\t\t\t\"WRITEABLE \"\t\\\n\t\t\t\t\t\t\t\"flag to True of \"\\\n\t\t\t\t\t\t\t\"this array \");\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n else\n self->flags &= ~WRITEABLE;\n }\n new = PyDict_GetItemString(obj, \"NOTSWAPPED\");\n if (new) {\n if (PyObject_IsTrue(new))\n self->flags |= NOTSWAPPED;\n else {\n self->flags &= ~NOTSWAPPED;\n\t\t\t}\n\t\t}\n return 0;\n }\n PyErr_SetString(PyExc_ValueError, \n \"object must be a dictionary\");\n return -1;\n}\n*/\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\tif (!PyTuple_Check(val)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"shape must be a tuple\");\n\t\treturn -1;\n\t}\n\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\n\t\n\tif (self->nd > 0) { /* Free old dimensions and strides */\n\t\tPyDimMem_FREE(self->dimensions);\n\t}\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;\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\treturn -1;\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->itemsize;\n\t\n\tif (!PyArray_CheckStrides(self->itemsize, self->nd, numbytes, \n\t\t\t\t self->dimensions, newstrides.ptr)) {\n\t\tPyErr_SetString(PyExc_ValueError, \"strides is not \"\\\n\t\t\t\t\"compatible with available memory\");\n\t\treturn -1;\n\t}\n\tmemcpy(self->strides, newstrides.ptr, sizeof(intp)*newstrides.len);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\treturn 0;\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->itemsize);\n}\n\nstatic PyObject *\narray_size_get(PyArrayObject *self)\n{\n\tlonglong size=PyArray_SIZE(self);\n\tif (size > MAX_INT || size < MIN_INT)\n\t\treturn PyLong_FromLongLong((longlong) size);\n\telse \n\t\treturn PyInt_FromLong((long) size);\n}\n\n\nstatic PyObject *\narray_typechar_get(PyArrayObject *self)\n{\n\tif PyArray_ISFLEXIBLE(self) \n\t\treturn PyString_FromFormat(\"%c%d\", (self->descr->type),\n\t\t\t\t\t self->itemsize);\n\telse \n\t\treturn PyString_FromStringAndSize(&(self->descr->type), 1);\n}\n\nstatic PyObject *\narray_typestr_get(PyArrayObject *self)\n{\n\tstatic char endians[] = \"<>\";\n\tchar endian;\n\tint which;\n\tunsigned long val = 1;\n\tchar *s;\n\tchar basic_=self->descr->kind;\n\n\ts = (char *)&val; /* s[0] == 0 implies big-endian */\n\twhich = (PyArray_ISNOTSWAPPED(self) ? 0 : 1);\n\tif (s[0] == 0) which = 1 - which;\n\tendian = endians[which]; \n\t\n\tif ((basic_==PyArray_VOIDLTR) || (basic_==PyArray_STRINGLTR) || \\\n\t (basic_==PyArray_OBJECTLTR) || (self->itemsize == 1))\n\t\treturn PyString_FromFormat(\"|%c%d\", basic_, self->itemsize);\n\telse\n\t\treturn PyString_FromFormat(\"%c%c%d\", endian, basic_,\n\t\t\t\t\t self->itemsize);\n}\n\nstatic PyObject *\narray_descr_get(PyArrayObject *self)\n{\n\tPyObject *res;\n\tPyObject *dobj;\n\n\t/* hand this off to the typeobject */\n\t/* or give default */\n\tif (PyArray_ISUSERDEF(self)) {\n\t\tres = PyObject_GetAttrString((PyObject *)self->descr->typeobj, \n\t\t\t\t\t \"__array_descr__\");\n\t\tif (res) return res;\n\t\tPyErr_Clear();\n\t}\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\n\nstatic PyObject *\narray_type_get(PyArrayObject *self)\n{\n\treturn PyArray_TypeObjectFromType(self->descr->type_num);\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*/\n\nstatic int\narray_type_set(PyArrayObject *self, PyObject *arg)\n{\n PyArray_Typecode newtype = {PyArray_NOTYPE, 0, 0};\n intp newdim;\n int index;\n char *msg = \"new type not compatible with array.\";\n\n if ((PyArray_TypecodeConverter(arg, &newtype) < 0) ||\n newtype.type_num == PyArray_NOTYPE) {\n PyErr_SetString(PyExc_TypeError, \"invalid type for array\");\n return -1;\n }\n if (!(PyArray_ISONESEGMENT(self) ||\t\t\\\n\t (newtype.itemsize != self->itemsize))) {\n PyErr_SetString(PyExc_ValueError, msg);\n return -1; \n }\n\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\n if (newtype.itemsize < self->itemsize) {\n /* if it is compatible increase the size of the dimension\n at end (or at the front for FORTRAN)\n */\n if (self->itemsize % newtype.itemsize != 0) {\n PyErr_SetString(PyExc_ValueError, msg);\n return -1;\n }\n newdim = self->itemsize / newtype.itemsize;\n\t\tself->dimensions[index] *= newdim;\n self->strides[index] = newtype.itemsize;\n\t}\n \n else if (newtype.itemsize > self->itemsize) {\n \n /* Determine if last (or first if FORTRAN) dimension\n is compatible */\n\n\t\tnewdim = self->dimensions[index] * self->itemsize;\n if ((newdim % newtype.itemsize) != 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, msg);\n return -1;\n }\n\t\t\n self->dimensions[index] = newdim / newtype.itemsize;\n self->strides[index] = newtype.itemsize;\n\t\t\n }\n\t\n \n /* fall through -- adjust type*/\n\n self->descr = PyArray_DescrFromType(newtype.type_num);\n self->itemsize = newtype.itemsize;\n PyArray_UpdateFlags(self, ALIGNED);\n return 0;\n\n}\n\n\n\nstatic PyObject *\narray_base_get(PyArrayObject *self)\n{\n\tif (self->base == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\telse {\n\t\tPy_INCREF(self->base);\n\t\treturn self->base;\n\t}\n}\n\n\nstatic PyObject *\narray_real_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *)ret;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n}\n\n\nstatic int\narray_real_set(PyArrayObject *self, PyObject *val)\n{\n\tPyArrayObject *ret;\n\tPyArrayObject *new;\n\tint rint;\n\n\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0);\n\tif (new == NULL) return -1;\n\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) 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\treturn rint;\n}\n\nstatic PyObject *\narray_imag_get(PyArrayObject *self)\n{\t\n\tPyArrayObject *ret;\n\tint itemsize;\n\tint typenum;\n PyArray_Typecode type;\n\t\n\ttype.type_num = self->descr->type_num;\n\ttype.itemsize = self->itemsize;\n\ttype.fortran = PyArray_ISFORTRAN(self);\n\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\titemsize = self->itemsize >> 1;\n\t\ttypenum = self->descr->type_num - PyArray_NUM_FLOATTYPE;\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 typenum,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data + itemsize,\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\tret = (PyArrayObject *)PyArray_Zeros(self->nd, \n\t\t\t\t\t\t self->dimensions, &type);\n\t\tret->flags &= ~WRITEABLE;\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic int\narray_imag_set(PyArrayObject *self, PyObject *val)\n{\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyArrayObject *ret;\n\t\tPyArrayObject *new;\n\t\tint rint;\n\n\t\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0); \n\t\tif (new == NULL) return -1;\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides+ \\\n\t\t\t\t\t\t (self->itemsize >> 1) ,\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) {\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_Typecode typecode;\n int swap;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode.type_num = self->descr->type_num;\n\ttypecode.itemsize = self->itemsize;\n\ttypecode.fortran = PyArray_ISFORTRAN(self);\n\t\n\tarr = PyArray_FromAny(val, &typecode, \n\t\t\t 0, 0, FORCECAST);\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->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 copyswap(selfit->dataptr, NULL, swap, \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->itemsize);\n copyswap(selfit->dataptr, NULL, swap, self->itemsize);\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\t{\"base\",\n\t (getter)array_base_get,\n\t NULL,\n\t \"base object\"},\n {\"dtype\", \n\t (getter)array_type_get, \n\t (setter)array_type_set,\n\t \"get array type class\"},\n\t{\"dtypechar\",\n\t (getter)array_typechar_get,\n\t NULL,\n\t \"get array type character code\"},\n\t{\"dtypestr\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"get array type string\"},\n {\"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_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\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\n\nstatic char Arraytype__doc__[] = \n \"A array object represents a multidimensional, homogeneous array\\n\"\n\t\" of basic values. Arrays are sequence, mapping and numeric\\n\"\n\t\" objects. More information is available in the scipy module and\\n\"\n\t\" by looking at the methods and attributes of an array.\";\n\nstatic PyTypeObject PyBigArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"scipy.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 \n offsetof(PyArrayObject, weakreflist), /*tp_weaklistoffset */\n\n /* Iterator support (use standard) */\n\n (getiterfunc)0, \t\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 0,\t /* tp_alloc */ \n (newfunc)array_new,\t\t /* tp_new */\n 0,\t \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 \"scipy.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) \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 if (PySequence_Length(s) == 0) \n\t\treturn 1;\n\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);\n\t\tif(d >= 0) d++;\n\t}\n Py_DECREF(e);\n return d;\n}\n\nstatic int\ndiscover_itemsize(PyObject *s, int nd, int *itemsize) \n{\n\tint n, r, i;\n\tPyObject *e;\n\t\n\tn = PyObject_Length(s);\n\n\tif ((nd == 0) || PyString_Check(s) ||\t\t\\\n\t PyUnicode_Check(s) || PyBuffer_Check(s)) {\n\t\tif PyUnicode_Check(s) \n\t\t\t*itemsize = MAX(*itemsize, sizeof(Py_UNICODE)*n);\n\t\telse\n\t\t\t*itemsize = MAX(*itemsize, n);\n\t\treturn 0;\n\t}\n\tfor (i=0; i n_lower) n_lower = d[1];\n }\n d[1] = n_lower;\n\t\n return 0;\n}\n\nstatic void\n_array_small_type(int chktype, int mintype, int chksize, int minsize, \n\t\t PyArray_Typecode *outtype)\n{\n\touttype->type_num = MAX(chktype, mintype);\n\tif (PyTypeNum_ISFLEXIBLE(outtype->type_num) &&\t\\\n\t PyTypeNum_ISFLEXIBLE(mintype)) {\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 == PyArray_STRING) {\n\t\t\touttype->itemsize = MAX(chksize, 2*minsize);\n\t\t}\n\t\telse {\n\t\t\touttype->itemsize = MAX(chksize, minsize);\n\t\t}\n\t}\n\telse {\n\t\touttype->itemsize = chksize;\n\t}\n\treturn;\t\n}\n\nstatic void\n_array_find_type(PyObject *op, PyArray_Typecode *minitype, \n\t\t PyArray_Typecode *outtype, int max)\n{\n int l;\n PyObject *ip;\n\tint chktype=0;\n\tint chksize=0;\n\tint mintype, minsize;\n\n\tif (minitype == NULL) {\n\t\tmintype = PyArray_BOOL;\n\t\tminsize = sizeof(Bool);\n\t}\n\telse {\n\t\tmintype = minitype->type_num;\n\t\tminsize = minitype->itemsize;\n\t}\n\n \n if (max < 0 || mintype == -1) goto deflt;\n\t\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_TYPE(op);\n\t\tchksize = PyArray_ITEMSIZE(op);\n\t\tgoto finish;\n\t}\n\t\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tPyArray_TypecodeFromScalar(op, outtype);\n\t\tchktype = outtype->type_num;\n\t\tchksize = outtype->itemsize;\n\t\tgoto finish;\n\t}\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_TYPE(ip);\n\t\t\tchksize = PyArray_ITEMSIZE(ip);\n\t\t\tgoto finish;\n\t\t}\n } \n\t\n\tif (PyObject_HasAttrString(op, \"__array_typestr__\")) {\n\t\tint swap=0, res;\n\t\tip = PyObject_GetAttrString(op, \"__array_typestr__\");\n\t\tif (ip && PyString_Check(ip)) {\n\t\t\tres = _array_typecode_fromstr(PyString_AS_STRING(ip), \n\t\t\t\t\t\t &swap, outtype); \n\t\t\tif (res >= 0) {\n\t\t\t\tPy_DECREF(ip);\n\t\t\t\tchktype = outtype->type_num;\n\t\t\t\tchksize = outtype->itemsize;\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t}\n\t\tPy_XDECREF(ip);\n\t}\n\n if (PyString_Check(op)) {\n\t\tchktype = PyArray_STRING;\n\t\tchksize = PyString_GET_SIZE(op);\n\t\tgoto finish;\n }\n\n\tif (PyUnicode_Check(op)) {\n\t\tchktype = PyArray_UNICODE;\n\t\tchksize = PyUnicode_GET_DATA_SIZE(op);\n\t\tgoto finish;\n\t}\n\n\tif (PyBuffer_Check(op)) {\n\t\tchktype = PyArray_VOID;\n\t\tchksize = op->ob_type->tp_as_sequence->sq_length(op);\n\t\tPyErr_Clear();\n\t\tgoto finish;\n\t}\n\n\tif (PyInstance_Check(op)) goto deflt;\n\t\n if (PySequence_Check(op)) {\n\t\tPyArray_Typecode newtype;\n\t\tnewtype.type_num = mintype;\n\t\tnewtype.itemsize = minsize;\n\t\tnewtype.fortran = 0;\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 && mintype == 0) {\n\t\t\tnewtype.type_num = PyArray_INTP;\n\t\t\tnewtype.itemsize = sizeof(intp);\n\t\t}\n while (--l >= 0) {\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\t_array_find_type(ip, &newtype, outtype, max-1);\n\t\t\t_array_small_type(outtype->type_num,\n\t\t\t\t\t newtype.type_num, \n\t\t\t\t\t outtype->itemsize,\n\t\t\t\t\t newtype.itemsize,\n\t\t\t\t\t &newtype);\n Py_DECREF(ip);\n }\n\t\tchktype = newtype.type_num;\n\t\tchksize = newtype.itemsize;\n\t\tgoto finish;\n }\n\t\n\tif (PyBool_Check(op)) {\n\t\tchktype = PyArray_BOOL;\n\t\tchksize = sizeof(Bool);\n\t\tgoto finish;\t\t\n\t}\n else if (PyInt_Check(op)) {\n\t\tchktype = PyArray_LONG;\n\t\tchksize = sizeof(long);\n\t\tgoto finish;\n } else if (PyFloat_Check(op)) {\n\t\tchktype = PyArray_DOUBLE;\n\t\tchksize = sizeof(double);\n\t\tgoto finish;\n\t} else if (PyComplex_Check(op)) {\n\t\tchktype = PyArray_CDOUBLE;\n\t\tchksize = sizeof(cdouble);\n\t\tgoto finish;\n\t}\n\n deflt:\n\tchktype = PyArray_OBJECT;\n\tchksize = sizeof(void *);\n\n finish:\n\t_array_small_type(chktype, mintype, chksize, minsize, \n\t\t\t outtype);\n\treturn;\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\" */ \nstatic PyObject *\nArray_FromScalar(PyObject *op, PyArray_Typecode *typecode) \n{\n PyArrayObject *ret;\n\tint itemsize = 0;\n\tint type = typecode->type_num;\n\n\tif PyTypeNum_ISFLEXIBLE(type) {\n\t\titemsize = PyObject_Length(op);\n\t}\n\n\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, 0, NULL, type,\n\t\t\t\t\t NULL, NULL, itemsize, 0, NULL);\n\n\tif (ret == NULL) return NULL;\n\n ret->descr->setitem(op, ret->data, ret);\n\t\n if (PyErr_Occurred()) {\n array_dealloc(ret);\n return NULL;\n } else {\n return (PyObject *)ret;\n }\n}\n\n\nstatic PyObject *\nArray_FromSequence(PyObject *s, PyArray_Typecode *typecode, int min_depth, \n\t\t int max_depth)\n{\n PyArrayObject *r;\n int nd;\n\tintp *d;\n\tint stop_at_string;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->itemsize;\n\t\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 if (!((nd=discover_depth(s, MAX_DIMS+1, stop_at_string)) > 0)) {\n\t\tif (nd==0)\n\t\t\treturn Array_FromScalar(s, typecode);\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid input sequence\");\n return NULL;\n }\n\t\n if ((max_depth && nd > max_depth) ||\t\\\n\t (min_depth && nd < min_depth)) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid number of dimensions\");\n return NULL;\n }\n\t\n\tif ((d=PyDimMem_NEW(nd)) == NULL) {\n\t\treturn PyErr_NoMemory();\n }\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) {\n\t\tPyDimMem_FREE(d);\n\t\treturn NULL;\n\t}\n\tif (itemsize == 0 && PyTypeNum_ISFLEXIBLE(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) {\n\t\t\tPyDimMem_FREE(d);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n r=(PyArrayObject*)PyArray_New(&PyArray_Type, nd, d, \n\t\t\t\t type, NULL, NULL,\n\t\t\t\t itemsize, \n\t\t\t\t typecode->fortran, NULL);\n\n PyDimMem_FREE(d);\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\n\nstatic int \nPyArray_ValidType(int type) \n{\n\tPyArray_Descr *descr;\n\t\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr==NULL) return 0;\n\treturn 1;\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->itemsize;\n\tint nels = PyArray_BUFSIZE;\n\tint el;\n\tint inswap, outswap=0;\n\tint obuf=!PyArray_ISCARRAY(out);\n\tint oelsize = out->itemsize;\n\tPyArray_VectorUnaryFunc *castfunc;\n PyArray_CopySwapFunc *in_csn;\n PyArray_CopySwapFunc *out_csn;\n\tint retval = -1;\n\n\tcastfunc = in->descr->cast[out->descr->type_num];\n in_csn = in->descr->copyswap;\n out_csn = out->descr->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\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\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->itemsize * 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\n/* For backward compatibility */\n\nstatic PyObject *\nPyArray_Cast(PyArrayObject *mp, int type_num) \n{\n\tPyArray_Typecode type;\n\tPyArray_Descr *descr;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\ttype.itemsize = descr->elsize;\n\ttype.type_num = descr->type_num;\n\ttype.fortran = 0;\n\t\n\treturn PyArray_CastToType(mp, &type);\n}\n\nstatic PyObject * \nPyArray_CastToType(PyArrayObject *mp, PyArray_Typecode *at) \n{\n\tPyObject *out;\n\tint ret;\n\n\tif ((mp->descr->type_num == at->type_num) && \\\n\t (at->itemsize==0 || mp->itemsize == at->itemsize) &&\n\t PyArray_ISBEHAVED_RO(mp)) {\n\t\tPy_INCREF(mp);\n\t\treturn (PyObject *)mp;\n\t}\n\t\t\n\tif (at->itemsize == 0) {\n\t\tif (mp->descr->type_num == PyArray_STRING &&\t\\\n\t\t at->type_num == PyArray_UNICODE)\n\t\t\tat->itemsize = mp->itemsize*sizeof(Py_UNICODE);\n\t\tif (mp->descr->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING) \n\t\t\tat->itemsize = mp->itemsize/sizeof(Py_UNICODE);\n\t\tif (at->type_num == PyArray_VOID)\n\t\t\tat->itemsize = mp->itemsize;\n\t}\n\n\tout = PyArray_New(mp->ob_type, mp->nd, \n\t\t\t mp->dimensions, \n\t\t\t at->type_num,\n\t\t\t NULL, NULL, at->itemsize, \n\t\t\t at->fortran, (PyObject *)mp);\n\tif (out == NULL) return NULL;\n\tret = PyArray_CastTo((PyArrayObject *)out, mp);\n\tif (ret != -1) return out;\n\n\tPy_DECREF(out);\n\treturn NULL;\n\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\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\tsimple = ((PyArray_ISCARRAY(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY(mp) && PyArray_ISFARRAY(out)));\n\t\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->itemsize * outsize;\n\t\tintp ncopies = outsize / mpsize;\n\n\t\twhile(ncopies--) {\n\t\t\tinptr = mp->data;\n\t\t\tmp->descr->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\nstatic PyObject *\narray_fromarray(PyArrayObject *arr, PyArray_Typecode *typecode, int flags) \n{\n\t\n\tPyArrayObject *ret=NULL;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->itemsize;\n\tint copy = 0;\n\tint arrflags;\n\tPyArray_Typecode oldtype;\n\tchar *msg = \"cannot copy back to a read-only array\";\n PyTypeObject *subtype;\n\n\toldtype.type_num = PyArray_TYPE(arr);\n\toldtype.itemsize = PyArray_ITEMSIZE(arr);\n\toldtype.fortran = 0;\n\n subtype = arr->ob_type;\n\n\tif (type == PyArray_NOTYPE) type = arr->descr->type_num;\n\tif (itemsize == 0) itemsize = arr->itemsize;\n\ttypecode->type_num = type;\n\ttypecode->itemsize = itemsize;\n\n\t/* Don't copy if sizes are compatible */\n\tif (PyArray_EquivalentTypes(&oldtype, typecode)) {\n\t\tarrflags = arr->flags;\n\n\t\tcopy = (flags & ENSURECOPY) || \\\n\t\t\t((flags & CONTIGUOUS) && (!(arrflags & CONTIGUOUS))) \\\n\t\t\t|| (PyArray_ITEMSIZE(arr) != itemsize) || \\\n\t\t\t((flags & ALIGNED) && (!(arrflags & ALIGNED))) || \\\n\t\t\t((flags & NOTSWAPPED) && (!(arrflags & NOTSWAPPED))) \\\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 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_New(subtype, \n\t\t\t\t\t arr->nd, \n\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t arr->descr->type_num,\n\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t itemsize,\n\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t (PyObject *)arr);\n\t\t\tif (PyArray_CopyInto(ret, arr) == -1) 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 ret = (PyArrayObject *) \\\n PyArray_New(&PyArray_Type,\n arr->nd,\n arr->dimensions,\n arr->descr->type_num,\n arr->strides,\n arr->data,\n arr->itemsize,\n arr->flags,NULL);\n if (ret == NULL) return NULL;\n ret->base = (PyObject *)arr;\n ret->flags &= ~UPDATEIFCOPY;\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_CanCastSafely(PyArray_TYPE(arr), type)) {\n if ((flags & UPDATEIFCOPY) && \\\n (!PyArray_ISWRITEABLE(arr))) {\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_New(subtype, arr->nd,\n arr->dimensions, typecode->type_num,\n NULL, NULL, typecode->itemsize,\n typecode->fortran, \n (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\nstatic int\n_array_typecode_fromstr(char *str, int *swap, PyArray_Typecode *type)\n{\n int type_num;\n char typechar;\n int size;\n unsigned long number = 1;\n char *s;\n char msg[] = \"unsupported typestring\";\n \n s = (char *)&number; /* s[0] == 0 implies big-endian */\n\n *swap = 0;\n\n if (str[0] == '<' || str[0] == '>') {\n\tif ((str[0] == '<') && (s[0] == 0)) *swap = 1;\n\telse if ((str[0] == '>') && (s[0] != 0)) *swap = 1;\n }\n str += 1;\n \n#define _MY_FAIL {\t\t\t\t \\\n\t PyErr_SetString(PyExc_ValueError, msg); \\\n\t return -1;\t\t\t \\\n }\t\t\n\n typechar = str[0];\n size = atoi(str + 1);\n switch (typechar) {\n case 'b':\n\t if (size == sizeof(Bool))\n\t\t type_num = PyArray_BOOL;\t \n\t else _MY_FAIL \n\t break;\t\t \n case 'u':\n if (size == sizeof(uintp))\n type_num = PyArray_UINTP;\n\t else if (size == sizeof(char))\n\t\t type_num = PyArray_UBYTE;\n\t else if (size == sizeof(short)) \n\t\t type_num = PyArray_USHORT;\n\t else if (size == sizeof(int)) \n\t\t type_num = PyArray_UINT;\n\t else if (size == sizeof(ulong)) \n\t\t type_num = PyArray_ULONG;\n\t else if (size == sizeof(ulonglong))\n\t\t type_num = PyArray_ULONGLONG;\n\t else _MY_FAIL\n\t break;\t\t \n case 'i':\n if (size == sizeof(intp))\n type_num = PyArray_INTP;\n\t else if (size == sizeof(char)) \n\t\t type_num = PyArray_BYTE;\n\t else if (size == sizeof(short)) \n\t\t type_num = PyArray_SHORT;\n\t else if (size == sizeof(int))\n\t\t type_num = PyArray_INT;\n\t else if (size == sizeof(long)) \n\t\t type_num = PyArray_LONG;\n\t else if (size == sizeof(longlong))\n\t\t type_num = PyArray_LONGLONG;\n\t else _MY_FAIL\n\t break;\t\t \n case 'f':\n\t if (size == sizeof(float))\n\t\t type_num = PyArray_FLOAT;\n\t else if (size == sizeof(double))\n\t\t type_num = PyArray_DOUBLE;\n\t else if (size == sizeof(longdouble))\n\t\t type_num = PyArray_LONGDOUBLE;\n\t else _MY_FAIL\n\t break;\n case 'c':\n\t if (size == sizeof(float)*2)\n\t\t type_num = PyArray_CFLOAT;\n\t else if (size == sizeof(double)*2)\n\t\t type_num = PyArray_CDOUBLE;\n\t else if (size == sizeof(longdouble)*2)\n\t\t type_num = PyArray_CLONGDOUBLE;\n\t else _MY_FAIL\n\t break;\n case 'O':\n\t if (size == sizeof(PyObject *))\n\t\t type_num = PyArray_OBJECT;\n\t else _MY_FAIL\n\t break;\n case 'S':\n\t type_num = PyArray_STRING;\n\t break;\n case 'U':\n\t type_num = PyArray_UNICODE;\n\t size *= sizeof(Py_UNICODE);\n\t break;\t \n case 'V':\n\t type_num = PyArray_VOID;\n\t break;\n default:\n\t _MY_FAIL\n }\n\n#undef _MY_FAIL\n\n type->type_num = type_num;\n type->itemsize = size;\n type->fortran = 0;\n return 0;\n}\n\nstatic PyObject *\narray_frominterface(PyObject *input, PyArray_Typecode *intype, int flags)\n{\n\tPyObject *attr=NULL, *item=NULL, *r;\n\tPyArrayObject *ret=NULL;\n\tPyArray_Typecode type;\n\tchar *data;\n\tint buffer_len;\n\tint res, i, n;\n\tintp dims[MAX_DIMS], strides[MAX_DIMS];\n\tint swap;\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\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) {Py_XDECREF(attr); return NULL;}\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t}\n\telse {\n\t\tif (PyTuple_GET_SIZE(attr) != 2) {\n\t\t\tPy_DECREF(attr);\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\treturn NULL;\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\tPy_DECREF(attr);\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\treturn NULL;\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 = PyObject_GetAttrString(input, \"__array_typestr__\");\n\tif (!PyString_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_typestr__ must be a string\");\n\t\tPy_DECREF(attr);\n\t\treturn NULL;\t\n\t}\n\tres = _array_typecode_fromstr(PyString_AS_STRING(attr), &swap, &type);\n\tPy_DECREF(attr);\n\tif (res < 0) return NULL;\n \n\tattr = PyObject_GetAttrString(input, \"__array_shape__\");\n\tif (!PyTuple_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_shape__ must be a tuple\");\n\t\tPy_DECREF(attr);\n\t\treturn NULL;\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\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\treturn NULL;\n\t\t}\n\t\tfor (i=0; istrides, strides, n*sizeof(intp));\n\t}\n\n\tif (swap) {\n\t\tPyObject *tmp;\n tmp = PyArray_Byteswap(ret, TRUE);\n\t\tPy_DECREF(tmp);\n\t}\n\n\tPyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n\tr = array_fromarray(ret, intype, flags);\n\tPy_DECREF(ret);\n\treturn r;\n}\n\nstatic PyObject *\narray_fromattr(PyObject *op, PyArray_Typecode *typecode, int flags) \n{\n PyObject *new, *r;\n\t \n if (typecode->type_num == PyArray_NOTYPE) {\n new = PyObject_CallMethod(op, \"__array__\", NULL);\n } else {\n\t\tPyArray_Descr *descr;\n\t\tPyObject *obj;\n\n\t\tdescr = PyArray_DescrFromType(typecode->type_num);\n\t\tif (PyTypeNum_ISFLEXIBLE(typecode->type_num)) {\n\t\t\tobj = PyString_FromFormat(\"%c%d\", descr->type,\n\t\t\t\t\t\t typecode->itemsize);\n\t\t}\n\t\telse { \n\t\t\tobj = (PyObject *)(descr->typeobj); Py_INCREF(obj);\n\t\t}\n\t\tnew = PyObject_CallMethod(op, \"__array__\", \"N\", obj);\n }\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 r = array_fromarray((PyArrayObject *)new, typecode, flags);\n Py_DECREF(new);\n return r;\n} \n\n\nstatic PyObject *\narray_fromobject(PyObject *op, PyArray_Typecode *typecode, int min_depth, \n\t\t int max_depth, int flags) \n{\n /* This is the main code to make a NumPy array from a Python\n Object. It is called from lot's of different places which\n is why there are so many checks. The comments try to\n explain some of the checks. */\n\n\tint type = typecode->type_num;\n PyObject *r=NULL;\n\n\t/* Is input object already an array? */\n\t/* This is where the flags are used */\n if (PyArray_Check(op)) \n\t\tr = array_fromarray((PyArrayObject *)op, typecode, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, typecode);\n\t}\n\telse if (PyObject_HasAttrString(op, \"__array__\")) {\n\t\t/* Code that returns the object to convert for a non\n\t\t multiarray input object from the __array__ attribute of the\n\t\t object. */\n r = array_fromattr(op, typecode, flags);\n\t}\n\telse if (PyObject_HasAttrString(op, \"__array_shape__\") &&\n\t\t PyObject_HasAttrString(op, \"__array_typestr__\")) {\n\t\tr = array_frominterface(op, typecode, flags);\n\t}\n\telse {\n\t\tif (type == PyArray_NOTYPE) {\n\t\t\t_array_find_type(op, NULL, typecode, MAX_DIMS);\n\t\t}\n\t\tif (PySequence_Check(op))\n\t\t\tr = Array_FromSequence(op, typecode, \n\t\t\t\t\t min_depth, max_depth);\n\t\telse\n\t\t\tr = Array_FromScalar(op, typecode);\n\t}\n\n /* If we didn't succed return NULL */\n if (r == NULL) return NULL;\n\t\n\t/* Be sure we succeed here */\n\t\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"internal error: array_fromobject \"\\\n\t\t\t\t\"not producing an array\");\n\t\tPy_DECREF(r);\n return NULL;\n }\n\n if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {\n Py_DECREF(r);\n PyErr_SetString(PyExc_ValueError, \n \"object of too small depth for desired array\");\n return NULL;\n }\n if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {\n Py_DECREF(r);\n PyErr_SetString(PyExc_ValueError, \n \"object too deep for desired array\");\n return NULL;\n }\n return r;\n}\n\nstatic void\nPyArray_ArrayType(PyObject *op, PyArray_Typecode *intype, \n\t\t PyArray_Typecode *outtype) \n{\n\t_array_find_type(op, intype, outtype, MAX_DIMS);\n\treturn;\n}\n\nstatic int \nPyArray_ObjectType(PyObject *op, int minimum_type) \n{\n\tPyArray_Typecode intype, outtype;\n\tintype.type_num = minimum_type;\n\t_array_find_type(op, &intype, &outtype, MAX_DIMS);\n\treturn outtype.type_num;\n}\n\n\n\n/* flags is any of \n CONTIGUOUS, \n FORTRAN, (or set typecode->fortran=1)\n ALIGNED, \n NOTSWAPPED, \n WRITEABLE, \n ENSURECOPY, \n UPDATEIFCOPY,\n FORCECAST,\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, NOTSWAPPED, and WRITEABLE\n and therefore it is redundant to include those as well. \n\n BEHAVED_FLAGS == ALIGNED | NOTSWAPPED | WRITEABLE\n BEHAVED_FLAGS_RO == ALIGNED | NOTSWAPPED\n CARRAY_FLAGS = CONTIGUOUS | BEHAVED_FLAGS\n FARRAY_FLAGS = FORTRAN | BEHAVED_FLAGS\n \n By default, the returned array will be a copy of the object, \n (C) contiguous in memory, aligned, notswapped, and writeable.\n \n So CONTIGUOUS | ENSURECOPY passed in means that the returned\n array does not have to be CONTIGUOUS or a COPY but should be\n ALIGNED, NOTSWAPPED and WRITEABLE. \n\n typecode->fortran can be set to request a\n fortran-contiguous array. Fortran arrays are always behaved (aligned, \n notswapped, and writeable) and not (C) CONTIGUOUS. Note that either\n FORTRAN in the flag or typecode->fortran = 1 is enough to request\n a FORTRAN-style array. \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\nstatic PyObject *\nPyArray_FromAny(PyObject *op, PyArray_Typecode *typecode, int min_depth, \n\t\tint max_depth, int requires) \n{\n \tPyArray_Typecode mine = {PyArray_NOTYPE, 0, 0};\n\tPyArray_Typecode *type;\n\t\n\tif (typecode == NULL) type = &mine;\n\telse type = typecode;\n\t\t\n\tif (requires & ENSURECOPY) {\n\t\trequires |= DEFAULT_FLAGS;\n\t}\n\t/* Ensure that type->fortran and flags & FORTRAN are the\n\t same */\n\tif (requires & FORTRAN) typecode->fortran = 1;\n\tif (type->fortran == 1) {\n\t\trequires |= FARRAY_FLAGS;\n\t\tif (min_depth > 2) requires &= ~CONTIGUOUS;\n\t}\n\n\t/* make sure itemsize is not 0 unless warranted. */\n\tif ((type->itemsize == 0) && (type->type_num != PyArray_NOTYPE)) {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(type->type_num);\n\t\tif (descr != NULL) type->itemsize = descr->elsize;\n\t\telse return NULL;\n\t}\n\t\n\treturn array_fromobject(op, type, min_depth, max_depth, \n\t\t\t\trequires);\t\n}\n\n/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0, 0) */\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\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);\n Py_DECREF(op);\n return new;\n}\n\n/* These are all compressed into a single API */\n/* Deprecated calls -- Use PyArray_FromAny */\n\nstatic PyObject *\nPyArray_FromObject(PyObject *op, int type, int min_depth, int max_depth) \n{\n\tPyArray_Typecode typecode = {0, 0, 0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth,\n\t\t\t max_depth, BEHAVED_FLAGS | ENSUREARRAY);\n}\n\nstatic PyObject *\nPyArray_ContiguousFromObject(PyObject *op, int type, int min_depth, \n\t\t\t int max_depth) \n{\n\tPyArray_Typecode typecode = {0, 0, 0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth,\n\t\t\t max_depth, DEFAULT_FLAGS | ENSUREARRAY);\n}\n\nstatic PyObject *\nPyArray_CopyFromObject(PyObject *op, int type, int min_depth, \n\t\t int max_depth) \n{\n\tPyArray_Typecode typecode = {0, 0, 0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth, max_depth,\n\t\t\t ENSURECOPY | ENSUREARRAY);\n}\n\n/* End of deprecated */\n\nstatic PyObject *\nPyArray_ContiguousFromAny(PyObject *op, int type, int min_depth, \n\t\t\t int max_depth)\n{\n\tPyArray_Typecode typecode = {0,0,0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth,\n\t\t\t max_depth, DEFAULT_FLAGS);\n}\t\n\nstatic int \nPyArray_CanCastSafely(int fromtype, int totype) \n{\n\tPyArray_Descr *from, *to;\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\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 (to->elsize > from->elsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (to->elsize >= from->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (from->elsize < 8)\n return (to->elsize > from->elsize);\n else\n return (to->elsize >= from->elsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (from->elsize < 8)\n return ((to->elsize >> 1) > from->elsize);\n else\n return ((to->elsize >> 1) >= from->elsize);\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 (to->elsize > from->elsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (to->elsize >= from->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (from->elsize < 8)\n return (to->elsize > from->elsize);\n else\n return (to->elsize >= from->elsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (from->elsize < 8)\n return ((to->elsize >> 1) > from->elsize);\n else\n return ((to->elsize >> 1) >= from->elsize);\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 ((to->elsize >> 1) >= from->elsize);\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\nstatic Bool\nPyArray_CanCastTo(PyArray_Typecode *from, PyArray_Typecode *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->itemsize <= to->itemsize);\n\t\t\t}\n\t\t\telse if (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->itemsize * sizeof(Py_UNICODE)\\\n\t\t\t\t <= to->itemsize);\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->itemsize <= to->itemsize);\n\t\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 scipy's arraymap ****/\n/* and Python's array iterator ***/\n \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 = PyObject_GC_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 PyObject_GC_Track(it);\n return (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 PyObject_GC_UnTrack(it);\n Py_XDECREF(it->ao);\n PyObject_GC_Del(it);\n }\n\nstatic int\narrayiter_traverse(PyArrayIterObject *it, visitproc visit, void *arg)\n{\n if (it->ao != NULL)\n return visit((PyObject *)(it->ao), arg);\n return 0;\n}\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->itemsize;\n\tr = PyArray_New(self->ao->ob_type, 1, &count, \n\t\t\tself->ao->descr->type_num, NULL, NULL,\n\t\t\titemsize, 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->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->itemsize;\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\tr = PyArray_New(self->ao->ob_type, ind->nd, ind->dimensions,\n\t\t\tself->ao->descr->type_num, NULL, \n\t\t\tNULL, self->ao->itemsize, \n\t\t\t0, (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)->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\tint i;\n\tPyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tint 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\t\t\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\n\t/* Tuples 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\tr = PyArray_New(self->ao->ob_type, 1, &ii, \n\t\t\t\t\tself->ao->descr->type_num, NULL, \n\t\t\t\t\tNULL, self->ao->itemsize, 0,\n\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 */\n\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->itemsize;\n\t\tr = PyArray_New(self->ao->ob_type, 1, &n_steps, \n\t\t\t\tself->ao->descr->type_num, NULL, NULL,\n\t\t\t\tsize, 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)->copyswap;\n\t\twhile(n_steps--) {\n copyswap(dptr, self->dataptr, swap, size);\n\t\t\tfor(i=0; i< step_size; i++) \n\t\t\t\tPyArray_ITER_NEXT(self);\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\tif (PyArray_IsScalar(ind, Integer) || PyList_Check(ind)) {\n\t\tobj = PyArray_FromAny(ind, &indtype, 0, 0, FORCECAST);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tr = iter_subscript_Bool(self, (PyArrayObject *)obj);\n\t\t} \n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, &indtype, 0, 0, \n\t\t\t\t\t FORCECAST | BEHAVED_FLAGS);\n\t\t\tif (new==NULL) goto fail;\n\t\t\tobj = new;\n\t\t\tr = iter_subscript_int(self, (PyArrayObject *)obj);\n\t\t}\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\t\"unsupported iterator index\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPy_DECREF(obj);\n\t\treturn r;\n\t}\n\n\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\n fail:\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->itemsize;\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->copyswap;\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(self->dataptr, val->dataptr, swap,\n itemsize);\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t\tPyArray_ITER_NEXT(val);\n\t\tif (val->index==val->size) \n\t\t\tPyArray_ITER_RESET(val);\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_Typecode typecode;\n\tintp num;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\titemsize = typecode.itemsize = self->ao->itemsize;\n\ttypecode.type_num = self->ao->descr->type_num;\n copyswap = self->ao->descr->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\n\nstatic int\niter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val) \n{\n\tint i;\n\tPyObject *arrval=NULL;\n\tPyArrayIterObject *val_it=NULL;\n\tPyArray_Typecode type;\n\tPyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tint swap;\n\tint itemsize;\n\tint start, step_size;\n\tintp n_steps;\n\tPyObject *obj;\n PyArray_CopySwapFunc *copyswap;\n\t\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\ti = iter_ass_subscript(self, ind, val);\n\t\tPy_DECREF(ind);\n\t\treturn i;\n\t}\n\t\n\ttype.type_num = self->ao->descr->type_num;\n\titemsize = type.itemsize = self->ao->itemsize;\n\t\n\tarrval = PyArray_FromAny(val, &type, 0, 0, 0);\n\tif (arrval==NULL) return -1;\n\tval_it = (PyArrayIterObject *)PyArray_IterNew(arrval);\n\tif (val_it==NULL) goto fail;\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\n copyswap = PyArray_DESCR(arrval)->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\tgoto succeed;\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 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 copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, itemsize);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\tgoto succeed;\n\t\t}\n\t\twhile(n_steps--) {\n copyswap(self->dataptr, val_it->dataptr,\n swap, itemsize);\n\t\t\tfor(i=0; i < step_size; i++) \n\t\t\t\tPyArray_ITER_NEXT(self);\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\tgoto succeed;\n\t} \n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tif (PyArray_IsScalar(ind, Integer))\n\t\tobj = PyArray_FromScalar(ind, &indtype);\n\telse if (PyList_Check(ind)) {\n\t\tobj = PyArray_FromAny(ind, &indtype, 0, 0, FORCECAST);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tif (iter_ass_sub_Bool(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto fail;\n\t\t} \n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, &indtype, 0, 0, \n\t\t\t\t\t FORCECAST | BEHAVED_FLAGS);\n\t\t\tif (new==NULL) goto fail;\n\t\t\tPy_DECREF(obj);\n\t\t\tobj = new;\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 fail;\n\t\t}\n\t\telse goto fail;\n\t\tPy_DECREF(obj);\n\t\tgoto succeed;\n\t}\n\n\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\tgoto fail;\n\n succeed:\n\tPy_DECREF(val_it);\n\tPy_DECREF(arrval);\n\treturn 0;\n\n fail:\n\tPy_XDECREF(val_it);\n\tPy_XDECREF(arrval);\n\treturn -1;\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 if (PyArray_ISCONTIGUOUS(it->ao)) {\n r = PyArray_New(it->ao->ob_type, 1, &size, \n\t\t\t\tit->ao->descr->type_num,\n NULL, it->ao->data, it->ao->itemsize, \n\t\t\t\tit->ao->flags,\n (PyObject *)it->ao); \n\t\tif (r==NULL) return NULL;\n }\n else {\n r = PyArray_New(it->ao->ob_type, 1, &size, \n\t\t\t\tit->ao->descr->type_num,\n NULL, NULL, it->ao->itemsize, 0, \n (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\n\nstatic PyTypeObject PyArrayIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"scipy.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 | Py_TPFLAGS_HAVE_GC,/* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)arrayiter_traverse,\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)arrayiter_next,\t\t/* tp_iternext */\n iter_methods,\t\t\t\t/* tp_methods */\n};\n\n/** END of Array Iterator **/\n\n\n\n/*********************** Subscript Array Iterator *************************\n * *\n * This object handles subscript behavior for array objects. *\n * It is an iterator object with a next method *\n * It abstracts the n-dimensional mapping behavior to make the looping *\n * code more understandable (maybe) *\n * and so that indexing can be set up ahead of time *\n */ \n\n/* This checks the args for any fancy indexing objects */\n\n#define SOBJ_NOTFANCY 0 \n#define SOBJ_ISFANCY 1\n#define SOBJ_BADARRAY 2\n#define SOBJ_TOOMANY 3\n#define SOBJ_LISTTUP 4\n\nstatic int\nfancy_indexing_check(PyObject *args)\n{\n\tint i, n;\n\tPyObject *obj;\n\tint retval = SOBJ_NOTFANCY;\n\n\tif (PyTuple_Check(args)) {\n\t\tn = PyTuple_GET_SIZE(args);\n\t\tif (n >= MAX_DIMS) return SOBJ_TOOMANY;\n\t\tfor (i=0; i=MAX_DIMS) return SOBJ_ISFANCY;\n\t\tfor (i=0; i SOBJ_ISFANCY) return retval;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* convert an indexing object to an INTP indexing array iterator\n if possible -- otherwise, it is a Slice or Ellipsis object\n and has to be interpreted on bind to a particular \n array so leave it NULL for now.\n */\nstatic int\n_convert_obj(PyObject *obj, PyArrayIterObject **iter)\n{\n\tPyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tPyObject *arr;\n\n\tif (PySlice_Check(obj) || (obj == Py_Ellipsis))\n\t\t*iter = NULL;\n\telse {\n\t\tarr = PyArray_FromAny(obj, &indtype, 0, 0, FORCECAST);\n\t\tif (arr == NULL) return -1;\n\t\t*iter = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (*iter == NULL) return -1;\n\t}\n\treturn 0;\n}\n\n/* Adjust dimensionality and strides for index object iterators \n --- i.e. broadcast\n */\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->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->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=NULL, *obj=NULL;\n\tint i, j, n, curraxis, ellipexp, noellip;\n\tPyArrayIterObject *it;\n\tintp dimsize;\n\tintp *indptr;\n\n\t/* Remove old binding if any */\n\tPy_XDECREF(mit->ait);\n\tmit->ait = NULL;\n\n\tPy_XDECREF(mit->subspace);\n\tmit->subspace = NULL;\n\t\n\tsubnd = arr->nd - mit->numiter;\n\tif (subnd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"too many indices for array\");\n\t\treturn;\n\t}\n\n\tmit->ait = (PyArrayIterObject *)PyArray_IterNew((PyObject *)arr);\n\tif (mit->ait == NULL) return;\n\n\t/* If this is just a view, then do nothing more */\n\t/* views are handled by just adjusting the strides\n\t and dimensions of the object.\n\t*/\n\t \n\tif (mit->view) return;\n\n\t/* no subspace iteration needed. 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\tif (mit->subspace == NULL) goto fail;\n\tPy_DECREF(sub);\n\n\t/* Expand dimensions of result */\n\tn = mit->subspace->ao->nd;\n\tfor (i=0; idimensions[mit->nd+i] = mit->subspace->ao->dimensions[i];\n\tmit->nd += n;\n\n\t/* Now, we still need to interpret the ellipsis and slice objects \n\t to determine which axes the indexing arrays are referring to\n\t*/\n\tn = PyTuple_GET_SIZE(mit->indexobj);\n\n\t/* The number of dimensions an ellipsis takes up */\n\tellipexp = arr->nd - n + 1;\n\t/* Now fill in iteraxes -- remember indexing arrays have been \n converted to 0's in mit->indexobj */\n\tcurraxis = 0;\n\tj = 0;\n\tnoellip = 1; /* Only expand the first ellipsis */\n\tmemset(mit->bscoord, 0, sizeof(intp)*arr->nd);\n\tfor (i=0; iindexobj, i);\n\t\tif (PyInt_Check(obj) || PyLong_Check(obj)) \n\t\t\tmit->iteraxes[j++] = curraxis++;\n\t\telse if (noellip && obj == Py_Ellipsis) {\n\t\t\tcurraxis += ellipexp;\n\t\t\tnoellip = 0;\n\t\t}\n\t\telse {\n\t\t\tint start=0;\n\t\t\tint 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}\t\t\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn;\n\n fail:\n\tPy_XDECREF(sub);\n\tPy_XDECREF(mit->ait);\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_Typecode typecode = {PyArray_BOOL, 0, 0};\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\tba = (PyArrayObject *)PyArray_FromAny(myBool, &typecode, 0, 0, \n\t\t\t\t\t CARRAY_FLAGS);\n\tif (ba == NULL) return -1;\n\tnd = ba->nd;\n\tfor (j=0; jdata;\n\tcount = 0;\n\n\t/* pre-determine how many nonzero entries there are */\n\tfor (i=0; iao->data;\n\t\tcoords[j] = 0;\n\t\tdims_m1[j] = ba->dimensions[j]-1;\n\t}\n\n\tptr = (Bool *)ba->data;\n\n\tif (count == 0) return nd;\n\n\t/* Loop through the Boolean array and copy coordinates\n\t for non-zero entries */\n\tfor (i=0; i=0; j--) {\n\t\t\tif (coords[j] < dims_m1[j]) {\n\t\t\t\tcoords[j]++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcoords[j] = 0;\n\t\t\t}\n\t\t}\n\t}\n\treturn nd;\n\n fail:\n\tfor (j=0; jiters[i] = NULL;\n \tmit->view = 0;\n \tmit->index = 0;\n \tmit->ait = NULL;\n \tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tfancy = fancy_indexing_check(indexobj);\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\tif (fancy == SOBJ_NOTFANCY) { /* bail out */\n\t\tmit->view = 1;\n\t\tgoto ret;\n\t}\n\n\tif (fancy == SOBJ_BADARRAY) {\n\t\tPyErr_SetString(PyExc_TypeError,\t\t\t\\\n\t\t\t\t\"arrays used as indexes must be of \" \\\n\t\t\t\t\"integer type\");\n\t\tgoto fail;\n\t}\n\tif (fancy == SOBJ_TOOMANY) {\n\t\tPyErr_SetString(PyExc_TypeError, \"too many indicies\");\n\t\tgoto fail;\n\t}\n\n\tif (fancy == SOBJ_LISTTUP) {\n\t\tPyObject *newobj;\n\t\tnewobj = PySequence_Tuple(indexobj);\n\t\tif (newobj == NULL) goto fail;\n\t\tPy_DECREF(indexobj);\n\t\tindexobj = newobj;\n\t\tmit->indexobj = indexobj;\n\t}\n\n#undef SOBJ_NOTFANCY \n#undef SOBJ_ISFANCY \n#undef SOBJ_BADARRAY \n#undef SOBJ_TOOMANY \n#undef SOBJ_LISTTUP \n\n\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\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 (PyList_Check(indexobj) || PyArray_Check(indexobj)) {\n\t\tmit->numiter = 1;\n\t\tarr = PyArray_FromAny(indexobj, &indtype, 0, 0, FORCECAST);\n\t\tif (arr == NULL) goto fail;\n\t\tmit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (mit->iters[0] == NULL) 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(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\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = new;\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\t/* Store the number of iterators actually converted */\n\t\t/* These will be mapped to actual axes at bind time */\n\t\tif (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)\n\t\t\tgoto fail;\n\t}\n\n ret:\n PyObject_GC_Track(mit);\n return (PyObject *)mit;\n \n fail:\n\tPy_XDECREF(arr);\n\tPy_XDECREF(mit->indexobj);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n PyObject_GC_Del(mit);\n\treturn NULL;\n}\n\n\n/* return unbound mapiter object */\n\nstatic PyObject *\narraymapiter_new(PyTypeObject *type, PyObject *args, PyObject *kwds) \n{\n\tPyObject *newtup, *res;\n\tint n;\n\n\tif (!PyTuple_Check(args)) {\n\t\tPyErr_BadInternalCall();\n\t\treturn NULL;\n\t}\n\n\tn = PyTuple_GET_SIZE(args);\n\t\n\tif (n < 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"must be initialized with >= 1 argument\");\n\t\treturn NULL;\n\t}\n\t\n\tif (n > 1) {\n\t\tnewtup = PyTuple_GetSlice(args, 0, n);\n\t\tif (newtup == NULL) return NULL;\n\t\tres = PyArray_MapIterNew(newtup);\n\t\tPy_DECREF(newtup);\n\t}\n\telse { /* n == 1 */\n\t\tnewtup = PyTuple_GET_ITEM(args, 0);\n\t\tres = PyArray_MapIterNew(newtup);\n\t}\n\n\treturn res; \t\n}\n\n\n/* Returns a 0-dim array holding the element desired */\n/*\nstatic PyObject *\narraymapiter_next(PyArrayMapIterObject *mit)\n{\n\tPyObject *ret;\n\tif (mit->ait == NULL) return NULL;\n\tif (mit->view) return NULL;\n\tif (mit->index < mit->size) {\n\t\tret = PyArray_ToScalar(mit->dataptr, mit->ait->ao);\n\t\tPyArray_MapIterNext(mit);\n\t\treturn ret;\n\t}\n return NULL;\n}\n*/\n\nstatic void\narraymapiter_dealloc(PyArrayMapIterObject *mit)\n{\n\tint i;\n PyObject_GC_UnTrack(mit);\n Py_XDECREF(mit->ait);\n\tPy_XDECREF(mit->indexobj);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n PyObject_GC_Del(mit);\n}\n\nstatic int\narraymapiter_traverse(PyArrayMapIterObject *mit, visitproc visit, void *arg)\n{\n\tint ret, i;\n if (mit->ait != NULL)\n if ((ret = visit((PyObject *)(mit->ait), arg)) != 0) \n\t\t\treturn ret;\t\n\n\tif (mit->iters != NULL) \n\t\tfor (i=0; inumiter; i++) \n\t\t\tif (mit->iters[i] != NULL) \n\t\t\t\tif ((ret=visit((PyObject *)mit->iters[i], \n\t\t\t\t\t arg)) != 0)\n\t\t\t\t\treturn ret;\n\n\tif (mit->indexobj != NULL)\n\t\tif ((ret = visit(mit->indexobj, arg)) != 0) return ret;\n\t\n return 0;\n}\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 MapIterNew must be \n that does not work. 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 char doc_mapiter_bind[] = \"obj.bind(a)\\n Bind an array to the \"\\\n\t\"mapiter object\";\n\nstatic PyObject *\nmapiter_bind(PyArrayMapIterObject *mit, PyObject *args)\n{\n\tPyArrayObject *arr;\n\n if (!PyArg_ParseTuple(args, \"O!\", &PyArray_Type, &arr)) return NULL;\n\n \tPyArray_MapIterBind(mit, arr);\n\n\tif (mit->ait == NULL) return NULL;\n\t\n \tPyArray_MapIterReset(mit);\n\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyMethodDef mapiter_methods[] = {\n\t{\"bind\", (PyCFunction)mapiter_bind, 1, doc_mapiter_bind},\n {NULL,\t\tNULL}\t\t\n};\n*/\n\n\nstatic PyTypeObject PyArrayMapIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"scipy.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 | Py_TPFLAGS_HAVE_GC,/* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)arraymapiter_traverse,\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, /*arraymapiter_next,*/\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 (newfunc)arraymapiter_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n\n};\n\n/** END of Subscript Iterator **/\n\n\n\n", "methods": [ { "name": "PyArray_PyIntAsIntp", "long_name": "PyArray_PyIntAsIntp( PyObject * o)", "filename": "arrayobject.c", "nloc": 59, "complexity": 19, "token_count": 385, "parameters": [ "o" ], "start_line": 40, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 64, "top_nesting_level": 0 }, { "name": "PyArray_PyIntAsInt", "long_name": "PyArray_PyIntAsInt( PyObject * o)", "filename": "arrayobject.c", "nloc": 57, "complexity": 19, "token_count": 389, "parameters": [ "o" ], "start_line": 109, "end_line": 169, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 61, "top_nesting_level": 0 }, { "name": "PyArray_GetPriority", "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", "filename": "arrayobject.c", "nloc": 17, "complexity": 5, "token_count": 86, "parameters": [ "obj", "default_" ], "start_line": 173, "end_line": 191, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "PyArray_Zero", "long_name": "PyArray_Zero( PyArrayObject * arr)", "filename": "arrayobject.c", "nloc": 34, "complexity": 6, "token_count": 190, "parameters": [ "arr" ], "start_line": 208, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "PyArray_One", "long_name": "PyArray_One( PyArrayObject * arr)", "filename": "arrayobject.c", "nloc": 40, "complexity": 7, "token_count": 222, "parameters": [ "arr" ], "start_line": 246, "end_line": 289, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "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": 295, "end_line": 345, "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": 368, "end_line": 399, "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": 213, "parameters": [ "src" ], "start_line": 402, "end_line": 436, "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": 449, "end_line": 471, "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": 474, "end_line": 495, "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": 499, "end_line": 537, "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": 542, "end_line": 562, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "index2ptr", "long_name": "index2ptr( PyArrayObject * mp , int i)", "filename": "arrayobject.c", "nloc": 10, "complexity": 7, "token_count": 86, "parameters": [ "mp", "i" ], "start_line": 570, "end_line": 580, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "PyArray_Size", "long_name": "PyArray_Size( PyObject * op)", "filename": "arrayobject.c", "nloc": 9, "complexity": 2, "token_count": 33, "parameters": [ "op" ], "start_line": 583, "end_line": 591, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "PyArray_CopyInto", "long_name": "PyArray_CopyInto( PyArrayObject * dest , PyArrayObject * src)", "filename": "arrayobject.c", "nloc": 71, "complexity": 16, "token_count": 427, "parameters": [ "dest", "src" ], "start_line": 604, "end_line": 684, "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": 16, "complexity": 2, "token_count": 98, "parameters": [ "dest", "src_object" ], "start_line": 688, "end_line": 707, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "PyArray_FromDimsAndDataAndDescr", "long_name": "PyArray_FromDimsAndDataAndDescr( int nd , int * d , PyArray_Descr * descr , char * data)", "filename": "arrayobject.c", "nloc": 15, "complexity": 3, "token_count": 121, "parameters": [ "nd", "d", "descr", "data" ], "start_line": 715, "end_line": 734, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "PyArray_FromDimsAndData", "long_name": "PyArray_FromDimsAndData( int nd , int * d , int type , char * data)", "filename": "arrayobject.c", "nloc": 14, "complexity": 3, "token_count": 112, "parameters": [ "nd", "d", "type", "data" ], "start_line": 738, "end_line": 755, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "PyArray_FromDims", "long_name": "PyArray_FromDims( int nd , int * d , int type)", "filename": "arrayobject.c", "nloc": 14, "complexity": 5, "token_count": 133, "parameters": [ "nd", "d", "type" ], "start_line": 759, "end_line": 776, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "PyArray_Copy", "long_name": "PyArray_Copy( PyArrayObject * m1)", "filename": "arrayobject.c", "nloc": 11, "complexity": 2, "token_count": 77, "parameters": [ "m1" ], "start_line": 782, "end_line": 794, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "PyArray_Scalar", "long_name": "PyArray_Scalar( char * data , int type_num , int itemsize , int swap)", "filename": "arrayobject.c", "nloc": 48, "complexity": 8, "token_count": 289, "parameters": [ "data", "type_num", "itemsize", "swap" ], "start_line": 800, "end_line": 849, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "top_nesting_level": 0 }, { "name": "PyArray_ToScalar", "long_name": "PyArray_ToScalar( char * data , PyArrayObject * arr)", "filename": "arrayobject.c", "nloc": 7, "complexity": 1, "token_count": 51, "parameters": [ "data", "arr" ], "start_line": 856, "end_line": 863, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_Return", "long_name": "PyArray_Return( PyArrayObject * mp)", "filename": "arrayobject.c", "nloc": 17, "complexity": 5, "token_count": 85, "parameters": [ "mp" ], "start_line": 869, "end_line": 888, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "PyArray_RegisterDataType", "long_name": "PyArray_RegisterDataType( PyTypeObject * type)", "filename": "arrayobject.c", "nloc": 31, "complexity": 6, "token_count": 177, "parameters": [ "type" ], "start_line": 899, "end_line": 931, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "PyArray_RegisterDescrForType", "long_name": "PyArray_RegisterDescrForType( int typenum , PyArray_Descr * descr)", "filename": "arrayobject.c", "nloc": 32, "complexity": 3, "token_count": 167, "parameters": [ "typenum", "descr" ], "start_line": 941, "end_line": 984, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "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": 16, "token_count": 577, "parameters": [ "self", "fp", "sep", "format" ], "start_line": 988, "end_line": 1079, "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": 24, "complexity": 5, "token_count": 151, "parameters": [ "self" ], "start_line": 1082, "end_line": 1110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "PyArray_ToString", "long_name": "PyArray_ToString( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 34, "complexity": 6, "token_count": 191, "parameters": [ "self" ], "start_line": 1113, "end_line": 1148, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "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": 1157, "end_line": 1194, "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": 1201, "end_line": 1209, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "array_item", "long_name": "array_item( PyArrayObject * self , int i)", "filename": "arrayobject.c", "nloc": 22, "complexity": 4, "token_count": 150, "parameters": [ "self", "i" ], "start_line": 1213, "end_line": 1237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "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": 26, "parameters": [ "self", "i" ], "start_line": 1240, "end_line": 1243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "array_ass_item", "long_name": "array_ass_item( PyArrayObject * self , int i , PyObject * v)", "filename": "arrayobject.c", "nloc": 27, "complexity": 8, "token_count": 177, "parameters": [ "self", "i", "v" ], "start_line": 1247, "end_line": 1277, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "slice_coerce_index", "long_name": "slice_coerce_index( PyObject * o , int * v)", "filename": "arrayobject.c", "nloc": 9, "complexity": 2, "token_count": 40, "parameters": [ "o", "v" ], "start_line": 1281, "end_line": 1289, "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 , int length , int * start , int * stop , int * step , intp * slicelength)", "filename": "arrayobject.c", "nloc": 45, "complexity": 24, "token_count": 376, "parameters": [ "r", "length", "start", "stop", "step", "slicelength" ], "start_line": 1295, "end_line": 1345, "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 , int * step_size , intp * n_steps , int max)", "filename": "arrayobject.c", "nloc": 45, "complexity": 11, "token_count": 223, "parameters": [ "op", "step_size", "n_steps", "max" ], "start_line": 1352, "end_line": 1397, "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": 89, "complexity": 20, "token_count": 540, "parameters": [ "self", "op", "dimensions", "strides", "offset_ptr" ], "start_line": 1401, "end_line": 1496, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 96, "top_nesting_level": 0 }, { "name": "_swap_axes", "long_name": "_swap_axes( PyArrayMapIterObject * mit , PyArrayObject ** ret)", "filename": "arrayobject.c", "nloc": 24, "complexity": 4, "token_count": 187, "parameters": [ "mit", "ret" ], "start_line": 1499, "end_line": 1533, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "PyArray_GetMap", "long_name": "PyArray_GetMap( PyArrayMapIterObject * mit)", "filename": "arrayobject.c", "nloc": 36, "complexity": 8, "token_count": 252, "parameters": [ "mit" ], "start_line": 1538, "end_line": 1587, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "top_nesting_level": 0 }, { "name": "PyArray_SetMap", "long_name": "PyArray_SetMap( PyArrayMapIterObject * mit , PyObject * op)", "filename": "arrayobject.c", "nloc": 50, "complexity": 12, "token_count": 392, "parameters": [ "mit", "op" ], "start_line": 1590, "end_line": 1649, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 60, "top_nesting_level": 0 }, { "name": "array_subscript", "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", "filename": "arrayobject.c", "nloc": 61, "complexity": 19, "token_count": 425, "parameters": [ "self", "op" ], "start_line": 1670, "end_line": 1745, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 76, "top_nesting_level": 0 }, { "name": "array_ass_sub", "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", "filename": "arrayobject.c", "nloc": 43, "complexity": 9, "token_count": 251, "parameters": [ "self", "index", "op" ], "start_line": 1758, "end_line": 1810, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "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": 1818, "end_line": 1821, "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": 1840, "end_line": 1852, "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": 1855, "end_line": 1870, "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": 1874, "end_line": 1883, "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": 1886, "end_line": 1897, "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": 1965, "end_line": 1998, "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": 2005, "end_line": 2044, "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": 23, "complexity": 5, "token_count": 136, "parameters": [ "m1", "op", "axis", "rtype" ], "start_line": 2047, "end_line": 2069, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "PyArray_GenericAccumulateFunction", "long_name": "PyArray_GenericAccumulateFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", "filename": "arrayobject.c", "nloc": 23, "complexity": 5, "token_count": 136, "parameters": [ "m1", "op", "axis", "rtype" ], "start_line": 2073, "end_line": 2095, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "PyArray_GenericBinaryFunction", "long_name": "PyArray_GenericBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", "filename": "arrayobject.c", "nloc": 12, "complexity": 2, "token_count": 69, "parameters": [ "m1", "m2", "op" ], "start_line": 2099, "end_line": 2110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_GenericUnaryFunction", "long_name": "PyArray_GenericUnaryFunction( PyArrayObject * m1 , PyObject * op)", "filename": "arrayobject.c", "nloc": 12, "complexity": 2, "token_count": 63, "parameters": [ "m1", "op" ], "start_line": 2113, "end_line": 2124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_GenericInplaceBinaryFunction", "long_name": "PyArray_GenericInplaceBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", "filename": "arrayobject.c", "nloc": 13, "complexity": 2, "token_count": 71, "parameters": [ "m1", "m2", "op" ], "start_line": 2127, "end_line": 2139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 2142, "end_line": 2145, "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": 2148, "end_line": 2151, "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": 2154, "end_line": 2157, "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": 2160, "end_line": 2163, "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": 2166, "end_line": 2169, "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": 2172, "end_line": 2175, "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": 2178, "end_line": 2181, "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": 2184, "end_line": 2187, "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": 2190, "end_line": 2193, "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": 2196, "end_line": 2199, "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": 2202, "end_line": 2205, "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": 2208, "end_line": 2211, "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": 2214, "end_line": 2217, "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": 2220, "end_line": 2223, "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": 2226, "end_line": 2229, "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": 2232, "end_line": 2235, "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": 2238, "end_line": 2241, "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": 2244, "end_line": 2247, "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": 2250, "end_line": 2253, "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": 2256, "end_line": 2259, "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": 2262, "end_line": 2265, "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": 2268, "end_line": 2271, "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": 2274, "end_line": 2277, "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": 2280, "end_line": 2283, "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": 2286, "end_line": 2289, "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": 2292, "end_line": 2295, "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": 2298, "end_line": 2301, "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": 2304, "end_line": 2308, "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": 2311, "end_line": 2315, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "array_all_nonzero", "long_name": "array_all_nonzero( PyArrayObject * mp)", "filename": "arrayobject.c", "nloc": 18, "complexity": 4, "token_count": 93, "parameters": [ "mp" ], "start_line": 2319, "end_line": 2337, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "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": 2340, "end_line": 2355, "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": 143, "parameters": [ "v" ], "start_line": 2359, "end_line": 2385, "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": 143, "parameters": [ "v" ], "start_line": 2388, "end_line": 2413, "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": 124, "parameters": [ "v" ], "start_line": 2416, "end_line": 2438, "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": 124, "parameters": [ "v" ], "start_line": 2441, "end_line": 2463, "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": 124, "parameters": [ "v" ], "start_line": 2466, "end_line": 2488, "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": 2491, "end_line": 2495, "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": 34, "complexity": 11, "token_count": 258, "parameters": [ "self", "ilow", "ihigh" ], "start_line": 2556, "end_line": 2594, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "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": 2598, "end_line": 2619, "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": 4, "complexity": 1, "token_count": 26, "parameters": [ "self", "el" ], "start_line": 2622, "end_line": 2627, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "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": 308, "parameters": [ "string", "n", "max_n", "data", "nd", "dimensions", "strides", "self" ], "start_line": 2648, "end_line": 2695, "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": 222, "parameters": [ "self" ], "start_line": 2698, "end_line": 2734, "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": 2740, "end_line": 2757, "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": 2760, "end_line": 2772, "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": 2775, "end_line": 2787, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "array_richcompare", "long_name": "array_richcompare( PyArrayObject * self , PyObject * other , int cmp_op)", "filename": "arrayobject.c", "nloc": 61, "complexity": 13, "token_count": 273, "parameters": [ "self", "other", "cmp_op" ], "start_line": 2791, "end_line": 2868, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 78, "top_nesting_level": 0 }, { "name": "_check_axis", "long_name": "_check_axis( PyArrayObject * arr , int * axis , int flags)", "filename": "arrayobject.c", "nloc": 29, "complexity": 8, "token_count": 164, "parameters": [ "arr", "axis", "flags" ], "start_line": 2871, "end_line": 2900, "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": 17, "complexity": 4, "token_count": 91, "parameters": [ "len", "vals" ], "start_line": 2906, "end_line": 2922, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "PyArray_IntpFromSequence", "long_name": "PyArray_IntpFromSequence( PyObject * seq , intp * vals , int maxvals)", "filename": "arrayobject.c", "nloc": 21, "complexity": 7, "token_count": 161, "parameters": [ "seq", "vals", "maxvals" ], "start_line": 2927, "end_line": 2950, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "_IsContiguous", "long_name": "_IsContiguous( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 14, "complexity": 6, "token_count": 109, "parameters": [ "ap" ], "start_line": 2956, "end_line": 2972, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_IsFortranContiguous", "long_name": "_IsFortranContiguous( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 14, "complexity": 6, "token_count": 107, "parameters": [ "ap" ], "start_line": 2976, "end_line": 2992, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_IsAligned", "long_name": "_IsAligned( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 14, "complexity": 4, "token_count": 110, "parameters": [ "ap" ], "start_line": 2995, "end_line": 3011, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_IsWriteable", "long_name": "_IsWriteable( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 16, "complexity": 8, "token_count": 109, "parameters": [ "ap" ], "start_line": 3014, "end_line": 3047, "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": 22, "complexity": 9, "token_count": 129, "parameters": [ "ret", "flagmask" ], "start_line": 3051, "end_line": 3073, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "PyArray_CheckStrides", "long_name": "PyArray_CheckStrides( int elsize , int nd , intp numbytes , intp * dims , intp * newstrides)", "filename": "arrayobject.c", "nloc": 13, "complexity": 4, "token_count": 84, "parameters": [ "elsize", "nd", "numbytes", "dims", "newstrides" ], "start_line": 3080, "end_line": 3095, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "_array_fill_strides", "long_name": "_array_fill_strides( intp * strides , intp * dims , int nd , intp itemsize , int inflag , int * objflags)", "filename": "arrayobject.c", "nloc": 24, "complexity": 9, "token_count": 171, "parameters": [ "strides", "dims", "nd", "itemsize", "inflag", "objflags" ], "start_line": 3115, "end_line": 3139, "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 , char * data , int itemsize , int flags , PyObject * obj)", "filename": "arrayobject.c", "nloc": 117, "complexity": 27, "token_count": 713, "parameters": [ "subtype", "nd", "dims", "type_num", "strides", "data", "itemsize", "flags", "obj" ], "start_line": 3143, "end_line": 3293, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 151, "top_nesting_level": 0 }, { "name": "PyArray_Resize", "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape)", "filename": "arrayobject.c", "nloc": 87, "complexity": 15, "token_count": 501, "parameters": [ "self", "newshape" ], "start_line": 3298, "end_line": 3403, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 106, "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": 3408, "end_line": 3425, "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": 47, "complexity": 7, "token_count": 261, "parameters": [ "arr", "obj" ], "start_line": 3428, "end_line": 3480, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "top_nesting_level": 0 }, { "name": "array_new", "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", "filename": "arrayobject.c", "nloc": 100, "complexity": 20, "token_count": 589, "parameters": [ "subtype", "args", "kwds" ], "start_line": 3483, "end_line": 3598, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 116, "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": 3605, "end_line": 3608, "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": 10, "complexity": 3, "token_count": 57, "parameters": [ "self" ], "start_line": 3611, "end_line": 3621, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "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": 3694, "end_line": 3697, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "array_shape_set", "long_name": "array_shape_set( PyArrayObject * self , PyObject * val)", "filename": "arrayobject.c", "nloc": 33, "complexity": 6, "token_count": 206, "parameters": [ "self", "val" ], "start_line": 3701, "end_line": 3735, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "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": 3739, "end_line": 3742, "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": 32, "complexity": 7, "token_count": 209, "parameters": [ "self", "obj" ], "start_line": 3745, "end_line": 3778, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "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": 3782, "end_line": 3789, "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": 3792, "end_line": 3800, "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": 3804, "end_line": 3810, "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": 3813, "end_line": 3827, "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": 3830, "end_line": 3874, "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": 19, "parameters": [ "self" ], "start_line": 3878, "end_line": 3881, "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": 8, "complexity": 3, "token_count": 45, "parameters": [ "self" ], "start_line": 3884, "end_line": 3891, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "array_typechar_get", "long_name": "array_typechar_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 8, "complexity": 2, "token_count": 47, "parameters": [ "self" ], "start_line": 3895, "end_line": 3902, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "array_typestr_get", "long_name": "array_typestr_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 19, "complexity": 7, "token_count": 141, "parameters": [ "self" ], "start_line": 3905, "end_line": 3925, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "array_descr_get", "long_name": "array_descr_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 19, "complexity": 5, "token_count": 128, "parameters": [ "self" ], "start_line": 3928, "end_line": 3950, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "array_type_get", "long_name": "array_type_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 4, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 3954, "end_line": 3957, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "array_type_set", "long_name": "array_type_set( PyArrayObject * self , PyObject * arg)", "filename": "arrayobject.c", "nloc": 41, "complexity": 10, "token_count": 294, "parameters": [ "self", "arg" ], "start_line": 3969, "end_line": 4027, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 59, "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": 4032, "end_line": 4042, "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": 4046, "end_line": 4071, "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": 31, "complexity": 4, "token_count": 177, "parameters": [ "self", "val" ], "start_line": 4075, "end_line": 4107, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "array_imag_get", "long_name": "array_imag_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 34, "complexity": 3, "token_count": 200, "parameters": [ "self" ], "start_line": 4110, "end_line": 4145, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "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": 203, "parameters": [ "self", "val" ], "start_line": 4148, "end_line": 4185, "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": 4188, "end_line": 4191, "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": 51, "complexity": 9, "token_count": 368, "parameters": [ "self", "val" ], "start_line": 4194, "end_line": 4248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 55, "top_nesting_level": 0 }, { "name": "discover_depth", "long_name": "discover_depth( PyObject * s , int max , int stop_at_string)", "filename": "arrayobject.c", "nloc": 23, "complexity": 14, "token_count": 169, "parameters": [ "s", "max", "stop_at_string" ], "start_line": 4423, "end_line": 4448, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "discover_itemsize", "long_name": "discover_itemsize( PyObject * s , int nd , int * itemsize)", "filename": "arrayobject.c", "nloc": 21, "complexity": 9, "token_count": 161, "parameters": [ "s", "nd", "itemsize" ], "start_line": 4451, "end_line": 4473, "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": 4480, "end_line": 4506, "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( int chktype , int mintype , int chksize , int minsize , PyArray_Typecode * outtype)", "filename": "arrayobject.c", "nloc": 19, "complexity": 5, "token_count": 100, "parameters": [ "chktype", "mintype", "chksize", "minsize", "outtype" ], "start_line": 4509, "end_line": 4529, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "_array_find_type", "long_name": "_array_find_type( PyObject * op , PyArray_Typecode * minitype , PyArray_Typecode * outtype , int max)", "filename": "arrayobject.c", "nloc": 126, "complexity": 28, "token_count": 671, "parameters": [ "op", "minitype", "outtype", "max" ], "start_line": 4532, "end_line": 4673, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 142, "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": 4676, "end_line": 4699, "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_Typecode * typecode)", "filename": "arrayobject.c", "nloc": 19, "complexity": 4, "token_count": 120, "parameters": [ "op", "typecode" ], "start_line": 4703, "end_line": 4726, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "Array_FromSequence", "long_name": "Array_FromSequence( PyObject * s , PyArray_Typecode * typecode , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 51, "complexity": 17, "token_count": 313, "parameters": [ "s", "typecode", "min_depth", "max_depth" ], "start_line": 4730, "end_line": 4787, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 58, "top_nesting_level": 0 }, { "name": "PyArray_ValidType", "long_name": "PyArray_ValidType( int type)", "filename": "arrayobject.c", "nloc": 7, "complexity": 2, "token_count": 30, "parameters": [ "type" ], "start_line": 4791, "end_line": 4798, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "_bufferedcast", "long_name": "_bufferedcast( PyArrayObject * out , PyArrayObject * in)", "filename": "arrayobject.c", "nloc": 75, "complexity": 16, "token_count": 477, "parameters": [ "out", "in" ], "start_line": 4804, "end_line": 4894, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 91, "top_nesting_level": 0 }, { "name": "PyArray_Cast", "long_name": "PyArray_Cast( PyArrayObject * mp , int type_num)", "filename": "arrayobject.c", "nloc": 10, "complexity": 1, "token_count": 56, "parameters": [ "mp", "type_num" ], "start_line": 4900, "end_line": 4911, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_CastToType", "long_name": "PyArray_CastToType( PyArrayObject * mp , PyArray_Typecode * at)", "filename": "arrayobject.c", "nloc": 31, "complexity": 13, "token_count": 233, "parameters": [ "mp", "at" ], "start_line": 4914, "end_line": 4949, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "PyArray_CastTo", "long_name": "PyArray_CastTo( PyArrayObject * out , PyArrayObject * mp)", "filename": "arrayobject.c", "nloc": 40, "complexity": 10, "token_count": 214, "parameters": [ "out", "mp" ], "start_line": 4956, "end_line": 5002, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "array_fromarray", "long_name": "array_fromarray( PyArrayObject * arr , PyArray_Typecode * typecode , int flags)", "filename": "arrayobject.c", "nloc": 116, "complexity": 35, "token_count": 725, "parameters": [ "arr", "typecode", "flags" ], "start_line": 5005, "end_line": 5136, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 132, "top_nesting_level": 0 }, { "name": "_array_typecode_fromstr", "long_name": "_array_typecode_fromstr( char * str , int * swap , PyArray_Typecode * type)", "filename": "arrayobject.c", "nloc": 94, "complexity": 36, "token_count": 533, "parameters": [ "str", "swap", "type" ], "start_line": 5140, "end_line": 5245, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 106, "top_nesting_level": 0 }, { "name": "array_frominterface", "long_name": "array_frominterface( PyObject * input , PyArray_Typecode * intype , int flags)", "filename": "arrayobject.c", "nloc": 113, "complexity": 26, "token_count": 715, "parameters": [ "input", "intype", "flags" ], "start_line": 5248, "end_line": 5371, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 124, "top_nesting_level": 0 }, { "name": "array_fromattr", "long_name": "array_fromattr( PyObject * op , PyArray_Typecode * typecode , int flags)", "filename": "arrayobject.c", "nloc": 30, "complexity": 5, "token_count": 181, "parameters": [ "op", "typecode", "flags" ], "start_line": 5374, "end_line": 5405, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "array_fromobject", "long_name": "array_fromobject( PyObject * op , PyArray_Typecode * typecode , int min_depth , int max_depth , int flags)", "filename": "arrayobject.c", "nloc": 49, "complexity": 14, "token_count": 291, "parameters": [ "op", "typecode", "min_depth", "max_depth", "flags" ], "start_line": 5409, "end_line": 5474, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 66, "top_nesting_level": 0 }, { "name": "PyArray_ArrayType", "long_name": "PyArray_ArrayType( PyObject * op , PyArray_Typecode * intype , PyArray_Typecode * outtype)", "filename": "arrayobject.c", "nloc": 6, "complexity": 1, "token_count": 29, "parameters": [ "op", "intype", "outtype" ], "start_line": 5477, "end_line": 5482, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "PyArray_ObjectType", "long_name": "PyArray_ObjectType( PyObject * op , int minimum_type)", "filename": "arrayobject.c", "nloc": 7, "complexity": 1, "token_count": 40, "parameters": [ "op", "minimum_type" ], "start_line": 5485, "end_line": 5491, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "PyArray_FromAny", "long_name": "PyArray_FromAny( PyObject * op , PyArray_Typecode * typecode , int min_depth , int max_depth , int requires)", "filename": "arrayobject.c", "nloc": 24, "complexity": 9, "token_count": 165, "parameters": [ "op", "typecode", "min_depth", "max_depth", "requires" ], "start_line": 5545, "end_line": 5575, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "PyArray_EnsureArray", "long_name": "PyArray_EnsureArray( PyObject * op)", "filename": "arrayobject.c", "nloc": 14, "complexity": 5, "token_count": 87, "parameters": [ "op" ], "start_line": 5586, "end_line": 5602, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "PyArray_FromObject", "long_name": "PyArray_FromObject( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 7, "complexity": 1, "token_count": 51, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5608, "end_line": 5614, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "PyArray_ContiguousFromObject", "long_name": "PyArray_ContiguousFromObject( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 8, "complexity": 1, "token_count": 51, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5617, "end_line": 5624, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_CopyFromObject", "long_name": "PyArray_CopyFromObject( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 8, "complexity": 1, "token_count": 51, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5627, "end_line": 5634, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_ContiguousFromAny", "long_name": "PyArray_ContiguousFromAny( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 8, "complexity": 1, "token_count": 49, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5639, "end_line": 5646, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_CanCastSafely", "long_name": "PyArray_CanCastSafely( int fromtype , int totype)", "filename": "arrayobject.c", "nloc": 81, "complexity": 39, "token_count": 476, "parameters": [ "fromtype", "totype" ], "start_line": 5649, "end_line": 5732, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 84, "top_nesting_level": 0 }, { "name": "PyArray_CanCastTo", "long_name": "PyArray_CanCastTo( PyArray_Typecode * from , PyArray_Typecode * to)", "filename": "arrayobject.c", "nloc": 24, "complexity": 7, "token_count": 134, "parameters": [ "from", "to" ], "start_line": 5735, "end_line": 5759, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 }, { "name": "PyArray_IterNew", "long_name": "PyArray_IterNew( PyObject * obj)", "filename": "arrayobject.c", "nloc": 34, "complexity": 6, "token_count": 258, "parameters": [ "obj" ], "start_line": 5769, "end_line": 5806, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "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": 5811, "end_line": 5821, "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": 6, "complexity": 1, "token_count": 25, "parameters": [ "it" ], "start_line": 5824, "end_line": 5829, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "arrayiter_traverse", "long_name": "arrayiter_traverse( PyArrayIterObject * it , visitproc visit , * arg)", "filename": "arrayobject.c", "nloc": 6, "complexity": 2, "token_count": 42, "parameters": [ "it", "visit", "arg" ], "start_line": 5832, "end_line": 5837, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "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": 5841, "end_line": 5844, "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": 42, "complexity": 7, "token_count": 272, "parameters": [ "self", "ind" ], "start_line": 5848, "end_line": 5896, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "iter_subscript_int", "long_name": "iter_subscript_int( PyArrayIterObject * self , PyArrayObject * ind)", "filename": "arrayobject.c", "nloc": 51, "complexity": 8, "token_count": 347, "parameters": [ "self", "ind" ], "start_line": 5899, "end_line": 5952, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 0 }, { "name": "iter_subscript", "long_name": "iter_subscript( PyArrayIterObject * self , PyObject * ind)", "filename": "arrayobject.c", "nloc": 97, "complexity": 20, "token_count": 593, "parameters": [ "self", "ind" ], "start_line": 5956, "end_line": 6075, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 120, "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": 176, "parameters": [ "self", "ind", "val", "swap" ], "start_line": 6079, "end_line": 6111, "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": 289, "parameters": [ "self", "ind", "val", "swap" ], "start_line": 6114, "end_line": 6156, "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": 103, "complexity": 24, "token_count": 636, "parameters": [ "self", "ind", "val" ], "start_line": 6160, "end_line": 6282, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 123, "top_nesting_level": 0 }, { "name": "iter_array", "long_name": "iter_array( PyArrayIterObject * it , PyObject * op)", "filename": "arrayobject.c", "nloc": 30, "complexity": 5, "token_count": 221, "parameters": [ "it", "op" ], "start_line": 6295, "end_line": 6337, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "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": 6342, "end_line": 6346, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "fancy_indexing_check", "long_name": "fancy_indexing_check( PyObject * args)", "filename": "arrayobject.c", "nloc": 55, "complexity": 22, "token_count": 293, "parameters": [ "args" ], "start_line": 6411, "end_line": 6472, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 62, "top_nesting_level": 0 }, { "name": "_convert_obj", "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", "filename": "arrayobject.c", "nloc": 15, "complexity": 5, "token_count": 105, "parameters": [ "obj", "iter" ], "start_line": 6480, "end_line": 6495, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "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": 6501, "end_line": 6570, "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": 261, "parameters": [ "mit" ], "start_line": 6574, "end_line": 6611, "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": 296, "parameters": [ "mit" ], "start_line": 6617, "end_line": 6661, "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": 102, "complexity": 22, "token_count": 690, "parameters": [ "mit", "arr" ], "start_line": 6679, "end_line": 6815, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 137, "top_nesting_level": 0 }, { "name": "_nonzero_indices", "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", "filename": "arrayobject.c", "nloc": 57, "complexity": 15, "token_count": 454, "parameters": [ "myBool", "iters" ], "start_line": 6821, "end_line": 6890, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 70, "top_nesting_level": 0 }, { "name": "PyArray_MapIterNew", "long_name": "PyArray_MapIterNew( PyObject * indexobj)", "filename": "arrayobject.c", "nloc": 111, "complexity": 24, "token_count": 745, "parameters": [ "indexobj" ], "start_line": 6893, "end_line": 7026, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 134, "top_nesting_level": 0 }, { "name": "arraymapiter_new", "long_name": "arraymapiter_new( PyTypeObject * type , PyObject * args , PyObject * kwds)", "filename": "arrayobject.c", "nloc": 26, "complexity": 5, "token_count": 130, "parameters": [ "type", "args", "kwds" ], "start_line": 7032, "end_line": 7062, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "arraymapiter_dealloc", "long_name": "arraymapiter_dealloc( PyArrayMapIterObject * mit)", "filename": "arrayobject.c", "nloc": 10, "complexity": 2, "token_count": 60, "parameters": [ "mit" ], "start_line": 7083, "end_line": 7092, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "arraymapiter_traverse", "long_name": "arraymapiter_traverse( PyArrayMapIterObject * mit , visitproc visit , * arg)", "filename": "arrayobject.c", "nloc": 16, "complexity": 9, "token_count": 146, "parameters": [ "mit", "visit", "arg" ], "start_line": 7095, "end_line": 7113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 } ], "methods_before": [ { "name": "PyArray_PyIntAsIntp", "long_name": "PyArray_PyIntAsIntp( PyObject * o)", "filename": "arrayobject.c", "nloc": 59, "complexity": 19, "token_count": 385, "parameters": [ "o" ], "start_line": 40, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 64, "top_nesting_level": 0 }, { "name": "PyArray_PyIntAsInt", "long_name": "PyArray_PyIntAsInt( PyObject * o)", "filename": "arrayobject.c", "nloc": 57, "complexity": 19, "token_count": 389, "parameters": [ "o" ], "start_line": 109, "end_line": 169, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 61, "top_nesting_level": 0 }, { "name": "PyArray_GetPriority", "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", "filename": "arrayobject.c", "nloc": 17, "complexity": 5, "token_count": 86, "parameters": [ "obj", "default_" ], "start_line": 173, "end_line": 191, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "PyArray_Zero", "long_name": "PyArray_Zero( PyArrayObject * arr)", "filename": "arrayobject.c", "nloc": 34, "complexity": 6, "token_count": 190, "parameters": [ "arr" ], "start_line": 208, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "PyArray_One", "long_name": "PyArray_One( PyArrayObject * arr)", "filename": "arrayobject.c", "nloc": 40, "complexity": 7, "token_count": 222, "parameters": [ "arr" ], "start_line": 246, "end_line": 289, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "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": 295, "end_line": 345, "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": 368, "end_line": 399, "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": 213, "parameters": [ "src" ], "start_line": 402, "end_line": 436, "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": 449, "end_line": 471, "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": 474, "end_line": 495, "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": 499, "end_line": 537, "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": 542, "end_line": 562, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "index2ptr", "long_name": "index2ptr( PyArrayObject * mp , int i)", "filename": "arrayobject.c", "nloc": 10, "complexity": 7, "token_count": 86, "parameters": [ "mp", "i" ], "start_line": 570, "end_line": 580, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "PyArray_Size", "long_name": "PyArray_Size( PyObject * op)", "filename": "arrayobject.c", "nloc": 9, "complexity": 2, "token_count": 33, "parameters": [ "op" ], "start_line": 583, "end_line": 591, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "PyArray_CopyInto", "long_name": "PyArray_CopyInto( PyArrayObject * dest , PyArrayObject * src)", "filename": "arrayobject.c", "nloc": 71, "complexity": 16, "token_count": 427, "parameters": [ "dest", "src" ], "start_line": 604, "end_line": 684, "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": 16, "complexity": 2, "token_count": 98, "parameters": [ "dest", "src_object" ], "start_line": 688, "end_line": 707, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "PyArray_FromDimsAndDataAndDescr", "long_name": "PyArray_FromDimsAndDataAndDescr( int nd , int * d , PyArray_Descr * descr , char * data)", "filename": "arrayobject.c", "nloc": 15, "complexity": 3, "token_count": 121, "parameters": [ "nd", "d", "descr", "data" ], "start_line": 715, "end_line": 734, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "PyArray_FromDimsAndData", "long_name": "PyArray_FromDimsAndData( int nd , int * d , int type , char * data)", "filename": "arrayobject.c", "nloc": 14, "complexity": 3, "token_count": 112, "parameters": [ "nd", "d", "type", "data" ], "start_line": 738, "end_line": 755, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "PyArray_FromDims", "long_name": "PyArray_FromDims( int nd , int * d , int type)", "filename": "arrayobject.c", "nloc": 14, "complexity": 5, "token_count": 133, "parameters": [ "nd", "d", "type" ], "start_line": 759, "end_line": 776, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "PyArray_Copy", "long_name": "PyArray_Copy( PyArrayObject * m1)", "filename": "arrayobject.c", "nloc": 11, "complexity": 2, "token_count": 77, "parameters": [ "m1" ], "start_line": 782, "end_line": 794, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "PyArray_Scalar", "long_name": "PyArray_Scalar( char * data , int type_num , int itemsize , int swap)", "filename": "arrayobject.c", "nloc": 48, "complexity": 8, "token_count": 289, "parameters": [ "data", "type_num", "itemsize", "swap" ], "start_line": 800, "end_line": 849, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "top_nesting_level": 0 }, { "name": "PyArray_ToScalar", "long_name": "PyArray_ToScalar( char * data , PyArrayObject * arr)", "filename": "arrayobject.c", "nloc": 7, "complexity": 1, "token_count": 51, "parameters": [ "data", "arr" ], "start_line": 856, "end_line": 863, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_Return", "long_name": "PyArray_Return( PyArrayObject * mp)", "filename": "arrayobject.c", "nloc": 17, "complexity": 5, "token_count": 85, "parameters": [ "mp" ], "start_line": 869, "end_line": 888, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "PyArray_RegisterDataType", "long_name": "PyArray_RegisterDataType( PyTypeObject * type)", "filename": "arrayobject.c", "nloc": 31, "complexity": 6, "token_count": 177, "parameters": [ "type" ], "start_line": 899, "end_line": 931, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "PyArray_RegisterDescrForType", "long_name": "PyArray_RegisterDescrForType( int typenum , PyArray_Descr * descr)", "filename": "arrayobject.c", "nloc": 32, "complexity": 3, "token_count": 167, "parameters": [ "typenum", "descr" ], "start_line": 941, "end_line": 984, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "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": 16, "token_count": 577, "parameters": [ "self", "fp", "sep", "format" ], "start_line": 988, "end_line": 1079, "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": 24, "complexity": 5, "token_count": 151, "parameters": [ "self" ], "start_line": 1082, "end_line": 1110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "PyArray_ToString", "long_name": "PyArray_ToString( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 34, "complexity": 6, "token_count": 191, "parameters": [ "self" ], "start_line": 1113, "end_line": 1148, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "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": 1157, "end_line": 1194, "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": 1201, "end_line": 1209, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "array_item", "long_name": "array_item( PyArrayObject * self , int i)", "filename": "arrayobject.c", "nloc": 22, "complexity": 4, "token_count": 150, "parameters": [ "self", "i" ], "start_line": 1213, "end_line": 1237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "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": 26, "parameters": [ "self", "i" ], "start_line": 1240, "end_line": 1243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "array_ass_item", "long_name": "array_ass_item( PyArrayObject * self , int i , PyObject * v)", "filename": "arrayobject.c", "nloc": 27, "complexity": 8, "token_count": 177, "parameters": [ "self", "i", "v" ], "start_line": 1247, "end_line": 1277, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "slice_coerce_index", "long_name": "slice_coerce_index( PyObject * o , int * v)", "filename": "arrayobject.c", "nloc": 9, "complexity": 2, "token_count": 40, "parameters": [ "o", "v" ], "start_line": 1281, "end_line": 1289, "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 , int length , int * start , int * stop , int * step , intp * slicelength)", "filename": "arrayobject.c", "nloc": 45, "complexity": 24, "token_count": 376, "parameters": [ "r", "length", "start", "stop", "step", "slicelength" ], "start_line": 1295, "end_line": 1345, "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 , int * step_size , intp * n_steps , int max)", "filename": "arrayobject.c", "nloc": 45, "complexity": 11, "token_count": 223, "parameters": [ "op", "step_size", "n_steps", "max" ], "start_line": 1352, "end_line": 1397, "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": 89, "complexity": 20, "token_count": 540, "parameters": [ "self", "op", "dimensions", "strides", "offset_ptr" ], "start_line": 1401, "end_line": 1496, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 96, "top_nesting_level": 0 }, { "name": "_swap_axes", "long_name": "_swap_axes( PyArrayMapIterObject * mit , PyArrayObject ** ret)", "filename": "arrayobject.c", "nloc": 24, "complexity": 4, "token_count": 187, "parameters": [ "mit", "ret" ], "start_line": 1499, "end_line": 1533, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "PyArray_GetMap", "long_name": "PyArray_GetMap( PyArrayMapIterObject * mit)", "filename": "arrayobject.c", "nloc": 36, "complexity": 8, "token_count": 252, "parameters": [ "mit" ], "start_line": 1538, "end_line": 1587, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "top_nesting_level": 0 }, { "name": "PyArray_SetMap", "long_name": "PyArray_SetMap( PyArrayMapIterObject * mit , PyObject * op)", "filename": "arrayobject.c", "nloc": 50, "complexity": 12, "token_count": 392, "parameters": [ "mit", "op" ], "start_line": 1590, "end_line": 1649, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 60, "top_nesting_level": 0 }, { "name": "array_subscript", "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", "filename": "arrayobject.c", "nloc": 61, "complexity": 19, "token_count": 425, "parameters": [ "self", "op" ], "start_line": 1670, "end_line": 1745, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 76, "top_nesting_level": 0 }, { "name": "array_ass_sub", "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", "filename": "arrayobject.c", "nloc": 43, "complexity": 9, "token_count": 251, "parameters": [ "self", "index", "op" ], "start_line": 1758, "end_line": 1810, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "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": 1818, "end_line": 1821, "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": 1840, "end_line": 1852, "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": 1855, "end_line": 1870, "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": 1874, "end_line": 1883, "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": 1886, "end_line": 1897, "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": 1965, "end_line": 1998, "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": 2005, "end_line": 2044, "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": 23, "complexity": 5, "token_count": 136, "parameters": [ "m1", "op", "axis", "rtype" ], "start_line": 2047, "end_line": 2069, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "PyArray_GenericAccumulateFunction", "long_name": "PyArray_GenericAccumulateFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", "filename": "arrayobject.c", "nloc": 23, "complexity": 5, "token_count": 136, "parameters": [ "m1", "op", "axis", "rtype" ], "start_line": 2073, "end_line": 2095, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "PyArray_GenericBinaryFunction", "long_name": "PyArray_GenericBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", "filename": "arrayobject.c", "nloc": 12, "complexity": 2, "token_count": 69, "parameters": [ "m1", "m2", "op" ], "start_line": 2099, "end_line": 2110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_GenericUnaryFunction", "long_name": "PyArray_GenericUnaryFunction( PyArrayObject * m1 , PyObject * op)", "filename": "arrayobject.c", "nloc": 12, "complexity": 2, "token_count": 63, "parameters": [ "m1", "op" ], "start_line": 2113, "end_line": 2124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_GenericInplaceBinaryFunction", "long_name": "PyArray_GenericInplaceBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", "filename": "arrayobject.c", "nloc": 13, "complexity": 2, "token_count": 71, "parameters": [ "m1", "m2", "op" ], "start_line": 2127, "end_line": 2139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 2142, "end_line": 2145, "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": 2148, "end_line": 2151, "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": 2154, "end_line": 2157, "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": 2160, "end_line": 2163, "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": 2166, "end_line": 2169, "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": 2172, "end_line": 2175, "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": 2178, "end_line": 2181, "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": 2184, "end_line": 2187, "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": 2190, "end_line": 2193, "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": 2196, "end_line": 2199, "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": 2202, "end_line": 2205, "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": 2208, "end_line": 2211, "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": 2214, "end_line": 2217, "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": 2220, "end_line": 2223, "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": 2226, "end_line": 2229, "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": 2232, "end_line": 2235, "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": 2238, "end_line": 2241, "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": 2244, "end_line": 2247, "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": 2250, "end_line": 2253, "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": 2256, "end_line": 2259, "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": 2262, "end_line": 2265, "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": 2268, "end_line": 2271, "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": 2274, "end_line": 2277, "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": 2280, "end_line": 2283, "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": 2286, "end_line": 2289, "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": 2292, "end_line": 2295, "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": 2298, "end_line": 2301, "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": 2304, "end_line": 2308, "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": 2311, "end_line": 2315, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "array_all_nonzero", "long_name": "array_all_nonzero( PyArrayObject * mp)", "filename": "arrayobject.c", "nloc": 18, "complexity": 4, "token_count": 93, "parameters": [ "mp" ], "start_line": 2319, "end_line": 2337, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "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": 2340, "end_line": 2355, "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": 143, "parameters": [ "v" ], "start_line": 2359, "end_line": 2385, "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": 143, "parameters": [ "v" ], "start_line": 2388, "end_line": 2413, "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": 124, "parameters": [ "v" ], "start_line": 2416, "end_line": 2438, "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": 124, "parameters": [ "v" ], "start_line": 2441, "end_line": 2463, "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": 124, "parameters": [ "v" ], "start_line": 2466, "end_line": 2488, "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": 2491, "end_line": 2495, "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": 34, "complexity": 11, "token_count": 258, "parameters": [ "self", "ilow", "ihigh" ], "start_line": 2556, "end_line": 2594, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "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": 2598, "end_line": 2619, "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": 4, "complexity": 1, "token_count": 26, "parameters": [ "self", "el" ], "start_line": 2622, "end_line": 2627, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "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": 308, "parameters": [ "string", "n", "max_n", "data", "nd", "dimensions", "strides", "self" ], "start_line": 2648, "end_line": 2695, "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": 222, "parameters": [ "self" ], "start_line": 2698, "end_line": 2734, "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": 2740, "end_line": 2757, "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": 2760, "end_line": 2772, "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": 2775, "end_line": 2787, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "array_richcompare", "long_name": "array_richcompare( PyArrayObject * self , PyObject * other , int cmp_op)", "filename": "arrayobject.c", "nloc": 61, "complexity": 13, "token_count": 273, "parameters": [ "self", "other", "cmp_op" ], "start_line": 2791, "end_line": 2868, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 78, "top_nesting_level": 0 }, { "name": "_check_axis", "long_name": "_check_axis( PyArrayObject * arr , int * axis , int flags)", "filename": "arrayobject.c", "nloc": 29, "complexity": 8, "token_count": 164, "parameters": [ "arr", "axis", "flags" ], "start_line": 2871, "end_line": 2900, "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": 17, "complexity": 4, "token_count": 91, "parameters": [ "len", "vals" ], "start_line": 2906, "end_line": 2922, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "PyArray_IntpFromSequence", "long_name": "PyArray_IntpFromSequence( PyObject * seq , intp * vals , int maxvals)", "filename": "arrayobject.c", "nloc": 21, "complexity": 7, "token_count": 161, "parameters": [ "seq", "vals", "maxvals" ], "start_line": 2927, "end_line": 2950, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "_IsContiguous", "long_name": "_IsContiguous( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 14, "complexity": 6, "token_count": 109, "parameters": [ "ap" ], "start_line": 2956, "end_line": 2972, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_IsFortranContiguous", "long_name": "_IsFortranContiguous( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 14, "complexity": 6, "token_count": 107, "parameters": [ "ap" ], "start_line": 2976, "end_line": 2992, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_IsAligned", "long_name": "_IsAligned( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 14, "complexity": 4, "token_count": 110, "parameters": [ "ap" ], "start_line": 2995, "end_line": 3011, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_IsWriteable", "long_name": "_IsWriteable( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 16, "complexity": 8, "token_count": 109, "parameters": [ "ap" ], "start_line": 3014, "end_line": 3047, "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": 22, "complexity": 9, "token_count": 129, "parameters": [ "ret", "flagmask" ], "start_line": 3051, "end_line": 3073, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "PyArray_CheckStrides", "long_name": "PyArray_CheckStrides( int elsize , int nd , intp numbytes , intp * dims , intp * newstrides)", "filename": "arrayobject.c", "nloc": 13, "complexity": 4, "token_count": 84, "parameters": [ "elsize", "nd", "numbytes", "dims", "newstrides" ], "start_line": 3080, "end_line": 3095, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "_array_fill_strides", "long_name": "_array_fill_strides( intp * strides , intp * dims , int nd , intp itemsize , int inflag , int * objflags)", "filename": "arrayobject.c", "nloc": 24, "complexity": 9, "token_count": 171, "parameters": [ "strides", "dims", "nd", "itemsize", "inflag", "objflags" ], "start_line": 3115, "end_line": 3139, "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 , char * data , int itemsize , int flags , PyObject * obj)", "filename": "arrayobject.c", "nloc": 117, "complexity": 27, "token_count": 713, "parameters": [ "subtype", "nd", "dims", "type_num", "strides", "data", "itemsize", "flags", "obj" ], "start_line": 3143, "end_line": 3293, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 151, "top_nesting_level": 0 }, { "name": "PyArray_Resize", "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape)", "filename": "arrayobject.c", "nloc": 87, "complexity": 15, "token_count": 501, "parameters": [ "self", "newshape" ], "start_line": 3298, "end_line": 3403, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 106, "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": 3408, "end_line": 3425, "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": 47, "complexity": 7, "token_count": 261, "parameters": [ "arr", "obj" ], "start_line": 3428, "end_line": 3480, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "top_nesting_level": 0 }, { "name": "array_new", "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", "filename": "arrayobject.c", "nloc": 100, "complexity": 20, "token_count": 589, "parameters": [ "subtype", "args", "kwds" ], "start_line": 3483, "end_line": 3598, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 116, "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": 3605, "end_line": 3608, "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": 10, "complexity": 3, "token_count": 57, "parameters": [ "self" ], "start_line": 3611, "end_line": 3621, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "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": 3694, "end_line": 3697, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "array_shape_set", "long_name": "array_shape_set( PyArrayObject * self , PyObject * val)", "filename": "arrayobject.c", "nloc": 33, "complexity": 6, "token_count": 206, "parameters": [ "self", "val" ], "start_line": 3701, "end_line": 3735, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "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": 3739, "end_line": 3742, "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": 32, "complexity": 7, "token_count": 209, "parameters": [ "self", "obj" ], "start_line": 3745, "end_line": 3778, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "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": 3782, "end_line": 3789, "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": 3792, "end_line": 3800, "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": 3804, "end_line": 3810, "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": 3813, "end_line": 3827, "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": 3830, "end_line": 3874, "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": 19, "parameters": [ "self" ], "start_line": 3878, "end_line": 3881, "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": 8, "complexity": 3, "token_count": 45, "parameters": [ "self" ], "start_line": 3884, "end_line": 3891, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "array_typechar_get", "long_name": "array_typechar_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 8, "complexity": 2, "token_count": 47, "parameters": [ "self" ], "start_line": 3895, "end_line": 3902, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "array_typestr_get", "long_name": "array_typestr_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 19, "complexity": 7, "token_count": 141, "parameters": [ "self" ], "start_line": 3905, "end_line": 3925, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "array_descr_get", "long_name": "array_descr_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 19, "complexity": 5, "token_count": 128, "parameters": [ "self" ], "start_line": 3928, "end_line": 3950, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "array_type_get", "long_name": "array_type_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 4, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 3954, "end_line": 3957, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "array_type_set", "long_name": "array_type_set( PyArrayObject * self , PyObject * arg)", "filename": "arrayobject.c", "nloc": 41, "complexity": 10, "token_count": 294, "parameters": [ "self", "arg" ], "start_line": 3969, "end_line": 4027, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 59, "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": 4032, "end_line": 4042, "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": 4046, "end_line": 4071, "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": 31, "complexity": 4, "token_count": 177, "parameters": [ "self", "val" ], "start_line": 4075, "end_line": 4107, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "array_imag_get", "long_name": "array_imag_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 34, "complexity": 3, "token_count": 200, "parameters": [ "self" ], "start_line": 4110, "end_line": 4145, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "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": 203, "parameters": [ "self", "val" ], "start_line": 4148, "end_line": 4185, "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": 4188, "end_line": 4191, "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": 51, "complexity": 9, "token_count": 368, "parameters": [ "self", "val" ], "start_line": 4194, "end_line": 4248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 55, "top_nesting_level": 0 }, { "name": "discover_depth", "long_name": "discover_depth( PyObject * s , int max , int stop_at_string)", "filename": "arrayobject.c", "nloc": 23, "complexity": 14, "token_count": 169, "parameters": [ "s", "max", "stop_at_string" ], "start_line": 4423, "end_line": 4448, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "discover_itemsize", "long_name": "discover_itemsize( PyObject * s , int nd , int * itemsize)", "filename": "arrayobject.c", "nloc": 21, "complexity": 9, "token_count": 161, "parameters": [ "s", "nd", "itemsize" ], "start_line": 4451, "end_line": 4473, "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": 4480, "end_line": 4506, "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( int chktype , int mintype , int chksize , int minsize , PyArray_Typecode * outtype)", "filename": "arrayobject.c", "nloc": 19, "complexity": 5, "token_count": 100, "parameters": [ "chktype", "mintype", "chksize", "minsize", "outtype" ], "start_line": 4509, "end_line": 4529, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "_array_find_type", "long_name": "_array_find_type( PyObject * op , PyArray_Typecode * minitype , PyArray_Typecode * outtype , int max)", "filename": "arrayobject.c", "nloc": 126, "complexity": 28, "token_count": 671, "parameters": [ "op", "minitype", "outtype", "max" ], "start_line": 4532, "end_line": 4673, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 142, "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": 4676, "end_line": 4699, "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_Typecode * typecode)", "filename": "arrayobject.c", "nloc": 19, "complexity": 4, "token_count": 120, "parameters": [ "op", "typecode" ], "start_line": 4703, "end_line": 4726, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "Array_FromSequence", "long_name": "Array_FromSequence( PyObject * s , PyArray_Typecode * typecode , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 51, "complexity": 17, "token_count": 313, "parameters": [ "s", "typecode", "min_depth", "max_depth" ], "start_line": 4730, "end_line": 4787, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 58, "top_nesting_level": 0 }, { "name": "PyArray_ValidType", "long_name": "PyArray_ValidType( int type)", "filename": "arrayobject.c", "nloc": 7, "complexity": 2, "token_count": 30, "parameters": [ "type" ], "start_line": 4791, "end_line": 4798, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "_bufferedcast", "long_name": "_bufferedcast( PyArrayObject * out , PyArrayObject * in)", "filename": "arrayobject.c", "nloc": 75, "complexity": 16, "token_count": 477, "parameters": [ "out", "in" ], "start_line": 4804, "end_line": 4894, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 91, "top_nesting_level": 0 }, { "name": "PyArray_Cast", "long_name": "PyArray_Cast( PyArrayObject * mp , int type_num)", "filename": "arrayobject.c", "nloc": 10, "complexity": 1, "token_count": 56, "parameters": [ "mp", "type_num" ], "start_line": 4900, "end_line": 4911, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_CastToType", "long_name": "PyArray_CastToType( PyArrayObject * mp , PyArray_Typecode * at)", "filename": "arrayobject.c", "nloc": 31, "complexity": 13, "token_count": 233, "parameters": [ "mp", "at" ], "start_line": 4914, "end_line": 4949, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "PyArray_CastTo", "long_name": "PyArray_CastTo( PyArrayObject * out , PyArrayObject * mp)", "filename": "arrayobject.c", "nloc": 40, "complexity": 10, "token_count": 214, "parameters": [ "out", "mp" ], "start_line": 4956, "end_line": 5002, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "array_fromarray", "long_name": "array_fromarray( PyArrayObject * arr , PyArray_Typecode * typecode , int flags)", "filename": "arrayobject.c", "nloc": 116, "complexity": 35, "token_count": 725, "parameters": [ "arr", "typecode", "flags" ], "start_line": 5005, "end_line": 5136, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 132, "top_nesting_level": 0 }, { "name": "_array_typecode_fromstr", "long_name": "_array_typecode_fromstr( char * str , int * swap , PyArray_Typecode * type)", "filename": "arrayobject.c", "nloc": 94, "complexity": 36, "token_count": 533, "parameters": [ "str", "swap", "type" ], "start_line": 5140, "end_line": 5245, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 106, "top_nesting_level": 0 }, { "name": "array_frominterface", "long_name": "array_frominterface( PyObject * input , PyArray_Typecode * intype , int flags)", "filename": "arrayobject.c", "nloc": 113, "complexity": 26, "token_count": 715, "parameters": [ "input", "intype", "flags" ], "start_line": 5248, "end_line": 5371, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 124, "top_nesting_level": 0 }, { "name": "array_fromattr", "long_name": "array_fromattr( PyObject * op , PyArray_Typecode * typecode , int flags)", "filename": "arrayobject.c", "nloc": 30, "complexity": 5, "token_count": 181, "parameters": [ "op", "typecode", "flags" ], "start_line": 5374, "end_line": 5405, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "array_fromobject", "long_name": "array_fromobject( PyObject * op , PyArray_Typecode * typecode , int min_depth , int max_depth , int flags)", "filename": "arrayobject.c", "nloc": 49, "complexity": 14, "token_count": 291, "parameters": [ "op", "typecode", "min_depth", "max_depth", "flags" ], "start_line": 5409, "end_line": 5474, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 66, "top_nesting_level": 0 }, { "name": "PyArray_ArrayType", "long_name": "PyArray_ArrayType( PyObject * op , PyArray_Typecode * intype , PyArray_Typecode * outtype)", "filename": "arrayobject.c", "nloc": 6, "complexity": 1, "token_count": 29, "parameters": [ "op", "intype", "outtype" ], "start_line": 5477, "end_line": 5482, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "PyArray_ObjectType", "long_name": "PyArray_ObjectType( PyObject * op , int minimum_type)", "filename": "arrayobject.c", "nloc": 7, "complexity": 1, "token_count": 40, "parameters": [ "op", "minimum_type" ], "start_line": 5485, "end_line": 5491, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "PyArray_FromAny", "long_name": "PyArray_FromAny( PyObject * op , PyArray_Typecode * typecode , int min_depth , int max_depth , int requires)", "filename": "arrayobject.c", "nloc": 24, "complexity": 9, "token_count": 165, "parameters": [ "op", "typecode", "min_depth", "max_depth", "requires" ], "start_line": 5545, "end_line": 5575, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "PyArray_EnsureArray", "long_name": "PyArray_EnsureArray( PyObject * op)", "filename": "arrayobject.c", "nloc": 14, "complexity": 5, "token_count": 87, "parameters": [ "op" ], "start_line": 5586, "end_line": 5602, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "PyArray_FromObject", "long_name": "PyArray_FromObject( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 7, "complexity": 1, "token_count": 51, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5608, "end_line": 5614, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "PyArray_ContiguousFromObject", "long_name": "PyArray_ContiguousFromObject( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 8, "complexity": 1, "token_count": 51, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5617, "end_line": 5624, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_CopyFromObject", "long_name": "PyArray_CopyFromObject( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 8, "complexity": 1, "token_count": 51, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5627, "end_line": 5634, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_ContiguousFromAny", "long_name": "PyArray_ContiguousFromAny( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 8, "complexity": 1, "token_count": 49, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5639, "end_line": 5646, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_CanCastSafely", "long_name": "PyArray_CanCastSafely( int fromtype , int totype)", "filename": "arrayobject.c", "nloc": 81, "complexity": 39, "token_count": 476, "parameters": [ "fromtype", "totype" ], "start_line": 5649, "end_line": 5732, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 84, "top_nesting_level": 0 }, { "name": "PyArray_CanCastTo", "long_name": "PyArray_CanCastTo( PyArray_Typecode * from , PyArray_Typecode * to)", "filename": "arrayobject.c", "nloc": 24, "complexity": 7, "token_count": 134, "parameters": [ "from", "to" ], "start_line": 5735, "end_line": 5759, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 }, { "name": "PyArray_IterNew", "long_name": "PyArray_IterNew( PyObject * obj)", "filename": "arrayobject.c", "nloc": 34, "complexity": 6, "token_count": 258, "parameters": [ "obj" ], "start_line": 5769, "end_line": 5806, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "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": 5811, "end_line": 5821, "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": 6, "complexity": 1, "token_count": 25, "parameters": [ "it" ], "start_line": 5824, "end_line": 5829, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "arrayiter_traverse", "long_name": "arrayiter_traverse( PyArrayIterObject * it , visitproc visit , * arg)", "filename": "arrayobject.c", "nloc": 6, "complexity": 2, "token_count": 42, "parameters": [ "it", "visit", "arg" ], "start_line": 5832, "end_line": 5837, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "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": 5841, "end_line": 5844, "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": 42, "complexity": 7, "token_count": 272, "parameters": [ "self", "ind" ], "start_line": 5848, "end_line": 5896, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "iter_subscript_int", "long_name": "iter_subscript_int( PyArrayIterObject * self , PyArrayObject * ind)", "filename": "arrayobject.c", "nloc": 51, "complexity": 8, "token_count": 347, "parameters": [ "self", "ind" ], "start_line": 5899, "end_line": 5952, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 0 }, { "name": "iter_subscript", "long_name": "iter_subscript( PyArrayIterObject * self , PyObject * ind)", "filename": "arrayobject.c", "nloc": 97, "complexity": 20, "token_count": 593, "parameters": [ "self", "ind" ], "start_line": 5956, "end_line": 6075, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 120, "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": 176, "parameters": [ "self", "ind", "val", "swap" ], "start_line": 6079, "end_line": 6111, "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": 289, "parameters": [ "self", "ind", "val", "swap" ], "start_line": 6114, "end_line": 6156, "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": 103, "complexity": 24, "token_count": 636, "parameters": [ "self", "ind", "val" ], "start_line": 6160, "end_line": 6282, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 123, "top_nesting_level": 0 }, { "name": "iter_array", "long_name": "iter_array( PyArrayIterObject * it , PyObject * op)", "filename": "arrayobject.c", "nloc": 30, "complexity": 5, "token_count": 221, "parameters": [ "it", "op" ], "start_line": 6295, "end_line": 6337, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "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": 6342, "end_line": 6346, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "fancy_indexing_check", "long_name": "fancy_indexing_check( PyObject * args)", "filename": "arrayobject.c", "nloc": 55, "complexity": 22, "token_count": 293, "parameters": [ "args" ], "start_line": 6411, "end_line": 6472, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 62, "top_nesting_level": 0 }, { "name": "_convert_obj", "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", "filename": "arrayobject.c", "nloc": 15, "complexity": 5, "token_count": 105, "parameters": [ "obj", "iter" ], "start_line": 6480, "end_line": 6495, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "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": 6501, "end_line": 6570, "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": 261, "parameters": [ "mit" ], "start_line": 6574, "end_line": 6611, "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": 296, "parameters": [ "mit" ], "start_line": 6617, "end_line": 6661, "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": 102, "complexity": 22, "token_count": 690, "parameters": [ "mit", "arr" ], "start_line": 6679, "end_line": 6815, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 137, "top_nesting_level": 0 }, { "name": "_nonzero_indices", "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", "filename": "arrayobject.c", "nloc": 57, "complexity": 15, "token_count": 454, "parameters": [ "myBool", "iters" ], "start_line": 6821, "end_line": 6890, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 70, "top_nesting_level": 0 }, { "name": "PyArray_MapIterNew", "long_name": "PyArray_MapIterNew( PyObject * indexobj)", "filename": "arrayobject.c", "nloc": 111, "complexity": 24, "token_count": 745, "parameters": [ "indexobj" ], "start_line": 6893, "end_line": 7026, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 134, "top_nesting_level": 0 }, { "name": "arraymapiter_new", "long_name": "arraymapiter_new( PyTypeObject * type , PyObject * args , PyObject * kwds)", "filename": "arrayobject.c", "nloc": 26, "complexity": 5, "token_count": 130, "parameters": [ "type", "args", "kwds" ], "start_line": 7032, "end_line": 7062, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "arraymapiter_dealloc", "long_name": "arraymapiter_dealloc( PyArrayMapIterObject * mit)", "filename": "arrayobject.c", "nloc": 10, "complexity": 2, "token_count": 60, "parameters": [ "mit" ], "start_line": 7083, "end_line": 7092, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "arraymapiter_traverse", "long_name": "arraymapiter_traverse( PyArrayMapIterObject * mit , visitproc visit , * arg)", "filename": "arrayobject.c", "nloc": 16, "complexity": 9, "token_count": 146, "parameters": [ "mit", "visit", "arg" ], "start_line": 7095, "end_line": 7113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "PyArray_New", "long_name": "PyArray_New( PyTypeObject * subtype , int nd , intp * dims , int type_num , intp * strides , char * data , int itemsize , int flags , PyObject * obj)", "filename": "arrayobject.c", "nloc": 117, "complexity": 27, "token_count": 713, "parameters": [ "subtype", "nd", "dims", "type_num", "strides", "data", "itemsize", "flags", "obj" ], "start_line": 3143, "end_line": 3293, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 151, "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": 3830, "end_line": 3874, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 45, "top_nesting_level": 0 }, { "name": "PyArray_ToList", "long_name": "PyArray_ToList( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 24, "complexity": 5, "token_count": 151, "parameters": [ "self" ], "start_line": 1082, "end_line": 1110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "array_frominterface", "long_name": "array_frominterface( PyObject * input , PyArray_Typecode * intype , int flags)", "filename": "arrayobject.c", "nloc": 113, "complexity": 26, "token_count": 715, "parameters": [ "input", "intype", "flags" ], "start_line": 5248, "end_line": 5371, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 124, "top_nesting_level": 0 }, { "name": "PyArray_CopyInto", "long_name": "PyArray_CopyInto( PyArrayObject * dest , PyArrayObject * src)", "filename": "arrayobject.c", "nloc": 71, "complexity": 16, "token_count": 427, "parameters": [ "dest", "src" ], "start_line": 604, "end_line": 684, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 81, "top_nesting_level": 0 } ], "nloc": 5641, "complexity": 1232, "token_count": 33717, "diff_parsed": { "added": [ " \"number of elements in destination must be \"\\", " \"integer multiple of number of \"\\", " \"elements in source\");", "\t\t\t\t\t\"array_item not returning smaller-\" \\", "\t\t\t\t\t\"dimensional array\");", "\t\t\t\t\t\"negative dimensions \"\t\\", "\t\t\t\t\t\"are not allowed\");", " \"cannot set UPDATEIFCOPY \" \\", "\t\t\t\t\t\"object does not have single-segment \" \\", "\t\t\t\t\t\"__array_data__ must return \"\t\\", "\t\t\t\t\t\"a 2-tuple with ('data pointer \"\\" ], "deleted": [ " \"destination number of elements must be\"\\", " \"an integer multiple of the source number of\"\\", " \"elements\");", "\t\t\t\t\t\"array_item not returning smaller\" \\", "\t\t\t\t\t\" dimensional array\");", "\t\t\t\t\t\"negative dimensions\"\t\\", "\t\t\t\t\t\" are not allowed\");", " \"cannot set UPDATEIFCOPY\" \\", "\t\t\t\t\t\"object does not have single-segment\" \\", "\t\t\t\t\t\"__array_data__ must return\"\t\\", "\t\t\t\t\t\" a 2-tuple with ('data pointer \"\\" ] } } ] }, { "hash": "3696fd0515c0aa8a144a34e53748f4eee143f15c", "msg": "Fixed default typecode on copy.", "author": { "name": "Travis Oliphant", "email": "oliphant@enthought.com" }, "committer": { "name": "Travis Oliphant", "email": "oliphant@enthought.com" }, "author_date": "2005-10-25T19:53:41+00:00", "author_timezone": 0, "committer_date": "2005-10-25T19:53:41+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "50878542380ce58b3cbdc52edac980eee5d885ce" ], "project_name": "repo_copy", "project_path": "/tmp/tmpn4cqam_6/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": "scipy/base/src/arrayobject.c", "new_path": "scipy/base/src/arrayobject.c", "filename": "arrayobject.c", "extension": "c", "change_type": "MODIFY", "diff": "@@ -5052,7 +5052,7 @@ array_fromarray(PyArrayObject *arr, PyArray_Typecode *typecode, int flags)\n \t\t\t\tPyArray_New(subtype, \n \t\t\t\t\t arr->nd, \n \t\t\t\t\t arr->dimensions,\n-\t\t\t\t\t arr->descr->type_num,\n+\t\t\t\t\t type,\n \t\t\t\t\t NULL, NULL, \n \t\t\t\t\t itemsize,\n \t\t\t\t\t flags & FORTRAN,\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\n/* $Id: arrayobject.c,v 1.59 2005/09/14 00:14:00 teoliphant Exp $ */\n\n/*\n#include \"Python.h\"\n#include \"structmember.h\"\n\n#define _MULTIARRAYMODULE\n#include \"Numeric3/arrayobject.h\"\n*/\n\n/* Helper functions */\n\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\n\nstatic intp\nPyArray_PyIntAsIntp(PyObject *o)\n{\n\tlonglong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr=NULL;\n\tPyArray_Typecode typecode = {PyArray_INTP, 0, 0};\n\tintp ret;\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\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\tarr = PyArray_CastToType((PyArrayObject *)o, &typecode);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tarr = PyArray_FromScalar(o, &typecode);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((intp *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\t\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONGLONG != SIZEOF_PY_INTPTR_T)\n\tif ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C intp\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (intp) long_value;\n}\n\n\nstatic PyObject *array_int(PyArrayObject *v);\n\nstatic int\nPyArray_PyIntAsInt(PyObject *o)\n{\n\tlong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr=NULL;\n\tPyArray_Typecode typecode = {PyArray_INT, 0, 0};\n\tint ret;\n\t\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\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\tarr = PyArray_CastToType((PyArrayObject *)o, &typecode);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tarr = PyArray_FromScalar(o, &typecode);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((int *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONG != SIZEOF_INT)\n\tif ((long_value < INT_MIN) || (long_value > INT_MAX)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C int\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (int) long_value;\n}\n\n\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\nstatic char *\nPyArray_Zero(PyArrayObject *arr)\n{\n char *zeroval;\n char *buf;\n int buf_len;\n PyObject *obj, *ret;\n\n zeroval = PyDataMem_NEW(arr->itemsize);\n if (zeroval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n if (PyArray_ISOBJECT(arr)) {\n obj=PyInt_FromLong((long) 0);\n memcpy(zeroval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return zeroval;\n }\n ret = PyObject_GetAttrString((PyObject *)arr, \"_zero\");\n if (ret != NULL) {\n if (PyObject_AsReadBuffer(ret, (const void **)&buf, \n &buf_len) < 0) {\n PyErr_SetString(PyExc_ValueError, \n \"_zero not returning \" \\\n \"writeable buffer\");\n Py_DECREF(ret);\n return NULL;\n }\n memcpy(zeroval, buf, buf_len);\n Py_DECREF(ret);\n }\n if (PyErr_Occurred()) PyErr_Clear();\n memset(zeroval, 0, arr->itemsize);\n return zeroval;\n}\n\nstatic char *\nPyArray_One(PyArrayObject *arr)\n{\n char *oneval;\n char *buf;\n int buf_len, ret2;\n PyObject *obj, *ret;\n\n oneval = PyDataMem_NEW(arr->itemsize);\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 ret = PyObject_GetAttrString((PyObject *)arr, \"_one\");\n if (ret != NULL) {\n if (PyObject_AsReadBuffer(ret, (const void **)&buf, \n &buf_len) < 0) {\n PyErr_SetString(PyExc_ValueError, \n \"_one not returning \" \\\n \"writeable buffer\");\n Py_DECREF(ret);\n PyDataMem_FREE(oneval);\n return NULL;\n }\n memcpy(oneval, buf, buf_len);\n Py_DECREF(ret);\n }\n if (PyErr_Occurred()) PyErr_Clear();\n\n ret2 = arr->descr->setitem(obj, oneval, arr);\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->itemsize;\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 *)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 { free(new_data); return NULL; }\n}\n\n/* end Helper functions */\n\n\nstatic PyObject *PyArray_New(PyTypeObject *, int nd, intp *, \n int, intp *, char *, 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. */\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/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\n\nstatic char *\nindex2ptr(PyArrayObject *mp, int i) \n{\n\tif (i==0 && (mp->nd == 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\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\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->copyswap;\n\tcopyswapn = dest->descr->copyswapn;\n\n elsize = dest->itemsize;\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->itemsize;\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\tPyArray_Typecode typecode;\n\n\n\ttypecode.type_num = dest->descr->type_num;\n\ttypecode.itemsize = dest->itemsize;\n\ttypecode.fortran = PyArray_ISFORTRAN(dest);\n\t\t\t\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n\t\t\t\t\t &typecode, 0,\n\t\t\t\t\t dest->nd, 0);\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\nstatic PyObject *\nPyArray_FromDimsAndDataAndDescr(int nd, int *d, \n PyArray_Descr *descr,\n char *data) {\n\tPyObject *ret;\n\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\n\tintp newd[MAX_DIMS];\n\t\n\tfor (i=0; itype_num, NULL, data, descr->elsize, \n\t\t\t CARRAY_FLAGS, NULL);\n#else\n\tret = PyArray_New(&PyArray_Type, nd, (intp *)d, \n descr->type_num, NULL, data, descr->elsize, \n\t\t\t CARRAY_FLAGS, NULL);\n#endif\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_FromDimsAndData(int nd, int *d, int type, char *data) \n{\n\tPyObject *ret;\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\t\n\tintp newd[MAX_DIMS];\n\n\tfor (i=0; iob_type, m1->nd, \n\t\t\t\t\t m1->dimensions,\n\t\t\t\t\t m1->descr->type_num,\n\t\t\t\t\t NULL, NULL, m1->itemsize,\n\t\t\t\t\t 0, (PyObject *)m1);\n\t\n if (PyArray_CopyInto(ret, m1) == -1) return NULL;\n\t\n return (PyObject *)ret;\n}\n\n\nstatic PyObject *array_item(PyArrayObject *, int);\n\nstatic PyObject *\nPyArray_Scalar(char *data, int type_num, int itemsize, int swap)\n{\n PyArray_Descr *descr;\n\tPyTypeObject *type;\n\tPyObject *obj;\t\n\tchar *destptr;\n PyArray_CopySwapFunc *copyswap;\n\n descr = PyArray_DescrFromType(type_num);\n if (descr == NULL) return NULL;\n type = descr->typeobj;\n copyswap = descr->copyswap;\n\tif (type_num == PyArray_STRING) \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_ISFLEXIBLE(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 {\n\t\t\tdestptr = PyDataMem_NEW(itemsize);\n\t\t\tif (destptr == NULL) {\n\t\t\t\tPyObject_Del(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tif (type_num == PyArray_UNICODE) {\n\t\t\t\tPyUnicode_AS_UNICODE(obj) = \\\n\t\t\t\t\t(Py_UNICODE *)destptr;\n\t\t\t\t((PyUnicodeObject*)obj)->length = itemsize / \\\n\t\t\t\t\tsizeof(Py_UNICODE);\n\t\t\t\t((PyUnicodeObject*)obj)->hash = -1;\n\t\t\t}\n\t\t\telse {\n\t\t\t\t((PyVoidScalarObject *)obj)->obval = destptr;\n\t\t\t\t((PyVoidScalarObject *)obj)->ob_size = itemsize;\n\t\t\t}\n\t\t}\n\t}\n\telse {\n\t\tdestptr = &(((PyScalarObject*)obj)->obval);\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*/\nstatic PyObject *\nPyArray_ToScalar(char *data, PyArrayObject *arr)\n{\n\tint type_num = arr->descr->type_num;\n\tint itemsize = arr->itemsize;\n int swap = !(PyArray_ISNOTSWAPPED(arr));\n\n\treturn PyArray_Scalar(data, type_num, itemsize, swap);\n}\n\n\n/* Return Python scalar if 0-d array object is encountered */\n\nstatic PyObject *\nPyArray_Return(PyArrayObject *mp) \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((PyObject *)mp) && 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*/\nstatic int \nPyArray_RegisterDataType(PyTypeObject *type)\n{\n\tPyArray_Descr *descr;\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 = malloc(sizeof(PyArray_Descr));\n\tmemcpy(descr, PyArray_DescrFromType(PyArray_VOID), \n\t sizeof(PyArray_Descr));\n\ttypenum = PyArray_USERDEF + PyArray_NUMUSERTYPES;\n\tdescr->type_num = typenum;\n\tdescr->typeobj = 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 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 frees the copy of the Descr_table already there.\n places a pointer to the new one into the slot.\n*/\nstatic int\nPyArray_RegisterDescrForType(int typenum, PyArray_Descr *descr)\n{\n\tPyArray_Descr *old;\n\tint i;\n\n\tif (!PyTypeNum_ISUSERDEF(typenum)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"data type not registered\");\n\t\treturn -1;\n\t}\n\told = userdescrs[typenum-PyArray_USERDEF];\n\tdescr->typeobj = old->typeobj;\n\tdescr->type_num = typenum;\n\n#define _NULL_CHECK(member) \\\n\tif (descr->member == NULL) descr->member = old->member\n\n\tfor (i=0; imember == 0) descr->member = old->member\n\n\t_ZERO_CHECK(kind);\n\t_ZERO_CHECK(type);\n\t_ZERO_CHECK(elsize);\n\t_ZERO_CHECK(alignment);\n#undef _ZERO_CHECK\n\n\tfree(old);\n\tuserdescrs[typenum-PyArray_USERDEF] = descr;\n\treturn 0;\n}\n\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 n3 = strlen((const char *)sep);\n if (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 \"\\\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->itemsize,\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->itemsize,\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 = strlen((const char *)format);\n while(it->index < it->size) {\n obj = self->descr->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\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->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\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 if (PyArray_TYPE(self) == PyArray_OBJECT) {\n PyErr_SetString(PyExc_ValueError, \"a string for the data\"\\\n\t\t\t\t\"in an object array is not appropriate\");\n return NULL;\n }\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->itemsize;\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 != NULL)) {\n\t\t/* Free internal references if an Object array */\n\t\tPyArray_XDECREF(self);\n\n PyDataMem_FREE(self->data);\n }\n\t\n if (self->dimensions != NULL) {\n PyDimMem_FREE(self->dimensions); \n\t}\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\n\nstatic PyObject *\narray_item(PyArrayObject *self, int i) \n{\n char *item;\n PyArrayObject *r;\n\n\n\tif(self->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n if ((item = index2ptr(self, i)) == NULL) return NULL;\n\n\tr = (PyArrayObject *)PyArray_New(self->ob_type, \n\t\t\t\t\t self->nd-1, self->dimensions+1, \n\t\t\t\t\t self->descr->type_num, \n\t\t\t\t\t self->strides+1, item, \n\t\t\t\t\t self->itemsize, self->flags,\n\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_item(self, i));\n}\n\n\nstatic int \narray_ass_item(PyArrayObject *self, int 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\n if (i < 0) i = i+self->dimensions[0];\n\n if (self->nd > 1) {\n if((tmp = (PyArrayObject *)array_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->setitem(v, item, self) == -1) return -1;\n return 0;\n}\n\n/* -------------------------------------------------------------- */\nstatic int\nslice_coerce_index(PyObject *o, int *v)\n{\n\t*v = PyArray_PyIntAsInt(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, int length,\n int *start, int *stop, int *step,\n intp *slicelength)\n{\n\tint 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 int\nparse_subindex(PyObject *op, int *step_size, intp *n_steps, int max)\n{\n\tint 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\tint 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_PyIntAsInt(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, start, offset, n_add, n_pseudo;\n int step_size;\n\tintp n_steps;\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, *tup;\n\tint n1, n2, n3, val;\n\tint i;\n\n\ttup = PyTuple_New(mit->nd);\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\tPyTuple_SET_ITEM(tup, i++, PyInt_FromLong((long)val++));\n\tval = 0;\n\twhile(val < n1)\n\t\tPyTuple_SET_ITEM(tup, i++, PyInt_FromLong((long)val++));\n\tval = n1+n2;\n\twhile(val < n3)\n\t\tPyTuple_SET_ITEM(tup, i++, PyInt_FromLong((long)val++));\n\n\tnew = PyArray_Transpose(*ret, tup);\n\tPy_DECREF(tup);\n\tPy_DECREF(*ret);\n\t*ret = (PyArrayObject *)new;\n}\n\n\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\tret = (PyArrayObject *)\\\n\t\tPyArray_New(temp->ob_type, mit->nd, mit->dimensions, \n\t\t\t temp->descr->type_num, NULL, NULL, \n\t\t\t temp->itemsize, \n\t\t\t PyArray_ISFORTRAN(temp),\n\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\treturn NULL;\n\tindex = it->size;\n\tswap = ((temp->flags & NOTSWAPPED) != (ret->flags & NOTSWAPPED));\n copyswap = ret->descr->copyswap;\n\tPyArray_MapIterReset(mit);\n\twhile (index--) {\n copyswap(it->dataptr, mit->dataptr, swap, ret->itemsize);\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\tPyArray_Typecode typecode = {0, 0, 0};\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Unbound Map Iterator */\n\tif (mit->ait == NULL) return -1;\n\n\ttypecode.type_num = mit->ait->ao->descr->type_num;\n\ttypecode.itemsize = mit->ait->ao->itemsize;\n\n\tarr = PyArray_FromAny(op, &typecode, \n\t\t\t 0, 0, FORCECAST);\n\tif (arr == NULL) return -1;\n\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, (PyArrayObject **)&arr);\n\t\t}\n\t}\n\t\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) \n\t\treturn -1;\n\n\tindex = mit->size;\n\tswap = ((mit->ait->ao->flags & NOTSWAPPED) != \\\n\t\t(PyArray_FLAGS(arr) & NOTSWAPPED));\n\n copyswap = PyArray_DESCR(arr)->copyswap;\n\tPyArray_MapIterReset(mit);\n /* Need to decref OBJECT arrays */\n if (PyTypeNum_ISOBJECT(typecode.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 copyswap(mit->dataptr, NULL, swap, \n sizeof(PyObject *));\n PyArray_MapIterNext(mit);\n PyArray_ITER_NEXT(it);\n if (it->index == it->size)\n PyArray_ITER_RESET(it);\n }\n return 0;\n }\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\treturn 0;\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 0-dimensional arrays */\n\nstatic PyObject *\narray_subscript(PyArrayObject *self, PyObject *op) \n{\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n\tintp offset;\n int nd, i;\n PyArrayObject *other;\n\tPyArrayMapIterObject *mit;\n\n if (PyArray_IsScalar(op, Integer) || PyInt_Check(op) || \\\n PyLong_Check(op)) {\n intp value;\n value = PyArray_PyIntAsIntp(op);\n if (PyErr_Occurred())\n PyErr_Clear();\n else if (value >= 0) {\n if (value <= MAX_INT)\n return array_item(self, (int) value);\n }\n else if (value < 0) {\n if (value >= -MAX_INT) {\n if (self->nd > 0) value += self->dimensions[0];\n return array_item(self, (int) value);\n }\n }\n }\n\n\tif (PyArrayMapIter_Check(op)) {\n\t\tmit = (PyArrayMapIterObject *)op;\n\t\t/* bind to current array */\n\t\tPyArray_MapIterBind(mit, self);\n\t\t\n\t\t/* If the mapiterator was created with standard indexing\n\t\t behavior, fall through to view-based code */\n\t\tif (!mit->view) return PyArray_GetMap(mit);\n\t\top = mit->indexobj;\n\t}\n\telse { /* wrap arguments into a mapiter object */\n\t\tmit = (PyArrayMapIterObject *)PyArray_MapIterNew(op);\n\t\tif (mit == NULL) return NULL;\n\t\tif (!mit->view) { /* fancy indexing */\n\t\t\tPyArray_MapIterBind(mit, self);\n\t\t\tother = (PyArrayObject *)PyArray_GetMap(mit);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn (PyObject *)other;\n\t\t}\n\t\tPy_DECREF(mit);\n\t}\n\n\ti = PyArray_PyIntAsInt(op);\n\tif (!error_converting(i)) {\n\t\tif (i < 0 && self->nd > 0) i = i+self->dimensions[0];\n\t\treturn array_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\tif ((other = (PyArrayObject *)\t\t\t\t\t\\\n\t PyArray_New(self->ob_type, nd, dimensions, self->descr->type_num,\n\t\t\t strides, self->data+offset, \n\t\t\t self->itemsize, self->flags,\n\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 \narray_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op) \n{\n int ret, 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\n\tif (PyArrayMapIter_Check(index)) {\n\t\tmit = (PyArrayMapIterObject *)index;\n\t\t/* bind behavior to current array */\n\t\tPyArray_MapIterBind(mit, self);\n\t\t\t\n\t\t/* fall through if standard view-based map iterator */\n\t\tif (!mit->view) return PyArray_SetMap(mit, op);\n\t\tindex = mit->indexobj;\n\t}\n\telse {\n\t\tmit = (PyArrayMapIterObject *)PyArray_MapIterNew(index);\n\t\tif (mit == NULL) return -1;\n\t\tif (!mit->view) {\n\t\t\tPyArray_MapIterBind(mit, self);\n\t\t\tret = PyArray_SetMap(mit, op);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn ret;\n\t\t}\n\t\tPy_DECREF((PyObject*)mit);\n\t}\n\n\ti = PyArray_PyIntAsInt(index);\n\tif (!error_converting(i)) {\n\t\treturn array_ass_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 ret = PyArray_CopyObject(tmp, op);\n Py_DECREF(tmp);\n\t\n return ret;\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 \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\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}\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}\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 PyObject *args, *ret;\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n args = Py_BuildValue(\"(OO)\", m1, m2);\n ret = PyObject_Call(op, args, NULL);\n Py_DECREF(args);\n return ret;\n}\n\nstatic PyObject *\nPyArray_GenericUnaryFunction(PyArrayObject *m1, PyObject *op) \n{\n PyObject *args, *ret;\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n args = Py_BuildValue(\"(O)\", m1);\n ret = PyObject_Call(op, args, NULL);\n Py_DECREF(args);\n return ret;\n}\n\nstatic PyObject *\nPyArray_GenericInplaceBinaryFunction(PyArrayObject *m1, \n\t\t\t\t PyObject *m2, PyObject *op) \n{\n PyObject *args, *ret;\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n args = Py_BuildValue(\"(OOO)\", m1, m2, m1);\n ret = PyObject_Call(op, args, NULL);\n Py_DECREF(args);\n return ret;\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_all_nonzero(PyArrayObject *mp) \n{\n\tintp index;\n\tPyArrayIterObject *it;\n\tBool anyTRUE = 0;\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->nonzero(it->dataptr, mp)) {\n\t\t\tanyTRUE = 1;\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 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->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->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->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->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->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_all_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 r = (PyArrayObject *)\\\n\t\tPyArray_New(self->ob_type, self->nd, self->dimensions, \n\t\t\t self->descr->type_num, self->strides, data,\n\t\t\t self->itemsize, 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 any(self == el) */\n\n return PyObject_RichCompareBool((PyObject *)self, el, Py_EQ);\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 *)realloc(*string, *max_n); }\n\t\n if (nd == 0) {\n\t\t\n if ((op = descr->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\tfree(string); return NULL; \n\t}\n\t\n\tif (PyArray_ISFLEXIBLE(self)) {\n\t\tchar buf[100];\n\t\tsnprintf(buf, sizeof(buf), \"%d\", self->itemsize);\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 free(string);\n return ret;\n}\n\nstatic PyObject *PyArray_StrFunction=NULL;\nstatic PyObject *PyArray_ReprFunction=NULL;\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\n\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) \n{\n PyObject *array_other, *result;\n\n switch (cmp_op) \n {\n case Py_LT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less);\n case Py_LE:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less_equal);\n case Py_EQ:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then return the integer\n\t\t\t object 0. This fixes code that used to\n\t\t\t allow equality comparisons between arrays\n\t\t\t and other objects which would give a result\n\t\t\t of 0\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n result = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.equal);\n /* If the comparison results in NULL, then the \n\t\t\t two array objects can not be compared together so \n\t\t\t return zero \n */\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n return result;\n case Py_NE:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then objects cannot be \n\t\t\t compared and cannot be equal, therefore, \n\t\t\t return True;\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n result = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.not_equal);\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n return result;\n case Py_GT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.greater);\n case Py_GE:\n return PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t other, \n\t\t\t\t\t \t n_ops.greater_equal);\n }\n return NULL;\n}\n\nstatic PyObject *\n_check_axis(PyArrayObject *arr, int *axis, int flags)\n{\n\tPyObject *temp;\n\tint n = arr->nd;\n\n\tif ((*axis >= MAX_DIMS) || (n==0)) {\n\t\ttemp = PyArray_Ravel(arr,0);\n\t\t*axis = 0;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_FromAny((PyObject *)arr, NULL, \n\t\t\t\t\t 0, 0, flags);\n\t\t\tif (temp == NULL) return NULL;\n\t\t}\n\t\telse {\n\t\t\tPy_INCREF(arr);\n\t\t\ttemp = (PyObject *)arr;\n\t\t}\n\t}\n\tif (*axis < 0) *axis += n;\n\tif ((*axis < 0) || (*axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", *axis);\n\t\tPy_DECREF(temp);\n\t\treturn NULL;\n\t}\n\treturn temp;\n}\n\n#include \"arraymethods.c\"\n\n/* Lifted from numarray */\nstatic PyObject *\nPyArray_IntTupleFromIntp(int len, intp *vals)\n{\n\tint i;\n PyObject *intTuple = PyTuple_New(len);\n if (!intTuple) goto fail;\n for(i=0; ind == 0) return 1;\n\tsd = ap->itemsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\n\t}\n\treturn 1;\n}\n\n\nstatic int \n_IsFortranContiguous(PyArrayObject *ap) \n{\n\tint sd;\n\tint i;\n\t\n\tif (ap->nd == 0) return 1;\n\tsd = ap->itemsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i=0; i< ap->nd; ++i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\n\t}\n\treturn 1;\n}\n\nstatic int\n_IsAligned(PyArrayObject *ap) \n{\n\tint i, alignment, aligned=1;\n\tintp ptr;\n\tint type = ap->descr->type_num;\n\n\tif ((type == PyArray_STRING) || (type == PyArray_VOID))\n\t\treturn 1;\n\n\talignment = ap->descr->alignment;\n\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\tPyBufferProcs *pb;\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\tpb = base->ob_type->tp_as_buffer;\n\tif (pb == NULL || pb->bf_getwritebuffer == NULL)\n\t\treturn FALSE;\n\t\n\treturn TRUE;\n}\n\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\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not \n walk outside of the memory implied by either numbytes or\n a single segment array of the provided dimensions and element size if\n numbytes is 0 */\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, \n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\t\n\tif (numbytes == 0) \n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\t\n\tfor (i=0; i numbytes) {\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\treturn TRUE;\n\t\n}\n\n\n/* This is the main array creation routine. */\n\n/* Flags argument has multiple related meanings \n depending on data and strides: \n\n If data is given, then flags is flags associated with data. \n If strides is not given, then a contiguous strides array will be created\n and the CONTIGUOUS bit will be set. If the flags argument \n has the FORTRAN bit set, then a FORTRAN-style strides array will be\n created (and of course the FORTRAN flag bit will be set). \n\n If data is not given but created here, then flags will be DEFAULT_FLAGS\n and a non-zero flags argument can be used to indicate a FORTRAN style\n array is desired. \n*/\n\nstatic intp\n_array_fill_strides(intp *strides, intp *dims, int nd, intp itemsize, \n\t\t int inflag, int *objflags) \n{\n\tint i;\n\t/* Only make Fortran strides if not contiguous as well */\n\tif ((inflag & FORTRAN) && !(inflag & CONTIGUOUS)) {\n\t\tfor (i=0; i 1) *objflags &= ~CONTIGUOUS;\n\t\telse *objflags |= CONTIGUOUS;\n\t}\n\telse {\n\t\tfor (i=nd-1;i>=0;i--) {\n\t\t\tstrides[i] = itemsize;\n\t\t\titemsize *= dims[i] ? dims[i] : 1;\n\t\t}\n\t\t*objflags |= CONTIGUOUS;\n\t\tif (nd > 1) *objflags &= ~FORTRAN;\n\t\telse *objflags |= FORTRAN;\n\t}\n\treturn itemsize;\n}\n\n\t\nstatic PyObject *\nPyArray_New(PyTypeObject *subtype, int nd, intp *dims, int type_num,\n intp *strides, char *data, int itemsize, int flags,\n\t PyObject *obj)\n{\n\tPyArrayObject *self;\n\tPyArray_Descr *descr;\n\tregister int i;\n\tintp sd, temp=-1;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\tif (descr == NULL) return NULL;\n\n\tif (nd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"number of dimensions must be >=0\");\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 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\treturn NULL;\n\t\t}\n\t}\n\t\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) return NULL;\t\n\tself->descr = descr;\n\tself->dimensions = 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\n\tif (PyTypeNum_ISFLEXIBLE(type_num)) {\n\t\tif (itemsize < 1) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"type must provide an itemsize\");\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn NULL;\n\t\t}\n\t\tself->itemsize = itemsize;\n\t\t/* Guarantee that these kind of arrays are never byteswapped\n\t\t unknowingly. \n\t\t*/\n\t\tif (type_num != PyArray_UNICODE)\n\t\t\tself->flags |= NOTSWAPPED;\n\t}\n\telse self->itemsize = descr->elsize; \n\t\t\n\tsd = self->itemsize;\n\t\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn PyErr_NoMemory();\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\tPyDimMem_FREE(self->dimensions);\n\t\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\t\treturn NULL;\n\t\t\t}\t\t\t\t\n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t}\n \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 (a.data) doesn't work\n\t\t as it should. */\n\n\t\tif (sd==0) sd = sizeof(intp);\n\n\t\tif ((data = PyDataMem_NEW(sd))==NULL) {\n\t\t\tPyDimMem_FREE(self->dimensions);\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn PyErr_NoMemory();\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\n\t\t/* It is bad to have unitialized OBJECT pointers */\n\t\t/* We shouldn't need to check for the OBJECT Letter\n\t\t but perhaps it's best. */\n\t\tif (type_num == PyArray_OBJECT || \\\n\t\t type_num == PyArray_OBJECTLTR) {\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\tself->nd = nd;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\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;\n\t\tif (temp==-1) { /* 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\tres = PyObject_CallMethod((PyObject *)self, \n\t\t\t\t\t \"__array_finalize__\",\n\t\t\t\t\t \"O\", obj);\n\t\tif (res == NULL) {\n\t\t\tPyDimMem_FREE(self->dimensions);\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn NULL;\n\t\t}\n\t\telse Py_DECREF(res);\n\t}\n\n\treturn (PyObject *)self;\n}\n\n\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\n newsize = PyArray_MultiplyList(new_dimensions, new_nd);\n\n if (newsize == 0) {\n PyErr_SetString(PyExc_ValueError, \n \"newsize is zero; cannot delete an array \"\\\n \"in this way\");\n return NULL;\n }\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 = (((PyObject *)self)->ob_refcnt);\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\n\t\t/* Reallocate space if needed */\n\t\tnew_data = PyDataMem_RENEW(self->data, \n\t\t\t\t\t newsize*(self->itemsize));\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->itemsize;\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->itemsize;\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 */\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; idataptr, fromptr, itemsize);\n\t\t\tPyArray_ITER_NEXT(iter);\n\t\t}\n\n\t\tPy_DECREF(iter);\n\t\tPy_DECREF(behaved);\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\", \"strides\", \n \"swap\", \"fortran\", NULL};\n\tint itemsize = 0;\n\tPyArray_Typecode typecode = {PyArray_NOTYPE, 0, 0};\n\tint type_num = PyArray_NOTYPE;\n PyArray_Dims dims = {NULL, 0};\n PyArray_Dims strides = {NULL, 0};\n PyArray_Chunk buffer;\n\tint fortran = 0;\n int swapped = 0;\n\tPyArrayObject *ret;\n\n\tbuffer.ptr = NULL; \n /* Usually called with shape and type\n but can also be called with buffer, strides, and swapped info\n */\n\n\t/* For now, let's just use this to create an empty, contiguous \n\t array of a specific type and shape. \n\t*/\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&O&ii\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &dims, \n PyArray_TypecodeConverter,\n\t\t\t\t\t &typecode, \n PyArray_BufferConverter,\n &buffer,\n &PyArray_IntpConverter, \n &strides,\n &swapped, &fortran)) \n\t\treturn NULL;\n\t\n if (typecode.type_num ==PyArray_NOTYPE) {\n\t\ttypecode.type_num = PyArray_DOUBLE;\n\t\ttypecode.itemsize = sizeof(double);\n\t}\n\ttype_num = typecode.type_num;\n\titemsize = typecode.itemsize;\n\n\n if (dims.ptr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"need to give a \"\\\n \"valid shape as the first argument\");\n goto fail;\n }\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)PyArray_New(subtype, (int)dims.len, \n dims.ptr, type_num,\n NULL, NULL, itemsize, \n fortran, NULL);\n \n if (ret == NULL) goto fail;\n if (type_num == PyArray_OBJECT) { /* place Py_None */\n PyArray_FillObjectArray(ret, Py_None);\n }\n }\n else { /* buffer given -- use it */\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = buffer.len / itemsize;\n }\n else if (buffer.len < itemsize* \\\n PyArray_MultiplyList(dims.ptr, dims.len)) {\n PyErr_SetString(PyExc_TypeError, \n \"buffer is too small for \" \\\n \"requested array\");\n goto fail;\n }\n if (strides.ptr != NULL) {\n\t\t\tif (strides.len != dims.len) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides, if given, must be \"\\\n\t\t\t\t\t\t\"the same length as shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CheckStrides(itemsize, strides.len, \n\t\t\t\t\t\t buffer.len,\n\t\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides is incompatible \"\\\n\t\t\t\t\t\t\"with shape of requested\"\\\n\t\t\t\t\t\t\"array and size of buffer\");\n\t\t\t\tgoto fail;\n\t\t\t}\n }\n if (type_num == PyArray_OBJECT) {\n PyErr_SetString(PyExc_TypeError, \"cannot construct \"\\\n \"an object array from buffer data\");\n goto fail;\n }\n /* get writeable and aligned */\n if (fortran) buffer.flags |= FORTRAN;\n if (!(swapped)) buffer.flags |= NOTSWAPPED;\n ret = (PyArrayObject *)PyArray_New(subtype, dims.len, \n dims.ptr, type_num,\n strides.ptr,\n (char *)buffer.ptr, \n itemsize, \n buffer.flags, NULL); \n if (ret == 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 PyArray_Return(ret);\n \n fail:\n if (dims.ptr) PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return NULL;\n}\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 static PyObject *module=NULL;\n\n if (module==NULL) {\n module = PyImport_ImportModule(\"scipy.base._internal\");\n if (module == NULL) return NULL;\n }\n return PyObject_CallMethod(module, \"flagsobj\", \"Oii\", \n self, self->flags, 0);\n}\n\n/*\nstatic int\narray_flags_set(PyArrayObject *self, PyObject *obj) \n{\n\tint flagback = self->flags;\n\n if (PyDict_Check(obj)) {\n PyObject *new;\n\t\tnew = PyDict_GetItemString(obj, \"ALIGNED\");\n\t\tif (new) {\n\t\t\tif (PyObject_Not(new)) self->flags &= ~ALIGNED;\n\t\t\telse if (_IsAligned(self)) self->flags |= ALIGNED;\n\t\t\telse {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"cannot set aligned flag of \" \\\n\t\t\t\t\t\t\"mis-aligned array to True\");\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t}\n new = PyDict_GetItemString(obj, \"UPDATEIFCOPY\");\n if (new) {\n if (PyObject_Not(new)) {\n self->flags &= ~UPDATEIFCOPY;\n Py_DECREF(self->base);\n self->base = NULL;\n }\n else {\n\t\t\t\tself->flags = flagback;\n PyErr_SetString(PyExc_ValueError, \n \"cannot set UPDATEIFCOPY \" \\\n \"flag to True\");\n return -1;\n }\n }\n new = PyDict_GetItemString(obj, \"WRITEABLE\");\n if (new) {\n\t\t\tif (PyObject_IsTrue(new)) {\n\t\t\t\tif (_IsWriteable(self)) {\n\t\t\t\t\tself->flags |= WRITEABLE;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tself->flags = flagback;\n\t\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\t\"cannot set \"\t\\\n\t\t\t\t\t\t\t\"WRITEABLE \"\t\\\n\t\t\t\t\t\t\t\"flag to True of \"\\\n\t\t\t\t\t\t\t\"this array \");\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n else\n self->flags &= ~WRITEABLE;\n }\n new = PyDict_GetItemString(obj, \"NOTSWAPPED\");\n if (new) {\n if (PyObject_IsTrue(new))\n self->flags |= NOTSWAPPED;\n else {\n self->flags &= ~NOTSWAPPED;\n\t\t\t}\n\t\t}\n return 0;\n }\n PyErr_SetString(PyExc_ValueError, \n \"object must be a dictionary\");\n return -1;\n}\n*/\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\tif (!PyTuple_Check(val)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"shape must be a tuple\");\n\t\treturn -1;\n\t}\n\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\n\t\n\tif (self->nd > 0) { /* Free old dimensions and strides */\n\t\tPyDimMem_FREE(self->dimensions);\n\t}\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;\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\treturn -1;\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->itemsize;\n\t\n\tif (!PyArray_CheckStrides(self->itemsize, self->nd, numbytes, \n\t\t\t\t self->dimensions, newstrides.ptr)) {\n\t\tPyErr_SetString(PyExc_ValueError, \"strides is not \"\\\n\t\t\t\t\"compatible with available memory\");\n\t\treturn -1;\n\t}\n\tmemcpy(self->strides, newstrides.ptr, sizeof(intp)*newstrides.len);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\treturn 0;\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->itemsize);\n}\n\nstatic PyObject *\narray_size_get(PyArrayObject *self)\n{\n\tlonglong size=PyArray_SIZE(self);\n\tif (size > MAX_INT || size < MIN_INT)\n\t\treturn PyLong_FromLongLong((longlong) size);\n\telse \n\t\treturn PyInt_FromLong((long) size);\n}\n\n\nstatic PyObject *\narray_typechar_get(PyArrayObject *self)\n{\n\tif PyArray_ISFLEXIBLE(self) \n\t\treturn PyString_FromFormat(\"%c%d\", (self->descr->type),\n\t\t\t\t\t self->itemsize);\n\telse \n\t\treturn PyString_FromStringAndSize(&(self->descr->type), 1);\n}\n\nstatic PyObject *\narray_typestr_get(PyArrayObject *self)\n{\n\tstatic char endians[] = \"<>\";\n\tchar endian;\n\tint which;\n\tunsigned long val = 1;\n\tchar *s;\n\tchar basic_=self->descr->kind;\n\n\ts = (char *)&val; /* s[0] == 0 implies big-endian */\n\twhich = (PyArray_ISNOTSWAPPED(self) ? 0 : 1);\n\tif (s[0] == 0) which = 1 - which;\n\tendian = endians[which]; \n\t\n\tif ((basic_==PyArray_VOIDLTR) || (basic_==PyArray_STRINGLTR) || \\\n\t (basic_==PyArray_OBJECTLTR) || (self->itemsize == 1))\n\t\treturn PyString_FromFormat(\"|%c%d\", basic_, self->itemsize);\n\telse\n\t\treturn PyString_FromFormat(\"%c%c%d\", endian, basic_,\n\t\t\t\t\t self->itemsize);\n}\n\nstatic PyObject *\narray_descr_get(PyArrayObject *self)\n{\n\tPyObject *res;\n\tPyObject *dobj;\n\n\t/* hand this off to the typeobject */\n\t/* or give default */\n\tif (PyArray_ISUSERDEF(self)) {\n\t\tres = PyObject_GetAttrString((PyObject *)self->descr->typeobj, \n\t\t\t\t\t \"__array_descr__\");\n\t\tif (res) return res;\n\t\tPyErr_Clear();\n\t}\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\n\nstatic PyObject *\narray_type_get(PyArrayObject *self)\n{\n\treturn PyArray_TypeObjectFromType(self->descr->type_num);\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*/\n\nstatic int\narray_type_set(PyArrayObject *self, PyObject *arg)\n{\n PyArray_Typecode newtype = {PyArray_NOTYPE, 0, 0};\n intp newdim;\n int index;\n char *msg = \"new type not compatible with array.\";\n\n if ((PyArray_TypecodeConverter(arg, &newtype) < 0) ||\n newtype.type_num == PyArray_NOTYPE) {\n PyErr_SetString(PyExc_TypeError, \"invalid type for array\");\n return -1;\n }\n if (!(PyArray_ISONESEGMENT(self) ||\t\t\\\n\t (newtype.itemsize != self->itemsize))) {\n PyErr_SetString(PyExc_ValueError, msg);\n return -1; \n }\n\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\n if (newtype.itemsize < self->itemsize) {\n /* if it is compatible increase the size of the dimension\n at end (or at the front for FORTRAN)\n */\n if (self->itemsize % newtype.itemsize != 0) {\n PyErr_SetString(PyExc_ValueError, msg);\n return -1;\n }\n newdim = self->itemsize / newtype.itemsize;\n\t\tself->dimensions[index] *= newdim;\n self->strides[index] = newtype.itemsize;\n\t}\n \n else if (newtype.itemsize > self->itemsize) {\n \n /* Determine if last (or first if FORTRAN) dimension\n is compatible */\n\n\t\tnewdim = self->dimensions[index] * self->itemsize;\n if ((newdim % newtype.itemsize) != 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, msg);\n return -1;\n }\n\t\t\n self->dimensions[index] = newdim / newtype.itemsize;\n self->strides[index] = newtype.itemsize;\n\t\t\n }\n\t\n \n /* fall through -- adjust type*/\n\n self->descr = PyArray_DescrFromType(newtype.type_num);\n self->itemsize = newtype.itemsize;\n PyArray_UpdateFlags(self, ALIGNED);\n return 0;\n\n}\n\n\n\nstatic PyObject *\narray_base_get(PyArrayObject *self)\n{\n\tif (self->base == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\telse {\n\t\tPy_INCREF(self->base);\n\t\treturn self->base;\n\t}\n}\n\n\nstatic PyObject *\narray_real_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *)ret;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n}\n\n\nstatic int\narray_real_set(PyArrayObject *self, PyObject *val)\n{\n\tPyArrayObject *ret;\n\tPyArrayObject *new;\n\tint rint;\n\n\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0);\n\tif (new == NULL) return -1;\n\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) 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\treturn rint;\n}\n\nstatic PyObject *\narray_imag_get(PyArrayObject *self)\n{\t\n\tPyArrayObject *ret;\n\tint itemsize;\n\tint typenum;\n PyArray_Typecode type;\n\t\n\ttype.type_num = self->descr->type_num;\n\ttype.itemsize = self->itemsize;\n\ttype.fortran = PyArray_ISFORTRAN(self);\n\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\titemsize = self->itemsize >> 1;\n\t\ttypenum = self->descr->type_num - PyArray_NUM_FLOATTYPE;\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 typenum,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data + itemsize,\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\tret = (PyArrayObject *)PyArray_Zeros(self->nd, \n\t\t\t\t\t\t self->dimensions, &type);\n\t\tret->flags &= ~WRITEABLE;\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic int\narray_imag_set(PyArrayObject *self, PyObject *val)\n{\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyArrayObject *ret;\n\t\tPyArrayObject *new;\n\t\tint rint;\n\n\t\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0); \n\t\tif (new == NULL) return -1;\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides+ \\\n\t\t\t\t\t\t (self->itemsize >> 1) ,\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) {\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_Typecode typecode;\n int swap;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode.type_num = self->descr->type_num;\n\ttypecode.itemsize = self->itemsize;\n\ttypecode.fortran = PyArray_ISFORTRAN(self);\n\t\n\tarr = PyArray_FromAny(val, &typecode, \n\t\t\t 0, 0, FORCECAST);\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->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 copyswap(selfit->dataptr, NULL, swap, \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->itemsize);\n copyswap(selfit->dataptr, NULL, swap, self->itemsize);\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\t{\"base\",\n\t (getter)array_base_get,\n\t NULL,\n\t \"base object\"},\n {\"dtype\", \n\t (getter)array_type_get, \n\t (setter)array_type_set,\n\t \"get array type class\"},\n\t{\"dtypechar\",\n\t (getter)array_typechar_get,\n\t NULL,\n\t \"get array type character code\"},\n\t{\"dtypestr\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"get array type string\"},\n {\"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_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\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\n\nstatic char Arraytype__doc__[] = \n \"A array object represents a multidimensional, homogeneous array\\n\"\n\t\" of basic values. Arrays are sequence, mapping and numeric\\n\"\n\t\" objects. More information is available in the scipy module and\\n\"\n\t\" by looking at the methods and attributes of an array.\";\n\nstatic PyTypeObject PyBigArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"scipy.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 \n offsetof(PyArrayObject, weakreflist), /*tp_weaklistoffset */\n\n /* Iterator support (use standard) */\n\n (getiterfunc)0, \t\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 0,\t /* tp_alloc */ \n (newfunc)array_new,\t\t /* tp_new */\n 0,\t \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 \"scipy.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) \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 if (PySequence_Length(s) == 0) \n\t\treturn 1;\n\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);\n\t\tif(d >= 0) d++;\n\t}\n Py_DECREF(e);\n return d;\n}\n\nstatic int\ndiscover_itemsize(PyObject *s, int nd, int *itemsize) \n{\n\tint n, r, i;\n\tPyObject *e;\n\t\n\tn = PyObject_Length(s);\n\n\tif ((nd == 0) || PyString_Check(s) ||\t\t\\\n\t PyUnicode_Check(s) || PyBuffer_Check(s)) {\n\t\tif PyUnicode_Check(s) \n\t\t\t*itemsize = MAX(*itemsize, sizeof(Py_UNICODE)*n);\n\t\telse\n\t\t\t*itemsize = MAX(*itemsize, n);\n\t\treturn 0;\n\t}\n\tfor (i=0; i n_lower) n_lower = d[1];\n }\n d[1] = n_lower;\n\t\n return 0;\n}\n\nstatic void\n_array_small_type(int chktype, int mintype, int chksize, int minsize, \n\t\t PyArray_Typecode *outtype)\n{\n\touttype->type_num = MAX(chktype, mintype);\n\tif (PyTypeNum_ISFLEXIBLE(outtype->type_num) &&\t\\\n\t PyTypeNum_ISFLEXIBLE(mintype)) {\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 == PyArray_STRING) {\n\t\t\touttype->itemsize = MAX(chksize, 2*minsize);\n\t\t}\n\t\telse {\n\t\t\touttype->itemsize = MAX(chksize, minsize);\n\t\t}\n\t}\n\telse {\n\t\touttype->itemsize = chksize;\n\t}\n\treturn;\t\n}\n\nstatic void\n_array_find_type(PyObject *op, PyArray_Typecode *minitype, \n\t\t PyArray_Typecode *outtype, int max)\n{\n int l;\n PyObject *ip;\n\tint chktype=0;\n\tint chksize=0;\n\tint mintype, minsize;\n\n\tif (minitype == NULL) {\n\t\tmintype = PyArray_BOOL;\n\t\tminsize = sizeof(Bool);\n\t}\n\telse {\n\t\tmintype = minitype->type_num;\n\t\tminsize = minitype->itemsize;\n\t}\n\n \n if (max < 0 || mintype == -1) goto deflt;\n\t\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_TYPE(op);\n\t\tchksize = PyArray_ITEMSIZE(op);\n\t\tgoto finish;\n\t}\n\t\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tPyArray_TypecodeFromScalar(op, outtype);\n\t\tchktype = outtype->type_num;\n\t\tchksize = outtype->itemsize;\n\t\tgoto finish;\n\t}\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_TYPE(ip);\n\t\t\tchksize = PyArray_ITEMSIZE(ip);\n\t\t\tgoto finish;\n\t\t}\n } \n\t\n\tif (PyObject_HasAttrString(op, \"__array_typestr__\")) {\n\t\tint swap=0, res;\n\t\tip = PyObject_GetAttrString(op, \"__array_typestr__\");\n\t\tif (ip && PyString_Check(ip)) {\n\t\t\tres = _array_typecode_fromstr(PyString_AS_STRING(ip), \n\t\t\t\t\t\t &swap, outtype); \n\t\t\tif (res >= 0) {\n\t\t\t\tPy_DECREF(ip);\n\t\t\t\tchktype = outtype->type_num;\n\t\t\t\tchksize = outtype->itemsize;\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t}\n\t\tPy_XDECREF(ip);\n\t}\n\n if (PyString_Check(op)) {\n\t\tchktype = PyArray_STRING;\n\t\tchksize = PyString_GET_SIZE(op);\n\t\tgoto finish;\n }\n\n\tif (PyUnicode_Check(op)) {\n\t\tchktype = PyArray_UNICODE;\n\t\tchksize = PyUnicode_GET_DATA_SIZE(op);\n\t\tgoto finish;\n\t}\n\n\tif (PyBuffer_Check(op)) {\n\t\tchktype = PyArray_VOID;\n\t\tchksize = op->ob_type->tp_as_sequence->sq_length(op);\n\t\tPyErr_Clear();\n\t\tgoto finish;\n\t}\n\n\tif (PyInstance_Check(op)) goto deflt;\n\t\n if (PySequence_Check(op)) {\n\t\tPyArray_Typecode newtype;\n\t\tnewtype.type_num = mintype;\n\t\tnewtype.itemsize = minsize;\n\t\tnewtype.fortran = 0;\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 && mintype == 0) {\n\t\t\tnewtype.type_num = PyArray_INTP;\n\t\t\tnewtype.itemsize = sizeof(intp);\n\t\t}\n while (--l >= 0) {\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\t_array_find_type(ip, &newtype, outtype, max-1);\n\t\t\t_array_small_type(outtype->type_num,\n\t\t\t\t\t newtype.type_num, \n\t\t\t\t\t outtype->itemsize,\n\t\t\t\t\t newtype.itemsize,\n\t\t\t\t\t &newtype);\n Py_DECREF(ip);\n }\n\t\tchktype = newtype.type_num;\n\t\tchksize = newtype.itemsize;\n\t\tgoto finish;\n }\n\t\n\tif (PyBool_Check(op)) {\n\t\tchktype = PyArray_BOOL;\n\t\tchksize = sizeof(Bool);\n\t\tgoto finish;\t\t\n\t}\n else if (PyInt_Check(op)) {\n\t\tchktype = PyArray_LONG;\n\t\tchksize = sizeof(long);\n\t\tgoto finish;\n } else if (PyFloat_Check(op)) {\n\t\tchktype = PyArray_DOUBLE;\n\t\tchksize = sizeof(double);\n\t\tgoto finish;\n\t} else if (PyComplex_Check(op)) {\n\t\tchktype = PyArray_CDOUBLE;\n\t\tchksize = sizeof(cdouble);\n\t\tgoto finish;\n\t}\n\n deflt:\n\tchktype = PyArray_OBJECT;\n\tchksize = sizeof(void *);\n\n finish:\n\t_array_small_type(chktype, mintype, chksize, minsize, \n\t\t\t outtype);\n\treturn;\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\" */ \nstatic PyObject *\nArray_FromScalar(PyObject *op, PyArray_Typecode *typecode) \n{\n PyArrayObject *ret;\n\tint itemsize = 0;\n\tint type = typecode->type_num;\n\n\tif PyTypeNum_ISFLEXIBLE(type) {\n\t\titemsize = PyObject_Length(op);\n\t}\n\n\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, 0, NULL, type,\n\t\t\t\t\t NULL, NULL, itemsize, 0, NULL);\n\n\tif (ret == NULL) return NULL;\n\n ret->descr->setitem(op, ret->data, ret);\n\t\n if (PyErr_Occurred()) {\n array_dealloc(ret);\n return NULL;\n } else {\n return (PyObject *)ret;\n }\n}\n\n\nstatic PyObject *\nArray_FromSequence(PyObject *s, PyArray_Typecode *typecode, int min_depth, \n\t\t int max_depth)\n{\n PyArrayObject *r;\n int nd;\n\tintp *d;\n\tint stop_at_string;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->itemsize;\n\t\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 if (!((nd=discover_depth(s, MAX_DIMS+1, stop_at_string)) > 0)) {\n\t\tif (nd==0)\n\t\t\treturn Array_FromScalar(s, typecode);\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid input sequence\");\n return NULL;\n }\n\t\n if ((max_depth && nd > max_depth) ||\t\\\n\t (min_depth && nd < min_depth)) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid number of dimensions\");\n return NULL;\n }\n\t\n\tif ((d=PyDimMem_NEW(nd)) == NULL) {\n\t\treturn PyErr_NoMemory();\n }\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) {\n\t\tPyDimMem_FREE(d);\n\t\treturn NULL;\n\t}\n\tif (itemsize == 0 && PyTypeNum_ISFLEXIBLE(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) {\n\t\t\tPyDimMem_FREE(d);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n r=(PyArrayObject*)PyArray_New(&PyArray_Type, nd, d, \n\t\t\t\t type, NULL, NULL,\n\t\t\t\t itemsize, \n\t\t\t\t typecode->fortran, NULL);\n\n PyDimMem_FREE(d);\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\n\nstatic int \nPyArray_ValidType(int type) \n{\n\tPyArray_Descr *descr;\n\t\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr==NULL) return 0;\n\treturn 1;\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->itemsize;\n\tint nels = PyArray_BUFSIZE;\n\tint el;\n\tint inswap, outswap=0;\n\tint obuf=!PyArray_ISCARRAY(out);\n\tint oelsize = out->itemsize;\n\tPyArray_VectorUnaryFunc *castfunc;\n PyArray_CopySwapFunc *in_csn;\n PyArray_CopySwapFunc *out_csn;\n\tint retval = -1;\n\n\tcastfunc = in->descr->cast[out->descr->type_num];\n in_csn = in->descr->copyswap;\n out_csn = out->descr->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\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\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->itemsize * 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\n/* For backward compatibility */\n\nstatic PyObject *\nPyArray_Cast(PyArrayObject *mp, int type_num) \n{\n\tPyArray_Typecode type;\n\tPyArray_Descr *descr;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\ttype.itemsize = descr->elsize;\n\ttype.type_num = descr->type_num;\n\ttype.fortran = 0;\n\t\n\treturn PyArray_CastToType(mp, &type);\n}\n\nstatic PyObject * \nPyArray_CastToType(PyArrayObject *mp, PyArray_Typecode *at) \n{\n\tPyObject *out;\n\tint ret;\n\n\tif ((mp->descr->type_num == at->type_num) && \\\n\t (at->itemsize==0 || mp->itemsize == at->itemsize) &&\n\t PyArray_ISBEHAVED_RO(mp)) {\n\t\tPy_INCREF(mp);\n\t\treturn (PyObject *)mp;\n\t}\n\t\t\n\tif (at->itemsize == 0) {\n\t\tif (mp->descr->type_num == PyArray_STRING &&\t\\\n\t\t at->type_num == PyArray_UNICODE)\n\t\t\tat->itemsize = mp->itemsize*sizeof(Py_UNICODE);\n\t\tif (mp->descr->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING) \n\t\t\tat->itemsize = mp->itemsize/sizeof(Py_UNICODE);\n\t\tif (at->type_num == PyArray_VOID)\n\t\t\tat->itemsize = mp->itemsize;\n\t}\n\n\tout = PyArray_New(mp->ob_type, mp->nd, \n\t\t\t mp->dimensions, \n\t\t\t at->type_num,\n\t\t\t NULL, NULL, at->itemsize, \n\t\t\t at->fortran, (PyObject *)mp);\n\tif (out == NULL) return NULL;\n\tret = PyArray_CastTo((PyArrayObject *)out, mp);\n\tif (ret != -1) return out;\n\n\tPy_DECREF(out);\n\treturn NULL;\n\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\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\tsimple = ((PyArray_ISCARRAY(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY(mp) && PyArray_ISFARRAY(out)));\n\t\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->itemsize * outsize;\n\t\tintp ncopies = outsize / mpsize;\n\n\t\twhile(ncopies--) {\n\t\t\tinptr = mp->data;\n\t\t\tmp->descr->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\nstatic PyObject *\narray_fromarray(PyArrayObject *arr, PyArray_Typecode *typecode, int flags) \n{\n\t\n\tPyArrayObject *ret=NULL;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->itemsize;\n\tint copy = 0;\n\tint arrflags;\n\tPyArray_Typecode oldtype;\n\tchar *msg = \"cannot copy back to a read-only array\";\n PyTypeObject *subtype;\n\n\toldtype.type_num = PyArray_TYPE(arr);\n\toldtype.itemsize = PyArray_ITEMSIZE(arr);\n\toldtype.fortran = 0;\n\n subtype = arr->ob_type;\n\n\tif (type == PyArray_NOTYPE) type = arr->descr->type_num;\n\tif (itemsize == 0) itemsize = arr->itemsize;\n\ttypecode->type_num = type;\n\ttypecode->itemsize = itemsize;\n\n\t/* Don't copy if sizes are compatible */\n\tif (PyArray_EquivalentTypes(&oldtype, typecode)) {\n\t\tarrflags = arr->flags;\n\n\t\tcopy = (flags & ENSURECOPY) || \\\n\t\t\t((flags & CONTIGUOUS) && (!(arrflags & CONTIGUOUS))) \\\n\t\t\t|| (PyArray_ITEMSIZE(arr) != itemsize) || \\\n\t\t\t((flags & ALIGNED) && (!(arrflags & ALIGNED))) || \\\n\t\t\t((flags & NOTSWAPPED) && (!(arrflags & NOTSWAPPED))) \\\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 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_New(subtype, \n\t\t\t\t\t arr->nd, \n\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t type,\n\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t itemsize,\n\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t (PyObject *)arr);\n\t\t\tif (PyArray_CopyInto(ret, arr) == -1) 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 ret = (PyArrayObject *) \\\n PyArray_New(&PyArray_Type,\n arr->nd,\n arr->dimensions,\n arr->descr->type_num,\n arr->strides,\n arr->data,\n arr->itemsize,\n arr->flags,NULL);\n if (ret == NULL) return NULL;\n ret->base = (PyObject *)arr;\n ret->flags &= ~UPDATEIFCOPY;\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_CanCastSafely(PyArray_TYPE(arr), type)) {\n if ((flags & UPDATEIFCOPY) && \\\n (!PyArray_ISWRITEABLE(arr))) {\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_New(subtype, arr->nd,\n arr->dimensions, typecode->type_num,\n NULL, NULL, typecode->itemsize,\n typecode->fortran, \n (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\nstatic int\n_array_typecode_fromstr(char *str, int *swap, PyArray_Typecode *type)\n{\n int type_num;\n char typechar;\n int size;\n unsigned long number = 1;\n char *s;\n char msg[] = \"unsupported typestring\";\n \n s = (char *)&number; /* s[0] == 0 implies big-endian */\n\n *swap = 0;\n\n if (str[0] == '<' || str[0] == '>') {\n\tif ((str[0] == '<') && (s[0] == 0)) *swap = 1;\n\telse if ((str[0] == '>') && (s[0] != 0)) *swap = 1;\n }\n str += 1;\n \n#define _MY_FAIL {\t\t\t\t \\\n\t PyErr_SetString(PyExc_ValueError, msg); \\\n\t return -1;\t\t\t \\\n }\t\t\n\n typechar = str[0];\n size = atoi(str + 1);\n switch (typechar) {\n case 'b':\n\t if (size == sizeof(Bool))\n\t\t type_num = PyArray_BOOL;\t \n\t else _MY_FAIL \n\t break;\t\t \n case 'u':\n if (size == sizeof(uintp))\n type_num = PyArray_UINTP;\n\t else if (size == sizeof(char))\n\t\t type_num = PyArray_UBYTE;\n\t else if (size == sizeof(short)) \n\t\t type_num = PyArray_USHORT;\n\t else if (size == sizeof(int)) \n\t\t type_num = PyArray_UINT;\n\t else if (size == sizeof(ulong)) \n\t\t type_num = PyArray_ULONG;\n\t else if (size == sizeof(ulonglong))\n\t\t type_num = PyArray_ULONGLONG;\n\t else _MY_FAIL\n\t break;\t\t \n case 'i':\n if (size == sizeof(intp))\n type_num = PyArray_INTP;\n\t else if (size == sizeof(char)) \n\t\t type_num = PyArray_BYTE;\n\t else if (size == sizeof(short)) \n\t\t type_num = PyArray_SHORT;\n\t else if (size == sizeof(int))\n\t\t type_num = PyArray_INT;\n\t else if (size == sizeof(long)) \n\t\t type_num = PyArray_LONG;\n\t else if (size == sizeof(longlong))\n\t\t type_num = PyArray_LONGLONG;\n\t else _MY_FAIL\n\t break;\t\t \n case 'f':\n\t if (size == sizeof(float))\n\t\t type_num = PyArray_FLOAT;\n\t else if (size == sizeof(double))\n\t\t type_num = PyArray_DOUBLE;\n\t else if (size == sizeof(longdouble))\n\t\t type_num = PyArray_LONGDOUBLE;\n\t else _MY_FAIL\n\t break;\n case 'c':\n\t if (size == sizeof(float)*2)\n\t\t type_num = PyArray_CFLOAT;\n\t else if (size == sizeof(double)*2)\n\t\t type_num = PyArray_CDOUBLE;\n\t else if (size == sizeof(longdouble)*2)\n\t\t type_num = PyArray_CLONGDOUBLE;\n\t else _MY_FAIL\n\t break;\n case 'O':\n\t if (size == sizeof(PyObject *))\n\t\t type_num = PyArray_OBJECT;\n\t else _MY_FAIL\n\t break;\n case 'S':\n\t type_num = PyArray_STRING;\n\t break;\n case 'U':\n\t type_num = PyArray_UNICODE;\n\t size *= sizeof(Py_UNICODE);\n\t break;\t \n case 'V':\n\t type_num = PyArray_VOID;\n\t break;\n default:\n\t _MY_FAIL\n }\n\n#undef _MY_FAIL\n\n type->type_num = type_num;\n type->itemsize = size;\n type->fortran = 0;\n return 0;\n}\n\nstatic PyObject *\narray_frominterface(PyObject *input, PyArray_Typecode *intype, int flags)\n{\n\tPyObject *attr=NULL, *item=NULL, *r;\n\tPyArrayObject *ret=NULL;\n\tPyArray_Typecode type;\n\tchar *data;\n\tint buffer_len;\n\tint res, i, n;\n\tintp dims[MAX_DIMS], strides[MAX_DIMS];\n\tint swap;\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\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) {Py_XDECREF(attr); return NULL;}\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t}\n\telse {\n\t\tif (PyTuple_GET_SIZE(attr) != 2) {\n\t\t\tPy_DECREF(attr);\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\treturn NULL;\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\tPy_DECREF(attr);\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\treturn NULL;\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 = PyObject_GetAttrString(input, \"__array_typestr__\");\n\tif (!PyString_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_typestr__ must be a string\");\n\t\tPy_DECREF(attr);\n\t\treturn NULL;\t\n\t}\n\tres = _array_typecode_fromstr(PyString_AS_STRING(attr), &swap, &type);\n\tPy_DECREF(attr);\n\tif (res < 0) return NULL;\n \n\tattr = PyObject_GetAttrString(input, \"__array_shape__\");\n\tif (!PyTuple_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_shape__ must be a tuple\");\n\t\tPy_DECREF(attr);\n\t\treturn NULL;\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\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\treturn NULL;\n\t\t}\n\t\tfor (i=0; istrides, strides, n*sizeof(intp));\n\t}\n\n\tif (swap) {\n\t\tPyObject *tmp;\n tmp = PyArray_Byteswap(ret, TRUE);\n\t\tPy_DECREF(tmp);\n\t}\n\n\tPyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n\tr = array_fromarray(ret, intype, flags);\n\tPy_DECREF(ret);\n\treturn r;\n}\n\nstatic PyObject *\narray_fromattr(PyObject *op, PyArray_Typecode *typecode, int flags) \n{\n PyObject *new, *r;\n\t \n if (typecode->type_num == PyArray_NOTYPE) {\n new = PyObject_CallMethod(op, \"__array__\", NULL);\n } else {\n\t\tPyArray_Descr *descr;\n\t\tPyObject *obj;\n\n\t\tdescr = PyArray_DescrFromType(typecode->type_num);\n\t\tif (PyTypeNum_ISFLEXIBLE(typecode->type_num)) {\n\t\t\tobj = PyString_FromFormat(\"%c%d\", descr->type,\n\t\t\t\t\t\t typecode->itemsize);\n\t\t}\n\t\telse { \n\t\t\tobj = (PyObject *)(descr->typeobj); Py_INCREF(obj);\n\t\t}\n\t\tnew = PyObject_CallMethod(op, \"__array__\", \"N\", obj);\n }\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 r = array_fromarray((PyArrayObject *)new, typecode, flags);\n Py_DECREF(new);\n return r;\n} \n\n\nstatic PyObject *\narray_fromobject(PyObject *op, PyArray_Typecode *typecode, int min_depth, \n\t\t int max_depth, int flags) \n{\n /* This is the main code to make a NumPy array from a Python\n Object. It is called from lot's of different places which\n is why there are so many checks. The comments try to\n explain some of the checks. */\n\n\tint type = typecode->type_num;\n PyObject *r=NULL;\n\n\t/* Is input object already an array? */\n\t/* This is where the flags are used */\n if (PyArray_Check(op)) \n\t\tr = array_fromarray((PyArrayObject *)op, typecode, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, typecode);\n\t}\n\telse if (PyObject_HasAttrString(op, \"__array__\")) {\n\t\t/* Code that returns the object to convert for a non\n\t\t multiarray input object from the __array__ attribute of the\n\t\t object. */\n r = array_fromattr(op, typecode, flags);\n\t}\n\telse if (PyObject_HasAttrString(op, \"__array_shape__\") &&\n\t\t PyObject_HasAttrString(op, \"__array_typestr__\")) {\n\t\tr = array_frominterface(op, typecode, flags);\n\t}\n\telse {\n\t\tif (type == PyArray_NOTYPE) {\n\t\t\t_array_find_type(op, NULL, typecode, MAX_DIMS);\n\t\t}\n\t\tif (PySequence_Check(op))\n\t\t\tr = Array_FromSequence(op, typecode, \n\t\t\t\t\t min_depth, max_depth);\n\t\telse\n\t\t\tr = Array_FromScalar(op, typecode);\n\t}\n\n /* If we didn't succed return NULL */\n if (r == NULL) return NULL;\n\t\n\t/* Be sure we succeed here */\n\t\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"internal error: array_fromobject \"\\\n\t\t\t\t\"not producing an array\");\n\t\tPy_DECREF(r);\n return NULL;\n }\n\n if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {\n Py_DECREF(r);\n PyErr_SetString(PyExc_ValueError, \n \"object of too small depth for desired array\");\n return NULL;\n }\n if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {\n Py_DECREF(r);\n PyErr_SetString(PyExc_ValueError, \n \"object too deep for desired array\");\n return NULL;\n }\n return r;\n}\n\nstatic void\nPyArray_ArrayType(PyObject *op, PyArray_Typecode *intype, \n\t\t PyArray_Typecode *outtype) \n{\n\t_array_find_type(op, intype, outtype, MAX_DIMS);\n\treturn;\n}\n\nstatic int \nPyArray_ObjectType(PyObject *op, int minimum_type) \n{\n\tPyArray_Typecode intype, outtype;\n\tintype.type_num = minimum_type;\n\t_array_find_type(op, &intype, &outtype, MAX_DIMS);\n\treturn outtype.type_num;\n}\n\n\n\n/* flags is any of \n CONTIGUOUS, \n FORTRAN, (or set typecode->fortran=1)\n ALIGNED, \n NOTSWAPPED, \n WRITEABLE, \n ENSURECOPY, \n UPDATEIFCOPY,\n FORCECAST,\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, NOTSWAPPED, and WRITEABLE\n and therefore it is redundant to include those as well. \n\n BEHAVED_FLAGS == ALIGNED | NOTSWAPPED | WRITEABLE\n BEHAVED_FLAGS_RO == ALIGNED | NOTSWAPPED\n CARRAY_FLAGS = CONTIGUOUS | BEHAVED_FLAGS\n FARRAY_FLAGS = FORTRAN | BEHAVED_FLAGS\n \n By default, the returned array will be a copy of the object, \n (C) contiguous in memory, aligned, notswapped, and writeable.\n \n So CONTIGUOUS | ENSURECOPY passed in means that the returned\n array does not have to be CONTIGUOUS or a COPY but should be\n ALIGNED, NOTSWAPPED and WRITEABLE. \n\n typecode->fortran can be set to request a\n fortran-contiguous array. Fortran arrays are always behaved (aligned, \n notswapped, and writeable) and not (C) CONTIGUOUS. Note that either\n FORTRAN in the flag or typecode->fortran = 1 is enough to request\n a FORTRAN-style array. \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\nstatic PyObject *\nPyArray_FromAny(PyObject *op, PyArray_Typecode *typecode, int min_depth, \n\t\tint max_depth, int requires) \n{\n \tPyArray_Typecode mine = {PyArray_NOTYPE, 0, 0};\n\tPyArray_Typecode *type;\n\t\n\tif (typecode == NULL) type = &mine;\n\telse type = typecode;\n\t\t\n\tif (requires & ENSURECOPY) {\n\t\trequires |= DEFAULT_FLAGS;\n\t}\n\t/* Ensure that type->fortran and flags & FORTRAN are the\n\t same */\n\tif (requires & FORTRAN) typecode->fortran = 1;\n\tif (type->fortran == 1) {\n\t\trequires |= FARRAY_FLAGS;\n\t\tif (min_depth > 2) requires &= ~CONTIGUOUS;\n\t}\n\n\t/* make sure itemsize is not 0 unless warranted. */\n\tif ((type->itemsize == 0) && (type->type_num != PyArray_NOTYPE)) {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(type->type_num);\n\t\tif (descr != NULL) type->itemsize = descr->elsize;\n\t\telse return NULL;\n\t}\n\t\n\treturn array_fromobject(op, type, min_depth, max_depth, \n\t\t\t\trequires);\t\n}\n\n/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0, 0) */\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\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);\n Py_DECREF(op);\n return new;\n}\n\n/* These are all compressed into a single API */\n/* Deprecated calls -- Use PyArray_FromAny */\n\nstatic PyObject *\nPyArray_FromObject(PyObject *op, int type, int min_depth, int max_depth) \n{\n\tPyArray_Typecode typecode = {0, 0, 0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth,\n\t\t\t max_depth, BEHAVED_FLAGS | ENSUREARRAY);\n}\n\nstatic PyObject *\nPyArray_ContiguousFromObject(PyObject *op, int type, int min_depth, \n\t\t\t int max_depth) \n{\n\tPyArray_Typecode typecode = {0, 0, 0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth,\n\t\t\t max_depth, DEFAULT_FLAGS | ENSUREARRAY);\n}\n\nstatic PyObject *\nPyArray_CopyFromObject(PyObject *op, int type, int min_depth, \n\t\t int max_depth) \n{\n\tPyArray_Typecode typecode = {0, 0, 0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth, max_depth,\n\t\t\t ENSURECOPY | ENSUREARRAY);\n}\n\n/* End of deprecated */\n\nstatic PyObject *\nPyArray_ContiguousFromAny(PyObject *op, int type, int min_depth, \n\t\t\t int max_depth)\n{\n\tPyArray_Typecode typecode = {0,0,0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth,\n\t\t\t max_depth, DEFAULT_FLAGS);\n}\t\n\nstatic int \nPyArray_CanCastSafely(int fromtype, int totype) \n{\n\tPyArray_Descr *from, *to;\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\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 (to->elsize > from->elsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (to->elsize >= from->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (from->elsize < 8)\n return (to->elsize > from->elsize);\n else\n return (to->elsize >= from->elsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (from->elsize < 8)\n return ((to->elsize >> 1) > from->elsize);\n else\n return ((to->elsize >> 1) >= from->elsize);\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 (to->elsize > from->elsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (to->elsize >= from->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (from->elsize < 8)\n return (to->elsize > from->elsize);\n else\n return (to->elsize >= from->elsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (from->elsize < 8)\n return ((to->elsize >> 1) > from->elsize);\n else\n return ((to->elsize >> 1) >= from->elsize);\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 ((to->elsize >> 1) >= from->elsize);\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\nstatic Bool\nPyArray_CanCastTo(PyArray_Typecode *from, PyArray_Typecode *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->itemsize <= to->itemsize);\n\t\t\t}\n\t\t\telse if (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->itemsize * sizeof(Py_UNICODE)\\\n\t\t\t\t <= to->itemsize);\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->itemsize <= to->itemsize);\n\t\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 scipy's arraymap ****/\n/* and Python's array iterator ***/\n \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 = PyObject_GC_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 PyObject_GC_Track(it);\n return (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 PyObject_GC_UnTrack(it);\n Py_XDECREF(it->ao);\n PyObject_GC_Del(it);\n }\n\nstatic int\narrayiter_traverse(PyArrayIterObject *it, visitproc visit, void *arg)\n{\n if (it->ao != NULL)\n return visit((PyObject *)(it->ao), arg);\n return 0;\n}\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->itemsize;\n\tr = PyArray_New(self->ao->ob_type, 1, &count, \n\t\t\tself->ao->descr->type_num, NULL, NULL,\n\t\t\titemsize, 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->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->itemsize;\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\tr = PyArray_New(self->ao->ob_type, ind->nd, ind->dimensions,\n\t\t\tself->ao->descr->type_num, NULL, \n\t\t\tNULL, self->ao->itemsize, \n\t\t\t0, (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)->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\tint i;\n\tPyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tint 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\t\t\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\n\t/* Tuples 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\tr = PyArray_New(self->ao->ob_type, 1, &ii, \n\t\t\t\t\tself->ao->descr->type_num, NULL, \n\t\t\t\t\tNULL, self->ao->itemsize, 0,\n\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 */\n\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->itemsize;\n\t\tr = PyArray_New(self->ao->ob_type, 1, &n_steps, \n\t\t\t\tself->ao->descr->type_num, NULL, NULL,\n\t\t\t\tsize, 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)->copyswap;\n\t\twhile(n_steps--) {\n copyswap(dptr, self->dataptr, swap, size);\n\t\t\tfor(i=0; i< step_size; i++) \n\t\t\t\tPyArray_ITER_NEXT(self);\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\tif (PyArray_IsScalar(ind, Integer) || PyList_Check(ind)) {\n\t\tobj = PyArray_FromAny(ind, &indtype, 0, 0, FORCECAST);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tr = iter_subscript_Bool(self, (PyArrayObject *)obj);\n\t\t} \n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, &indtype, 0, 0, \n\t\t\t\t\t FORCECAST | BEHAVED_FLAGS);\n\t\t\tif (new==NULL) goto fail;\n\t\t\tobj = new;\n\t\t\tr = iter_subscript_int(self, (PyArrayObject *)obj);\n\t\t}\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\t\"unsupported iterator index\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPy_DECREF(obj);\n\t\treturn r;\n\t}\n\n\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\n fail:\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->itemsize;\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->copyswap;\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(self->dataptr, val->dataptr, swap,\n itemsize);\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t\tPyArray_ITER_NEXT(val);\n\t\tif (val->index==val->size) \n\t\t\tPyArray_ITER_RESET(val);\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_Typecode typecode;\n\tintp num;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\titemsize = typecode.itemsize = self->ao->itemsize;\n\ttypecode.type_num = self->ao->descr->type_num;\n copyswap = self->ao->descr->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\n\nstatic int\niter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val) \n{\n\tint i;\n\tPyObject *arrval=NULL;\n\tPyArrayIterObject *val_it=NULL;\n\tPyArray_Typecode type;\n\tPyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tint swap;\n\tint itemsize;\n\tint start, step_size;\n\tintp n_steps;\n\tPyObject *obj;\n PyArray_CopySwapFunc *copyswap;\n\t\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\ti = iter_ass_subscript(self, ind, val);\n\t\tPy_DECREF(ind);\n\t\treturn i;\n\t}\n\t\n\ttype.type_num = self->ao->descr->type_num;\n\titemsize = type.itemsize = self->ao->itemsize;\n\t\n\tarrval = PyArray_FromAny(val, &type, 0, 0, 0);\n\tif (arrval==NULL) return -1;\n\tval_it = (PyArrayIterObject *)PyArray_IterNew(arrval);\n\tif (val_it==NULL) goto fail;\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\n copyswap = PyArray_DESCR(arrval)->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\tgoto succeed;\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 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 copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, itemsize);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\tgoto succeed;\n\t\t}\n\t\twhile(n_steps--) {\n copyswap(self->dataptr, val_it->dataptr,\n swap, itemsize);\n\t\t\tfor(i=0; i < step_size; i++) \n\t\t\t\tPyArray_ITER_NEXT(self);\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\tgoto succeed;\n\t} \n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tif (PyArray_IsScalar(ind, Integer))\n\t\tobj = PyArray_FromScalar(ind, &indtype);\n\telse if (PyList_Check(ind)) {\n\t\tobj = PyArray_FromAny(ind, &indtype, 0, 0, FORCECAST);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tif (iter_ass_sub_Bool(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto fail;\n\t\t} \n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, &indtype, 0, 0, \n\t\t\t\t\t FORCECAST | BEHAVED_FLAGS);\n\t\t\tif (new==NULL) goto fail;\n\t\t\tPy_DECREF(obj);\n\t\t\tobj = new;\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 fail;\n\t\t}\n\t\telse goto fail;\n\t\tPy_DECREF(obj);\n\t\tgoto succeed;\n\t}\n\n\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\tgoto fail;\n\n succeed:\n\tPy_DECREF(val_it);\n\tPy_DECREF(arrval);\n\treturn 0;\n\n fail:\n\tPy_XDECREF(val_it);\n\tPy_XDECREF(arrval);\n\treturn -1;\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 if (PyArray_ISCONTIGUOUS(it->ao)) {\n r = PyArray_New(it->ao->ob_type, 1, &size, \n\t\t\t\tit->ao->descr->type_num,\n NULL, it->ao->data, it->ao->itemsize, \n\t\t\t\tit->ao->flags,\n (PyObject *)it->ao); \n\t\tif (r==NULL) return NULL;\n }\n else {\n r = PyArray_New(it->ao->ob_type, 1, &size, \n\t\t\t\tit->ao->descr->type_num,\n NULL, NULL, it->ao->itemsize, 0, \n (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\n\nstatic PyTypeObject PyArrayIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"scipy.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 | Py_TPFLAGS_HAVE_GC,/* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)arrayiter_traverse,\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)arrayiter_next,\t\t/* tp_iternext */\n iter_methods,\t\t\t\t/* tp_methods */\n};\n\n/** END of Array Iterator **/\n\n\n\n/*********************** Subscript Array Iterator *************************\n * *\n * This object handles subscript behavior for array objects. *\n * It is an iterator object with a next method *\n * It abstracts the n-dimensional mapping behavior to make the looping *\n * code more understandable (maybe) *\n * and so that indexing can be set up ahead of time *\n */ \n\n/* This checks the args for any fancy indexing objects */\n\n#define SOBJ_NOTFANCY 0 \n#define SOBJ_ISFANCY 1\n#define SOBJ_BADARRAY 2\n#define SOBJ_TOOMANY 3\n#define SOBJ_LISTTUP 4\n\nstatic int\nfancy_indexing_check(PyObject *args)\n{\n\tint i, n;\n\tPyObject *obj;\n\tint retval = SOBJ_NOTFANCY;\n\n\tif (PyTuple_Check(args)) {\n\t\tn = PyTuple_GET_SIZE(args);\n\t\tif (n >= MAX_DIMS) return SOBJ_TOOMANY;\n\t\tfor (i=0; i=MAX_DIMS) return SOBJ_ISFANCY;\n\t\tfor (i=0; i SOBJ_ISFANCY) return retval;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* convert an indexing object to an INTP indexing array iterator\n if possible -- otherwise, it is a Slice or Ellipsis object\n and has to be interpreted on bind to a particular \n array so leave it NULL for now.\n */\nstatic int\n_convert_obj(PyObject *obj, PyArrayIterObject **iter)\n{\n\tPyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tPyObject *arr;\n\n\tif (PySlice_Check(obj) || (obj == Py_Ellipsis))\n\t\t*iter = NULL;\n\telse {\n\t\tarr = PyArray_FromAny(obj, &indtype, 0, 0, FORCECAST);\n\t\tif (arr == NULL) return -1;\n\t\t*iter = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (*iter == NULL) return -1;\n\t}\n\treturn 0;\n}\n\n/* Adjust dimensionality and strides for index object iterators \n --- i.e. broadcast\n */\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->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->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=NULL, *obj=NULL;\n\tint i, j, n, curraxis, ellipexp, noellip;\n\tPyArrayIterObject *it;\n\tintp dimsize;\n\tintp *indptr;\n\n\t/* Remove old binding if any */\n\tPy_XDECREF(mit->ait);\n\tmit->ait = NULL;\n\n\tPy_XDECREF(mit->subspace);\n\tmit->subspace = NULL;\n\t\n\tsubnd = arr->nd - mit->numiter;\n\tif (subnd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"too many indices for array\");\n\t\treturn;\n\t}\n\n\tmit->ait = (PyArrayIterObject *)PyArray_IterNew((PyObject *)arr);\n\tif (mit->ait == NULL) return;\n\n\t/* If this is just a view, then do nothing more */\n\t/* views are handled by just adjusting the strides\n\t and dimensions of the object.\n\t*/\n\t \n\tif (mit->view) return;\n\n\t/* no subspace iteration needed. 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\tif (mit->subspace == NULL) goto fail;\n\tPy_DECREF(sub);\n\n\t/* Expand dimensions of result */\n\tn = mit->subspace->ao->nd;\n\tfor (i=0; idimensions[mit->nd+i] = mit->subspace->ao->dimensions[i];\n\tmit->nd += n;\n\n\t/* Now, we still need to interpret the ellipsis and slice objects \n\t to determine which axes the indexing arrays are referring to\n\t*/\n\tn = PyTuple_GET_SIZE(mit->indexobj);\n\n\t/* The number of dimensions an ellipsis takes up */\n\tellipexp = arr->nd - n + 1;\n\t/* Now fill in iteraxes -- remember indexing arrays have been \n converted to 0's in mit->indexobj */\n\tcurraxis = 0;\n\tj = 0;\n\tnoellip = 1; /* Only expand the first ellipsis */\n\tmemset(mit->bscoord, 0, sizeof(intp)*arr->nd);\n\tfor (i=0; iindexobj, i);\n\t\tif (PyInt_Check(obj) || PyLong_Check(obj)) \n\t\t\tmit->iteraxes[j++] = curraxis++;\n\t\telse if (noellip && obj == Py_Ellipsis) {\n\t\t\tcurraxis += ellipexp;\n\t\t\tnoellip = 0;\n\t\t}\n\t\telse {\n\t\t\tint start=0;\n\t\t\tint 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}\t\t\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn;\n\n fail:\n\tPy_XDECREF(sub);\n\tPy_XDECREF(mit->ait);\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_Typecode typecode = {PyArray_BOOL, 0, 0};\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\tba = (PyArrayObject *)PyArray_FromAny(myBool, &typecode, 0, 0, \n\t\t\t\t\t CARRAY_FLAGS);\n\tif (ba == NULL) return -1;\n\tnd = ba->nd;\n\tfor (j=0; jdata;\n\tcount = 0;\n\n\t/* pre-determine how many nonzero entries there are */\n\tfor (i=0; iao->data;\n\t\tcoords[j] = 0;\n\t\tdims_m1[j] = ba->dimensions[j]-1;\n\t}\n\n\tptr = (Bool *)ba->data;\n\n\tif (count == 0) return nd;\n\n\t/* Loop through the Boolean array and copy coordinates\n\t for non-zero entries */\n\tfor (i=0; i=0; j--) {\n\t\t\tif (coords[j] < dims_m1[j]) {\n\t\t\t\tcoords[j]++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcoords[j] = 0;\n\t\t\t}\n\t\t}\n\t}\n\treturn nd;\n\n fail:\n\tfor (j=0; jiters[i] = NULL;\n \tmit->view = 0;\n \tmit->index = 0;\n \tmit->ait = NULL;\n \tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tfancy = fancy_indexing_check(indexobj);\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\tif (fancy == SOBJ_NOTFANCY) { /* bail out */\n\t\tmit->view = 1;\n\t\tgoto ret;\n\t}\n\n\tif (fancy == SOBJ_BADARRAY) {\n\t\tPyErr_SetString(PyExc_TypeError,\t\t\t\\\n\t\t\t\t\"arrays used as indexes must be of \" \\\n\t\t\t\t\"integer type\");\n\t\tgoto fail;\n\t}\n\tif (fancy == SOBJ_TOOMANY) {\n\t\tPyErr_SetString(PyExc_TypeError, \"too many indicies\");\n\t\tgoto fail;\n\t}\n\n\tif (fancy == SOBJ_LISTTUP) {\n\t\tPyObject *newobj;\n\t\tnewobj = PySequence_Tuple(indexobj);\n\t\tif (newobj == NULL) goto fail;\n\t\tPy_DECREF(indexobj);\n\t\tindexobj = newobj;\n\t\tmit->indexobj = indexobj;\n\t}\n\n#undef SOBJ_NOTFANCY \n#undef SOBJ_ISFANCY \n#undef SOBJ_BADARRAY \n#undef SOBJ_TOOMANY \n#undef SOBJ_LISTTUP \n\n\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\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 (PyList_Check(indexobj) || PyArray_Check(indexobj)) {\n\t\tmit->numiter = 1;\n\t\tarr = PyArray_FromAny(indexobj, &indtype, 0, 0, FORCECAST);\n\t\tif (arr == NULL) goto fail;\n\t\tmit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (mit->iters[0] == NULL) 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(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\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = new;\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\t/* Store the number of iterators actually converted */\n\t\t/* These will be mapped to actual axes at bind time */\n\t\tif (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)\n\t\t\tgoto fail;\n\t}\n\n ret:\n PyObject_GC_Track(mit);\n return (PyObject *)mit;\n \n fail:\n\tPy_XDECREF(arr);\n\tPy_XDECREF(mit->indexobj);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n PyObject_GC_Del(mit);\n\treturn NULL;\n}\n\n\n/* return unbound mapiter object */\n\nstatic PyObject *\narraymapiter_new(PyTypeObject *type, PyObject *args, PyObject *kwds) \n{\n\tPyObject *newtup, *res;\n\tint n;\n\n\tif (!PyTuple_Check(args)) {\n\t\tPyErr_BadInternalCall();\n\t\treturn NULL;\n\t}\n\n\tn = PyTuple_GET_SIZE(args);\n\t\n\tif (n < 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"must be initialized with >= 1 argument\");\n\t\treturn NULL;\n\t}\n\t\n\tif (n > 1) {\n\t\tnewtup = PyTuple_GetSlice(args, 0, n);\n\t\tif (newtup == NULL) return NULL;\n\t\tres = PyArray_MapIterNew(newtup);\n\t\tPy_DECREF(newtup);\n\t}\n\telse { /* n == 1 */\n\t\tnewtup = PyTuple_GET_ITEM(args, 0);\n\t\tres = PyArray_MapIterNew(newtup);\n\t}\n\n\treturn res; \t\n}\n\n\n/* Returns a 0-dim array holding the element desired */\n/*\nstatic PyObject *\narraymapiter_next(PyArrayMapIterObject *mit)\n{\n\tPyObject *ret;\n\tif (mit->ait == NULL) return NULL;\n\tif (mit->view) return NULL;\n\tif (mit->index < mit->size) {\n\t\tret = PyArray_ToScalar(mit->dataptr, mit->ait->ao);\n\t\tPyArray_MapIterNext(mit);\n\t\treturn ret;\n\t}\n return NULL;\n}\n*/\n\nstatic void\narraymapiter_dealloc(PyArrayMapIterObject *mit)\n{\n\tint i;\n PyObject_GC_UnTrack(mit);\n Py_XDECREF(mit->ait);\n\tPy_XDECREF(mit->indexobj);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n PyObject_GC_Del(mit);\n}\n\nstatic int\narraymapiter_traverse(PyArrayMapIterObject *mit, visitproc visit, void *arg)\n{\n\tint ret, i;\n if (mit->ait != NULL)\n if ((ret = visit((PyObject *)(mit->ait), arg)) != 0) \n\t\t\treturn ret;\t\n\n\tif (mit->iters != NULL) \n\t\tfor (i=0; inumiter; i++) \n\t\t\tif (mit->iters[i] != NULL) \n\t\t\t\tif ((ret=visit((PyObject *)mit->iters[i], \n\t\t\t\t\t arg)) != 0)\n\t\t\t\t\treturn ret;\n\n\tif (mit->indexobj != NULL)\n\t\tif ((ret = visit(mit->indexobj, arg)) != 0) return ret;\n\t\n return 0;\n}\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 MapIterNew must be \n that does not work. 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 char doc_mapiter_bind[] = \"obj.bind(a)\\n Bind an array to the \"\\\n\t\"mapiter object\";\n\nstatic PyObject *\nmapiter_bind(PyArrayMapIterObject *mit, PyObject *args)\n{\n\tPyArrayObject *arr;\n\n if (!PyArg_ParseTuple(args, \"O!\", &PyArray_Type, &arr)) return NULL;\n\n \tPyArray_MapIterBind(mit, arr);\n\n\tif (mit->ait == NULL) return NULL;\n\t\n \tPyArray_MapIterReset(mit);\n\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyMethodDef mapiter_methods[] = {\n\t{\"bind\", (PyCFunction)mapiter_bind, 1, doc_mapiter_bind},\n {NULL,\t\tNULL}\t\t\n};\n*/\n\n\nstatic PyTypeObject PyArrayMapIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"scipy.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 | Py_TPFLAGS_HAVE_GC,/* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)arraymapiter_traverse,\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, /*arraymapiter_next,*/\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 (newfunc)arraymapiter_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n\n};\n\n/** END of Subscript Iterator **/\n\n\n\n", "source_code_before": " /*\n Provide multidimensional arrays as a basic object type in python. \n\nBased on Original Numeric implementation\nCopyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\nwith contributions from many Numeric Python developers 1995-2004 *\n\nHeavily modified in 2005 with inspiration from Numarray \n\nby\n\nTravis Oliphant\nAssistant Professor at\nBrigham Young University \n\nmaintainer email: oliphant.travis@ieee.org\n\nNumarray design (which provided guidance) by \nSpace Science Telescope Institute \n (J. Todd Miller, Perry Greenfield, Rick White)\n\n*/\n\n/* $Id: arrayobject.c,v 1.59 2005/09/14 00:14:00 teoliphant Exp $ */\n\n/*\n#include \"Python.h\"\n#include \"structmember.h\"\n\n#define _MULTIARRAYMODULE\n#include \"Numeric3/arrayobject.h\"\n*/\n\n/* Helper functions */\n\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\n\nstatic intp\nPyArray_PyIntAsIntp(PyObject *o)\n{\n\tlonglong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr=NULL;\n\tPyArray_Typecode typecode = {PyArray_INTP, 0, 0};\n\tintp ret;\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\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\tarr = PyArray_CastToType((PyArrayObject *)o, &typecode);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tarr = PyArray_FromScalar(o, &typecode);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((intp *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\t\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONGLONG != SIZEOF_PY_INTPTR_T)\n\tif ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C intp\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (intp) long_value;\n}\n\n\nstatic PyObject *array_int(PyArrayObject *v);\n\nstatic int\nPyArray_PyIntAsInt(PyObject *o)\n{\n\tlong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr=NULL;\n\tPyArray_Typecode typecode = {PyArray_INT, 0, 0};\n\tint ret;\n\t\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\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\tarr = PyArray_CastToType((PyArrayObject *)o, &typecode);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tarr = PyArray_FromScalar(o, &typecode);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((int *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONG != SIZEOF_INT)\n\tif ((long_value < INT_MIN) || (long_value > INT_MAX)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C int\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (int) long_value;\n}\n\n\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\nstatic char *\nPyArray_Zero(PyArrayObject *arr)\n{\n char *zeroval;\n char *buf;\n int buf_len;\n PyObject *obj, *ret;\n\n zeroval = PyDataMem_NEW(arr->itemsize);\n if (zeroval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n if (PyArray_ISOBJECT(arr)) {\n obj=PyInt_FromLong((long) 0);\n memcpy(zeroval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return zeroval;\n }\n ret = PyObject_GetAttrString((PyObject *)arr, \"_zero\");\n if (ret != NULL) {\n if (PyObject_AsReadBuffer(ret, (const void **)&buf, \n &buf_len) < 0) {\n PyErr_SetString(PyExc_ValueError, \n \"_zero not returning \" \\\n \"writeable buffer\");\n Py_DECREF(ret);\n return NULL;\n }\n memcpy(zeroval, buf, buf_len);\n Py_DECREF(ret);\n }\n if (PyErr_Occurred()) PyErr_Clear();\n memset(zeroval, 0, arr->itemsize);\n return zeroval;\n}\n\nstatic char *\nPyArray_One(PyArrayObject *arr)\n{\n char *oneval;\n char *buf;\n int buf_len, ret2;\n PyObject *obj, *ret;\n\n oneval = PyDataMem_NEW(arr->itemsize);\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 ret = PyObject_GetAttrString((PyObject *)arr, \"_one\");\n if (ret != NULL) {\n if (PyObject_AsReadBuffer(ret, (const void **)&buf, \n &buf_len) < 0) {\n PyErr_SetString(PyExc_ValueError, \n \"_one not returning \" \\\n \"writeable buffer\");\n Py_DECREF(ret);\n PyDataMem_FREE(oneval);\n return NULL;\n }\n memcpy(oneval, buf, buf_len);\n Py_DECREF(ret);\n }\n if (PyErr_Occurred()) PyErr_Clear();\n\n ret2 = arr->descr->setitem(obj, oneval, arr);\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->itemsize;\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 *)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 { free(new_data); return NULL; }\n}\n\n/* end Helper functions */\n\n\nstatic PyObject *PyArray_New(PyTypeObject *, int nd, intp *, \n int, intp *, char *, 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. */\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/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\n\nstatic char *\nindex2ptr(PyArrayObject *mp, int i) \n{\n\tif (i==0 && (mp->nd == 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\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\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->copyswap;\n\tcopyswapn = dest->descr->copyswapn;\n\n elsize = dest->itemsize;\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->itemsize;\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\tPyArray_Typecode typecode;\n\n\n\ttypecode.type_num = dest->descr->type_num;\n\ttypecode.itemsize = dest->itemsize;\n\ttypecode.fortran = PyArray_ISFORTRAN(dest);\n\t\t\t\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n\t\t\t\t\t &typecode, 0,\n\t\t\t\t\t dest->nd, 0);\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\nstatic PyObject *\nPyArray_FromDimsAndDataAndDescr(int nd, int *d, \n PyArray_Descr *descr,\n char *data) {\n\tPyObject *ret;\n\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\n\tintp newd[MAX_DIMS];\n\t\n\tfor (i=0; itype_num, NULL, data, descr->elsize, \n\t\t\t CARRAY_FLAGS, NULL);\n#else\n\tret = PyArray_New(&PyArray_Type, nd, (intp *)d, \n descr->type_num, NULL, data, descr->elsize, \n\t\t\t CARRAY_FLAGS, NULL);\n#endif\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_FromDimsAndData(int nd, int *d, int type, char *data) \n{\n\tPyObject *ret;\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\t\n\tintp newd[MAX_DIMS];\n\n\tfor (i=0; iob_type, m1->nd, \n\t\t\t\t\t m1->dimensions,\n\t\t\t\t\t m1->descr->type_num,\n\t\t\t\t\t NULL, NULL, m1->itemsize,\n\t\t\t\t\t 0, (PyObject *)m1);\n\t\n if (PyArray_CopyInto(ret, m1) == -1) return NULL;\n\t\n return (PyObject *)ret;\n}\n\n\nstatic PyObject *array_item(PyArrayObject *, int);\n\nstatic PyObject *\nPyArray_Scalar(char *data, int type_num, int itemsize, int swap)\n{\n PyArray_Descr *descr;\n\tPyTypeObject *type;\n\tPyObject *obj;\t\n\tchar *destptr;\n PyArray_CopySwapFunc *copyswap;\n\n descr = PyArray_DescrFromType(type_num);\n if (descr == NULL) return NULL;\n type = descr->typeobj;\n copyswap = descr->copyswap;\n\tif (type_num == PyArray_STRING) \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_ISFLEXIBLE(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 {\n\t\t\tdestptr = PyDataMem_NEW(itemsize);\n\t\t\tif (destptr == NULL) {\n\t\t\t\tPyObject_Del(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tif (type_num == PyArray_UNICODE) {\n\t\t\t\tPyUnicode_AS_UNICODE(obj) = \\\n\t\t\t\t\t(Py_UNICODE *)destptr;\n\t\t\t\t((PyUnicodeObject*)obj)->length = itemsize / \\\n\t\t\t\t\tsizeof(Py_UNICODE);\n\t\t\t\t((PyUnicodeObject*)obj)->hash = -1;\n\t\t\t}\n\t\t\telse {\n\t\t\t\t((PyVoidScalarObject *)obj)->obval = destptr;\n\t\t\t\t((PyVoidScalarObject *)obj)->ob_size = itemsize;\n\t\t\t}\n\t\t}\n\t}\n\telse {\n\t\tdestptr = &(((PyScalarObject*)obj)->obval);\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*/\nstatic PyObject *\nPyArray_ToScalar(char *data, PyArrayObject *arr)\n{\n\tint type_num = arr->descr->type_num;\n\tint itemsize = arr->itemsize;\n int swap = !(PyArray_ISNOTSWAPPED(arr));\n\n\treturn PyArray_Scalar(data, type_num, itemsize, swap);\n}\n\n\n/* Return Python scalar if 0-d array object is encountered */\n\nstatic PyObject *\nPyArray_Return(PyArrayObject *mp) \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((PyObject *)mp) && 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*/\nstatic int \nPyArray_RegisterDataType(PyTypeObject *type)\n{\n\tPyArray_Descr *descr;\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 = malloc(sizeof(PyArray_Descr));\n\tmemcpy(descr, PyArray_DescrFromType(PyArray_VOID), \n\t sizeof(PyArray_Descr));\n\ttypenum = PyArray_USERDEF + PyArray_NUMUSERTYPES;\n\tdescr->type_num = typenum;\n\tdescr->typeobj = 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 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 frees the copy of the Descr_table already there.\n places a pointer to the new one into the slot.\n*/\nstatic int\nPyArray_RegisterDescrForType(int typenum, PyArray_Descr *descr)\n{\n\tPyArray_Descr *old;\n\tint i;\n\n\tif (!PyTypeNum_ISUSERDEF(typenum)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"data type not registered\");\n\t\treturn -1;\n\t}\n\told = userdescrs[typenum-PyArray_USERDEF];\n\tdescr->typeobj = old->typeobj;\n\tdescr->type_num = typenum;\n\n#define _NULL_CHECK(member) \\\n\tif (descr->member == NULL) descr->member = old->member\n\n\tfor (i=0; imember == 0) descr->member = old->member\n\n\t_ZERO_CHECK(kind);\n\t_ZERO_CHECK(type);\n\t_ZERO_CHECK(elsize);\n\t_ZERO_CHECK(alignment);\n#undef _ZERO_CHECK\n\n\tfree(old);\n\tuserdescrs[typenum-PyArray_USERDEF] = descr;\n\treturn 0;\n}\n\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 n3 = strlen((const char *)sep);\n if (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 \"\\\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->itemsize,\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->itemsize,\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 = strlen((const char *)format);\n while(it->index < it->size) {\n obj = self->descr->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\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->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\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 if (PyArray_TYPE(self) == PyArray_OBJECT) {\n PyErr_SetString(PyExc_ValueError, \"a string for the data\"\\\n\t\t\t\t\"in an object array is not appropriate\");\n return NULL;\n }\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->itemsize;\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 != NULL)) {\n\t\t/* Free internal references if an Object array */\n\t\tPyArray_XDECREF(self);\n\n PyDataMem_FREE(self->data);\n }\n\t\n if (self->dimensions != NULL) {\n PyDimMem_FREE(self->dimensions); \n\t}\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\n\nstatic PyObject *\narray_item(PyArrayObject *self, int i) \n{\n char *item;\n PyArrayObject *r;\n\n\n\tif(self->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n if ((item = index2ptr(self, i)) == NULL) return NULL;\n\n\tr = (PyArrayObject *)PyArray_New(self->ob_type, \n\t\t\t\t\t self->nd-1, self->dimensions+1, \n\t\t\t\t\t self->descr->type_num, \n\t\t\t\t\t self->strides+1, item, \n\t\t\t\t\t self->itemsize, self->flags,\n\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_item(self, i));\n}\n\n\nstatic int \narray_ass_item(PyArrayObject *self, int 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\n if (i < 0) i = i+self->dimensions[0];\n\n if (self->nd > 1) {\n if((tmp = (PyArrayObject *)array_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->setitem(v, item, self) == -1) return -1;\n return 0;\n}\n\n/* -------------------------------------------------------------- */\nstatic int\nslice_coerce_index(PyObject *o, int *v)\n{\n\t*v = PyArray_PyIntAsInt(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, int length,\n int *start, int *stop, int *step,\n intp *slicelength)\n{\n\tint 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 int\nparse_subindex(PyObject *op, int *step_size, intp *n_steps, int max)\n{\n\tint 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\tint 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_PyIntAsInt(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, start, offset, n_add, n_pseudo;\n int step_size;\n\tintp n_steps;\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, *tup;\n\tint n1, n2, n3, val;\n\tint i;\n\n\ttup = PyTuple_New(mit->nd);\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\tPyTuple_SET_ITEM(tup, i++, PyInt_FromLong((long)val++));\n\tval = 0;\n\twhile(val < n1)\n\t\tPyTuple_SET_ITEM(tup, i++, PyInt_FromLong((long)val++));\n\tval = n1+n2;\n\twhile(val < n3)\n\t\tPyTuple_SET_ITEM(tup, i++, PyInt_FromLong((long)val++));\n\n\tnew = PyArray_Transpose(*ret, tup);\n\tPy_DECREF(tup);\n\tPy_DECREF(*ret);\n\t*ret = (PyArrayObject *)new;\n}\n\n\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\tret = (PyArrayObject *)\\\n\t\tPyArray_New(temp->ob_type, mit->nd, mit->dimensions, \n\t\t\t temp->descr->type_num, NULL, NULL, \n\t\t\t temp->itemsize, \n\t\t\t PyArray_ISFORTRAN(temp),\n\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\treturn NULL;\n\tindex = it->size;\n\tswap = ((temp->flags & NOTSWAPPED) != (ret->flags & NOTSWAPPED));\n copyswap = ret->descr->copyswap;\n\tPyArray_MapIterReset(mit);\n\twhile (index--) {\n copyswap(it->dataptr, mit->dataptr, swap, ret->itemsize);\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\tPyArray_Typecode typecode = {0, 0, 0};\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Unbound Map Iterator */\n\tif (mit->ait == NULL) return -1;\n\n\ttypecode.type_num = mit->ait->ao->descr->type_num;\n\ttypecode.itemsize = mit->ait->ao->itemsize;\n\n\tarr = PyArray_FromAny(op, &typecode, \n\t\t\t 0, 0, FORCECAST);\n\tif (arr == NULL) return -1;\n\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, (PyArrayObject **)&arr);\n\t\t}\n\t}\n\t\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) \n\t\treturn -1;\n\n\tindex = mit->size;\n\tswap = ((mit->ait->ao->flags & NOTSWAPPED) != \\\n\t\t(PyArray_FLAGS(arr) & NOTSWAPPED));\n\n copyswap = PyArray_DESCR(arr)->copyswap;\n\tPyArray_MapIterReset(mit);\n /* Need to decref OBJECT arrays */\n if (PyTypeNum_ISOBJECT(typecode.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 copyswap(mit->dataptr, NULL, swap, \n sizeof(PyObject *));\n PyArray_MapIterNext(mit);\n PyArray_ITER_NEXT(it);\n if (it->index == it->size)\n PyArray_ITER_RESET(it);\n }\n return 0;\n }\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\treturn 0;\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 0-dimensional arrays */\n\nstatic PyObject *\narray_subscript(PyArrayObject *self, PyObject *op) \n{\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n\tintp offset;\n int nd, i;\n PyArrayObject *other;\n\tPyArrayMapIterObject *mit;\n\n if (PyArray_IsScalar(op, Integer) || PyInt_Check(op) || \\\n PyLong_Check(op)) {\n intp value;\n value = PyArray_PyIntAsIntp(op);\n if (PyErr_Occurred())\n PyErr_Clear();\n else if (value >= 0) {\n if (value <= MAX_INT)\n return array_item(self, (int) value);\n }\n else if (value < 0) {\n if (value >= -MAX_INT) {\n if (self->nd > 0) value += self->dimensions[0];\n return array_item(self, (int) value);\n }\n }\n }\n\n\tif (PyArrayMapIter_Check(op)) {\n\t\tmit = (PyArrayMapIterObject *)op;\n\t\t/* bind to current array */\n\t\tPyArray_MapIterBind(mit, self);\n\t\t\n\t\t/* If the mapiterator was created with standard indexing\n\t\t behavior, fall through to view-based code */\n\t\tif (!mit->view) return PyArray_GetMap(mit);\n\t\top = mit->indexobj;\n\t}\n\telse { /* wrap arguments into a mapiter object */\n\t\tmit = (PyArrayMapIterObject *)PyArray_MapIterNew(op);\n\t\tif (mit == NULL) return NULL;\n\t\tif (!mit->view) { /* fancy indexing */\n\t\t\tPyArray_MapIterBind(mit, self);\n\t\t\tother = (PyArrayObject *)PyArray_GetMap(mit);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn (PyObject *)other;\n\t\t}\n\t\tPy_DECREF(mit);\n\t}\n\n\ti = PyArray_PyIntAsInt(op);\n\tif (!error_converting(i)) {\n\t\tif (i < 0 && self->nd > 0) i = i+self->dimensions[0];\n\t\treturn array_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\tif ((other = (PyArrayObject *)\t\t\t\t\t\\\n\t PyArray_New(self->ob_type, nd, dimensions, self->descr->type_num,\n\t\t\t strides, self->data+offset, \n\t\t\t self->itemsize, self->flags,\n\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 \narray_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op) \n{\n int ret, 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\n\tif (PyArrayMapIter_Check(index)) {\n\t\tmit = (PyArrayMapIterObject *)index;\n\t\t/* bind behavior to current array */\n\t\tPyArray_MapIterBind(mit, self);\n\t\t\t\n\t\t/* fall through if standard view-based map iterator */\n\t\tif (!mit->view) return PyArray_SetMap(mit, op);\n\t\tindex = mit->indexobj;\n\t}\n\telse {\n\t\tmit = (PyArrayMapIterObject *)PyArray_MapIterNew(index);\n\t\tif (mit == NULL) return -1;\n\t\tif (!mit->view) {\n\t\t\tPyArray_MapIterBind(mit, self);\n\t\t\tret = PyArray_SetMap(mit, op);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn ret;\n\t\t}\n\t\tPy_DECREF((PyObject*)mit);\n\t}\n\n\ti = PyArray_PyIntAsInt(index);\n\tif (!error_converting(i)) {\n\t\treturn array_ass_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 ret = PyArray_CopyObject(tmp, op);\n Py_DECREF(tmp);\n\t\n return ret;\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 \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\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}\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}\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 PyObject *args, *ret;\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n args = Py_BuildValue(\"(OO)\", m1, m2);\n ret = PyObject_Call(op, args, NULL);\n Py_DECREF(args);\n return ret;\n}\n\nstatic PyObject *\nPyArray_GenericUnaryFunction(PyArrayObject *m1, PyObject *op) \n{\n PyObject *args, *ret;\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n args = Py_BuildValue(\"(O)\", m1);\n ret = PyObject_Call(op, args, NULL);\n Py_DECREF(args);\n return ret;\n}\n\nstatic PyObject *\nPyArray_GenericInplaceBinaryFunction(PyArrayObject *m1, \n\t\t\t\t PyObject *m2, PyObject *op) \n{\n PyObject *args, *ret;\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n args = Py_BuildValue(\"(OOO)\", m1, m2, m1);\n ret = PyObject_Call(op, args, NULL);\n Py_DECREF(args);\n return ret;\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_all_nonzero(PyArrayObject *mp) \n{\n\tintp index;\n\tPyArrayIterObject *it;\n\tBool anyTRUE = 0;\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->nonzero(it->dataptr, mp)) {\n\t\t\tanyTRUE = 1;\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 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->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->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->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->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->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_all_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 r = (PyArrayObject *)\\\n\t\tPyArray_New(self->ob_type, self->nd, self->dimensions, \n\t\t\t self->descr->type_num, self->strides, data,\n\t\t\t self->itemsize, 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 any(self == el) */\n\n return PyObject_RichCompareBool((PyObject *)self, el, Py_EQ);\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 *)realloc(*string, *max_n); }\n\t\n if (nd == 0) {\n\t\t\n if ((op = descr->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\tfree(string); return NULL; \n\t}\n\t\n\tif (PyArray_ISFLEXIBLE(self)) {\n\t\tchar buf[100];\n\t\tsnprintf(buf, sizeof(buf), \"%d\", self->itemsize);\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 free(string);\n return ret;\n}\n\nstatic PyObject *PyArray_StrFunction=NULL;\nstatic PyObject *PyArray_ReprFunction=NULL;\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\n\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) \n{\n PyObject *array_other, *result;\n\n switch (cmp_op) \n {\n case Py_LT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less);\n case Py_LE:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less_equal);\n case Py_EQ:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then return the integer\n\t\t\t object 0. This fixes code that used to\n\t\t\t allow equality comparisons between arrays\n\t\t\t and other objects which would give a result\n\t\t\t of 0\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n result = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.equal);\n /* If the comparison results in NULL, then the \n\t\t\t two array objects can not be compared together so \n\t\t\t return zero \n */\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n return result;\n case Py_NE:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then objects cannot be \n\t\t\t compared and cannot be equal, therefore, \n\t\t\t return True;\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n result = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.not_equal);\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n return result;\n case Py_GT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.greater);\n case Py_GE:\n return PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t other, \n\t\t\t\t\t \t n_ops.greater_equal);\n }\n return NULL;\n}\n\nstatic PyObject *\n_check_axis(PyArrayObject *arr, int *axis, int flags)\n{\n\tPyObject *temp;\n\tint n = arr->nd;\n\n\tif ((*axis >= MAX_DIMS) || (n==0)) {\n\t\ttemp = PyArray_Ravel(arr,0);\n\t\t*axis = 0;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_FromAny((PyObject *)arr, NULL, \n\t\t\t\t\t 0, 0, flags);\n\t\t\tif (temp == NULL) return NULL;\n\t\t}\n\t\telse {\n\t\t\tPy_INCREF(arr);\n\t\t\ttemp = (PyObject *)arr;\n\t\t}\n\t}\n\tif (*axis < 0) *axis += n;\n\tif ((*axis < 0) || (*axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", *axis);\n\t\tPy_DECREF(temp);\n\t\treturn NULL;\n\t}\n\treturn temp;\n}\n\n#include \"arraymethods.c\"\n\n/* Lifted from numarray */\nstatic PyObject *\nPyArray_IntTupleFromIntp(int len, intp *vals)\n{\n\tint i;\n PyObject *intTuple = PyTuple_New(len);\n if (!intTuple) goto fail;\n for(i=0; ind == 0) return 1;\n\tsd = ap->itemsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\n\t}\n\treturn 1;\n}\n\n\nstatic int \n_IsFortranContiguous(PyArrayObject *ap) \n{\n\tint sd;\n\tint i;\n\t\n\tif (ap->nd == 0) return 1;\n\tsd = ap->itemsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i=0; i< ap->nd; ++i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\n\t}\n\treturn 1;\n}\n\nstatic int\n_IsAligned(PyArrayObject *ap) \n{\n\tint i, alignment, aligned=1;\n\tintp ptr;\n\tint type = ap->descr->type_num;\n\n\tif ((type == PyArray_STRING) || (type == PyArray_VOID))\n\t\treturn 1;\n\n\talignment = ap->descr->alignment;\n\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\tPyBufferProcs *pb;\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\tpb = base->ob_type->tp_as_buffer;\n\tif (pb == NULL || pb->bf_getwritebuffer == NULL)\n\t\treturn FALSE;\n\t\n\treturn TRUE;\n}\n\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\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not \n walk outside of the memory implied by either numbytes or\n a single segment array of the provided dimensions and element size if\n numbytes is 0 */\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, \n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\t\n\tif (numbytes == 0) \n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\t\n\tfor (i=0; i numbytes) {\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\treturn TRUE;\n\t\n}\n\n\n/* This is the main array creation routine. */\n\n/* Flags argument has multiple related meanings \n depending on data and strides: \n\n If data is given, then flags is flags associated with data. \n If strides is not given, then a contiguous strides array will be created\n and the CONTIGUOUS bit will be set. If the flags argument \n has the FORTRAN bit set, then a FORTRAN-style strides array will be\n created (and of course the FORTRAN flag bit will be set). \n\n If data is not given but created here, then flags will be DEFAULT_FLAGS\n and a non-zero flags argument can be used to indicate a FORTRAN style\n array is desired. \n*/\n\nstatic intp\n_array_fill_strides(intp *strides, intp *dims, int nd, intp itemsize, \n\t\t int inflag, int *objflags) \n{\n\tint i;\n\t/* Only make Fortran strides if not contiguous as well */\n\tif ((inflag & FORTRAN) && !(inflag & CONTIGUOUS)) {\n\t\tfor (i=0; i 1) *objflags &= ~CONTIGUOUS;\n\t\telse *objflags |= CONTIGUOUS;\n\t}\n\telse {\n\t\tfor (i=nd-1;i>=0;i--) {\n\t\t\tstrides[i] = itemsize;\n\t\t\titemsize *= dims[i] ? dims[i] : 1;\n\t\t}\n\t\t*objflags |= CONTIGUOUS;\n\t\tif (nd > 1) *objflags &= ~FORTRAN;\n\t\telse *objflags |= FORTRAN;\n\t}\n\treturn itemsize;\n}\n\n\t\nstatic PyObject *\nPyArray_New(PyTypeObject *subtype, int nd, intp *dims, int type_num,\n intp *strides, char *data, int itemsize, int flags,\n\t PyObject *obj)\n{\n\tPyArrayObject *self;\n\tPyArray_Descr *descr;\n\tregister int i;\n\tintp sd, temp=-1;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\tif (descr == NULL) return NULL;\n\n\tif (nd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"number of dimensions must be >=0\");\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 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\treturn NULL;\n\t\t}\n\t}\n\t\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) return NULL;\t\n\tself->descr = descr;\n\tself->dimensions = 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\n\tif (PyTypeNum_ISFLEXIBLE(type_num)) {\n\t\tif (itemsize < 1) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"type must provide an itemsize\");\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn NULL;\n\t\t}\n\t\tself->itemsize = itemsize;\n\t\t/* Guarantee that these kind of arrays are never byteswapped\n\t\t unknowingly. \n\t\t*/\n\t\tif (type_num != PyArray_UNICODE)\n\t\t\tself->flags |= NOTSWAPPED;\n\t}\n\telse self->itemsize = descr->elsize; \n\t\t\n\tsd = self->itemsize;\n\t\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn PyErr_NoMemory();\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\tPyDimMem_FREE(self->dimensions);\n\t\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\t\treturn NULL;\n\t\t\t}\t\t\t\t\n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t}\n \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 (a.data) doesn't work\n\t\t as it should. */\n\n\t\tif (sd==0) sd = sizeof(intp);\n\n\t\tif ((data = PyDataMem_NEW(sd))==NULL) {\n\t\t\tPyDimMem_FREE(self->dimensions);\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn PyErr_NoMemory();\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\n\t\t/* It is bad to have unitialized OBJECT pointers */\n\t\t/* We shouldn't need to check for the OBJECT Letter\n\t\t but perhaps it's best. */\n\t\tif (type_num == PyArray_OBJECT || \\\n\t\t type_num == PyArray_OBJECTLTR) {\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\tself->nd = nd;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\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;\n\t\tif (temp==-1) { /* 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\tres = PyObject_CallMethod((PyObject *)self, \n\t\t\t\t\t \"__array_finalize__\",\n\t\t\t\t\t \"O\", obj);\n\t\tif (res == NULL) {\n\t\t\tPyDimMem_FREE(self->dimensions);\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn NULL;\n\t\t}\n\t\telse Py_DECREF(res);\n\t}\n\n\treturn (PyObject *)self;\n}\n\n\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\n newsize = PyArray_MultiplyList(new_dimensions, new_nd);\n\n if (newsize == 0) {\n PyErr_SetString(PyExc_ValueError, \n \"newsize is zero; cannot delete an array \"\\\n \"in this way\");\n return NULL;\n }\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 = (((PyObject *)self)->ob_refcnt);\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\n\t\t/* Reallocate space if needed */\n\t\tnew_data = PyDataMem_RENEW(self->data, \n\t\t\t\t\t newsize*(self->itemsize));\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->itemsize;\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->itemsize;\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 */\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; idataptr, fromptr, itemsize);\n\t\t\tPyArray_ITER_NEXT(iter);\n\t\t}\n\n\t\tPy_DECREF(iter);\n\t\tPy_DECREF(behaved);\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\", \"strides\", \n \"swap\", \"fortran\", NULL};\n\tint itemsize = 0;\n\tPyArray_Typecode typecode = {PyArray_NOTYPE, 0, 0};\n\tint type_num = PyArray_NOTYPE;\n PyArray_Dims dims = {NULL, 0};\n PyArray_Dims strides = {NULL, 0};\n PyArray_Chunk buffer;\n\tint fortran = 0;\n int swapped = 0;\n\tPyArrayObject *ret;\n\n\tbuffer.ptr = NULL; \n /* Usually called with shape and type\n but can also be called with buffer, strides, and swapped info\n */\n\n\t/* For now, let's just use this to create an empty, contiguous \n\t array of a specific type and shape. \n\t*/\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&O&ii\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &dims, \n PyArray_TypecodeConverter,\n\t\t\t\t\t &typecode, \n PyArray_BufferConverter,\n &buffer,\n &PyArray_IntpConverter, \n &strides,\n &swapped, &fortran)) \n\t\treturn NULL;\n\t\n if (typecode.type_num ==PyArray_NOTYPE) {\n\t\ttypecode.type_num = PyArray_DOUBLE;\n\t\ttypecode.itemsize = sizeof(double);\n\t}\n\ttype_num = typecode.type_num;\n\titemsize = typecode.itemsize;\n\n\n if (dims.ptr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"need to give a \"\\\n \"valid shape as the first argument\");\n goto fail;\n }\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)PyArray_New(subtype, (int)dims.len, \n dims.ptr, type_num,\n NULL, NULL, itemsize, \n fortran, NULL);\n \n if (ret == NULL) goto fail;\n if (type_num == PyArray_OBJECT) { /* place Py_None */\n PyArray_FillObjectArray(ret, Py_None);\n }\n }\n else { /* buffer given -- use it */\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = buffer.len / itemsize;\n }\n else if (buffer.len < itemsize* \\\n PyArray_MultiplyList(dims.ptr, dims.len)) {\n PyErr_SetString(PyExc_TypeError, \n \"buffer is too small for \" \\\n \"requested array\");\n goto fail;\n }\n if (strides.ptr != NULL) {\n\t\t\tif (strides.len != dims.len) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides, if given, must be \"\\\n\t\t\t\t\t\t\"the same length as shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CheckStrides(itemsize, strides.len, \n\t\t\t\t\t\t buffer.len,\n\t\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides is incompatible \"\\\n\t\t\t\t\t\t\"with shape of requested\"\\\n\t\t\t\t\t\t\"array and size of buffer\");\n\t\t\t\tgoto fail;\n\t\t\t}\n }\n if (type_num == PyArray_OBJECT) {\n PyErr_SetString(PyExc_TypeError, \"cannot construct \"\\\n \"an object array from buffer data\");\n goto fail;\n }\n /* get writeable and aligned */\n if (fortran) buffer.flags |= FORTRAN;\n if (!(swapped)) buffer.flags |= NOTSWAPPED;\n ret = (PyArrayObject *)PyArray_New(subtype, dims.len, \n dims.ptr, type_num,\n strides.ptr,\n (char *)buffer.ptr, \n itemsize, \n buffer.flags, NULL); \n if (ret == 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 PyArray_Return(ret);\n \n fail:\n if (dims.ptr) PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return NULL;\n}\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 static PyObject *module=NULL;\n\n if (module==NULL) {\n module = PyImport_ImportModule(\"scipy.base._internal\");\n if (module == NULL) return NULL;\n }\n return PyObject_CallMethod(module, \"flagsobj\", \"Oii\", \n self, self->flags, 0);\n}\n\n/*\nstatic int\narray_flags_set(PyArrayObject *self, PyObject *obj) \n{\n\tint flagback = self->flags;\n\n if (PyDict_Check(obj)) {\n PyObject *new;\n\t\tnew = PyDict_GetItemString(obj, \"ALIGNED\");\n\t\tif (new) {\n\t\t\tif (PyObject_Not(new)) self->flags &= ~ALIGNED;\n\t\t\telse if (_IsAligned(self)) self->flags |= ALIGNED;\n\t\t\telse {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"cannot set aligned flag of \" \\\n\t\t\t\t\t\t\"mis-aligned array to True\");\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t}\n new = PyDict_GetItemString(obj, \"UPDATEIFCOPY\");\n if (new) {\n if (PyObject_Not(new)) {\n self->flags &= ~UPDATEIFCOPY;\n Py_DECREF(self->base);\n self->base = NULL;\n }\n else {\n\t\t\t\tself->flags = flagback;\n PyErr_SetString(PyExc_ValueError, \n \"cannot set UPDATEIFCOPY \" \\\n \"flag to True\");\n return -1;\n }\n }\n new = PyDict_GetItemString(obj, \"WRITEABLE\");\n if (new) {\n\t\t\tif (PyObject_IsTrue(new)) {\n\t\t\t\tif (_IsWriteable(self)) {\n\t\t\t\t\tself->flags |= WRITEABLE;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tself->flags = flagback;\n\t\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\t\"cannot set \"\t\\\n\t\t\t\t\t\t\t\"WRITEABLE \"\t\\\n\t\t\t\t\t\t\t\"flag to True of \"\\\n\t\t\t\t\t\t\t\"this array \");\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n else\n self->flags &= ~WRITEABLE;\n }\n new = PyDict_GetItemString(obj, \"NOTSWAPPED\");\n if (new) {\n if (PyObject_IsTrue(new))\n self->flags |= NOTSWAPPED;\n else {\n self->flags &= ~NOTSWAPPED;\n\t\t\t}\n\t\t}\n return 0;\n }\n PyErr_SetString(PyExc_ValueError, \n \"object must be a dictionary\");\n return -1;\n}\n*/\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\tif (!PyTuple_Check(val)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"shape must be a tuple\");\n\t\treturn -1;\n\t}\n\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\n\t\n\tif (self->nd > 0) { /* Free old dimensions and strides */\n\t\tPyDimMem_FREE(self->dimensions);\n\t}\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;\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\treturn -1;\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->itemsize;\n\t\n\tif (!PyArray_CheckStrides(self->itemsize, self->nd, numbytes, \n\t\t\t\t self->dimensions, newstrides.ptr)) {\n\t\tPyErr_SetString(PyExc_ValueError, \"strides is not \"\\\n\t\t\t\t\"compatible with available memory\");\n\t\treturn -1;\n\t}\n\tmemcpy(self->strides, newstrides.ptr, sizeof(intp)*newstrides.len);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\treturn 0;\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->itemsize);\n}\n\nstatic PyObject *\narray_size_get(PyArrayObject *self)\n{\n\tlonglong size=PyArray_SIZE(self);\n\tif (size > MAX_INT || size < MIN_INT)\n\t\treturn PyLong_FromLongLong((longlong) size);\n\telse \n\t\treturn PyInt_FromLong((long) size);\n}\n\n\nstatic PyObject *\narray_typechar_get(PyArrayObject *self)\n{\n\tif PyArray_ISFLEXIBLE(self) \n\t\treturn PyString_FromFormat(\"%c%d\", (self->descr->type),\n\t\t\t\t\t self->itemsize);\n\telse \n\t\treturn PyString_FromStringAndSize(&(self->descr->type), 1);\n}\n\nstatic PyObject *\narray_typestr_get(PyArrayObject *self)\n{\n\tstatic char endians[] = \"<>\";\n\tchar endian;\n\tint which;\n\tunsigned long val = 1;\n\tchar *s;\n\tchar basic_=self->descr->kind;\n\n\ts = (char *)&val; /* s[0] == 0 implies big-endian */\n\twhich = (PyArray_ISNOTSWAPPED(self) ? 0 : 1);\n\tif (s[0] == 0) which = 1 - which;\n\tendian = endians[which]; \n\t\n\tif ((basic_==PyArray_VOIDLTR) || (basic_==PyArray_STRINGLTR) || \\\n\t (basic_==PyArray_OBJECTLTR) || (self->itemsize == 1))\n\t\treturn PyString_FromFormat(\"|%c%d\", basic_, self->itemsize);\n\telse\n\t\treturn PyString_FromFormat(\"%c%c%d\", endian, basic_,\n\t\t\t\t\t self->itemsize);\n}\n\nstatic PyObject *\narray_descr_get(PyArrayObject *self)\n{\n\tPyObject *res;\n\tPyObject *dobj;\n\n\t/* hand this off to the typeobject */\n\t/* or give default */\n\tif (PyArray_ISUSERDEF(self)) {\n\t\tres = PyObject_GetAttrString((PyObject *)self->descr->typeobj, \n\t\t\t\t\t \"__array_descr__\");\n\t\tif (res) return res;\n\t\tPyErr_Clear();\n\t}\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\n\nstatic PyObject *\narray_type_get(PyArrayObject *self)\n{\n\treturn PyArray_TypeObjectFromType(self->descr->type_num);\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*/\n\nstatic int\narray_type_set(PyArrayObject *self, PyObject *arg)\n{\n PyArray_Typecode newtype = {PyArray_NOTYPE, 0, 0};\n intp newdim;\n int index;\n char *msg = \"new type not compatible with array.\";\n\n if ((PyArray_TypecodeConverter(arg, &newtype) < 0) ||\n newtype.type_num == PyArray_NOTYPE) {\n PyErr_SetString(PyExc_TypeError, \"invalid type for array\");\n return -1;\n }\n if (!(PyArray_ISONESEGMENT(self) ||\t\t\\\n\t (newtype.itemsize != self->itemsize))) {\n PyErr_SetString(PyExc_ValueError, msg);\n return -1; \n }\n\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\n if (newtype.itemsize < self->itemsize) {\n /* if it is compatible increase the size of the dimension\n at end (or at the front for FORTRAN)\n */\n if (self->itemsize % newtype.itemsize != 0) {\n PyErr_SetString(PyExc_ValueError, msg);\n return -1;\n }\n newdim = self->itemsize / newtype.itemsize;\n\t\tself->dimensions[index] *= newdim;\n self->strides[index] = newtype.itemsize;\n\t}\n \n else if (newtype.itemsize > self->itemsize) {\n \n /* Determine if last (or first if FORTRAN) dimension\n is compatible */\n\n\t\tnewdim = self->dimensions[index] * self->itemsize;\n if ((newdim % newtype.itemsize) != 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, msg);\n return -1;\n }\n\t\t\n self->dimensions[index] = newdim / newtype.itemsize;\n self->strides[index] = newtype.itemsize;\n\t\t\n }\n\t\n \n /* fall through -- adjust type*/\n\n self->descr = PyArray_DescrFromType(newtype.type_num);\n self->itemsize = newtype.itemsize;\n PyArray_UpdateFlags(self, ALIGNED);\n return 0;\n\n}\n\n\n\nstatic PyObject *\narray_base_get(PyArrayObject *self)\n{\n\tif (self->base == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\telse {\n\t\tPy_INCREF(self->base);\n\t\treturn self->base;\n\t}\n}\n\n\nstatic PyObject *\narray_real_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *)ret;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n}\n\n\nstatic int\narray_real_set(PyArrayObject *self, PyObject *val)\n{\n\tPyArrayObject *ret;\n\tPyArrayObject *new;\n\tint rint;\n\n\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0);\n\tif (new == NULL) return -1;\n\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) 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\treturn rint;\n}\n\nstatic PyObject *\narray_imag_get(PyArrayObject *self)\n{\t\n\tPyArrayObject *ret;\n\tint itemsize;\n\tint typenum;\n PyArray_Typecode type;\n\t\n\ttype.type_num = self->descr->type_num;\n\ttype.itemsize = self->itemsize;\n\ttype.fortran = PyArray_ISFORTRAN(self);\n\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\titemsize = self->itemsize >> 1;\n\t\ttypenum = self->descr->type_num - PyArray_NUM_FLOATTYPE;\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 typenum,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data + itemsize,\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\tret = (PyArrayObject *)PyArray_Zeros(self->nd, \n\t\t\t\t\t\t self->dimensions, &type);\n\t\tret->flags &= ~WRITEABLE;\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic int\narray_imag_set(PyArrayObject *self, PyObject *val)\n{\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyArrayObject *ret;\n\t\tPyArrayObject *new;\n\t\tint rint;\n\n\t\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0); \n\t\tif (new == NULL) return -1;\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides+ \\\n\t\t\t\t\t\t (self->itemsize >> 1) ,\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) {\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_Typecode typecode;\n int swap;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode.type_num = self->descr->type_num;\n\ttypecode.itemsize = self->itemsize;\n\ttypecode.fortran = PyArray_ISFORTRAN(self);\n\t\n\tarr = PyArray_FromAny(val, &typecode, \n\t\t\t 0, 0, FORCECAST);\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->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 copyswap(selfit->dataptr, NULL, swap, \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->itemsize);\n copyswap(selfit->dataptr, NULL, swap, self->itemsize);\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\t{\"base\",\n\t (getter)array_base_get,\n\t NULL,\n\t \"base object\"},\n {\"dtype\", \n\t (getter)array_type_get, \n\t (setter)array_type_set,\n\t \"get array type class\"},\n\t{\"dtypechar\",\n\t (getter)array_typechar_get,\n\t NULL,\n\t \"get array type character code\"},\n\t{\"dtypestr\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"get array type string\"},\n {\"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_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\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\n\nstatic char Arraytype__doc__[] = \n \"A array object represents a multidimensional, homogeneous array\\n\"\n\t\" of basic values. Arrays are sequence, mapping and numeric\\n\"\n\t\" objects. More information is available in the scipy module and\\n\"\n\t\" by looking at the methods and attributes of an array.\";\n\nstatic PyTypeObject PyBigArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"scipy.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 \n offsetof(PyArrayObject, weakreflist), /*tp_weaklistoffset */\n\n /* Iterator support (use standard) */\n\n (getiterfunc)0, \t\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 0,\t /* tp_alloc */ \n (newfunc)array_new,\t\t /* tp_new */\n 0,\t \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 \"scipy.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) \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 if (PySequence_Length(s) == 0) \n\t\treturn 1;\n\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);\n\t\tif(d >= 0) d++;\n\t}\n Py_DECREF(e);\n return d;\n}\n\nstatic int\ndiscover_itemsize(PyObject *s, int nd, int *itemsize) \n{\n\tint n, r, i;\n\tPyObject *e;\n\t\n\tn = PyObject_Length(s);\n\n\tif ((nd == 0) || PyString_Check(s) ||\t\t\\\n\t PyUnicode_Check(s) || PyBuffer_Check(s)) {\n\t\tif PyUnicode_Check(s) \n\t\t\t*itemsize = MAX(*itemsize, sizeof(Py_UNICODE)*n);\n\t\telse\n\t\t\t*itemsize = MAX(*itemsize, n);\n\t\treturn 0;\n\t}\n\tfor (i=0; i n_lower) n_lower = d[1];\n }\n d[1] = n_lower;\n\t\n return 0;\n}\n\nstatic void\n_array_small_type(int chktype, int mintype, int chksize, int minsize, \n\t\t PyArray_Typecode *outtype)\n{\n\touttype->type_num = MAX(chktype, mintype);\n\tif (PyTypeNum_ISFLEXIBLE(outtype->type_num) &&\t\\\n\t PyTypeNum_ISFLEXIBLE(mintype)) {\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 == PyArray_STRING) {\n\t\t\touttype->itemsize = MAX(chksize, 2*minsize);\n\t\t}\n\t\telse {\n\t\t\touttype->itemsize = MAX(chksize, minsize);\n\t\t}\n\t}\n\telse {\n\t\touttype->itemsize = chksize;\n\t}\n\treturn;\t\n}\n\nstatic void\n_array_find_type(PyObject *op, PyArray_Typecode *minitype, \n\t\t PyArray_Typecode *outtype, int max)\n{\n int l;\n PyObject *ip;\n\tint chktype=0;\n\tint chksize=0;\n\tint mintype, minsize;\n\n\tif (minitype == NULL) {\n\t\tmintype = PyArray_BOOL;\n\t\tminsize = sizeof(Bool);\n\t}\n\telse {\n\t\tmintype = minitype->type_num;\n\t\tminsize = minitype->itemsize;\n\t}\n\n \n if (max < 0 || mintype == -1) goto deflt;\n\t\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_TYPE(op);\n\t\tchksize = PyArray_ITEMSIZE(op);\n\t\tgoto finish;\n\t}\n\t\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tPyArray_TypecodeFromScalar(op, outtype);\n\t\tchktype = outtype->type_num;\n\t\tchksize = outtype->itemsize;\n\t\tgoto finish;\n\t}\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_TYPE(ip);\n\t\t\tchksize = PyArray_ITEMSIZE(ip);\n\t\t\tgoto finish;\n\t\t}\n } \n\t\n\tif (PyObject_HasAttrString(op, \"__array_typestr__\")) {\n\t\tint swap=0, res;\n\t\tip = PyObject_GetAttrString(op, \"__array_typestr__\");\n\t\tif (ip && PyString_Check(ip)) {\n\t\t\tres = _array_typecode_fromstr(PyString_AS_STRING(ip), \n\t\t\t\t\t\t &swap, outtype); \n\t\t\tif (res >= 0) {\n\t\t\t\tPy_DECREF(ip);\n\t\t\t\tchktype = outtype->type_num;\n\t\t\t\tchksize = outtype->itemsize;\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t}\n\t\tPy_XDECREF(ip);\n\t}\n\n if (PyString_Check(op)) {\n\t\tchktype = PyArray_STRING;\n\t\tchksize = PyString_GET_SIZE(op);\n\t\tgoto finish;\n }\n\n\tif (PyUnicode_Check(op)) {\n\t\tchktype = PyArray_UNICODE;\n\t\tchksize = PyUnicode_GET_DATA_SIZE(op);\n\t\tgoto finish;\n\t}\n\n\tif (PyBuffer_Check(op)) {\n\t\tchktype = PyArray_VOID;\n\t\tchksize = op->ob_type->tp_as_sequence->sq_length(op);\n\t\tPyErr_Clear();\n\t\tgoto finish;\n\t}\n\n\tif (PyInstance_Check(op)) goto deflt;\n\t\n if (PySequence_Check(op)) {\n\t\tPyArray_Typecode newtype;\n\t\tnewtype.type_num = mintype;\n\t\tnewtype.itemsize = minsize;\n\t\tnewtype.fortran = 0;\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 && mintype == 0) {\n\t\t\tnewtype.type_num = PyArray_INTP;\n\t\t\tnewtype.itemsize = sizeof(intp);\n\t\t}\n while (--l >= 0) {\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\t_array_find_type(ip, &newtype, outtype, max-1);\n\t\t\t_array_small_type(outtype->type_num,\n\t\t\t\t\t newtype.type_num, \n\t\t\t\t\t outtype->itemsize,\n\t\t\t\t\t newtype.itemsize,\n\t\t\t\t\t &newtype);\n Py_DECREF(ip);\n }\n\t\tchktype = newtype.type_num;\n\t\tchksize = newtype.itemsize;\n\t\tgoto finish;\n }\n\t\n\tif (PyBool_Check(op)) {\n\t\tchktype = PyArray_BOOL;\n\t\tchksize = sizeof(Bool);\n\t\tgoto finish;\t\t\n\t}\n else if (PyInt_Check(op)) {\n\t\tchktype = PyArray_LONG;\n\t\tchksize = sizeof(long);\n\t\tgoto finish;\n } else if (PyFloat_Check(op)) {\n\t\tchktype = PyArray_DOUBLE;\n\t\tchksize = sizeof(double);\n\t\tgoto finish;\n\t} else if (PyComplex_Check(op)) {\n\t\tchktype = PyArray_CDOUBLE;\n\t\tchksize = sizeof(cdouble);\n\t\tgoto finish;\n\t}\n\n deflt:\n\tchktype = PyArray_OBJECT;\n\tchksize = sizeof(void *);\n\n finish:\n\t_array_small_type(chktype, mintype, chksize, minsize, \n\t\t\t outtype);\n\treturn;\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\" */ \nstatic PyObject *\nArray_FromScalar(PyObject *op, PyArray_Typecode *typecode) \n{\n PyArrayObject *ret;\n\tint itemsize = 0;\n\tint type = typecode->type_num;\n\n\tif PyTypeNum_ISFLEXIBLE(type) {\n\t\titemsize = PyObject_Length(op);\n\t}\n\n\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, 0, NULL, type,\n\t\t\t\t\t NULL, NULL, itemsize, 0, NULL);\n\n\tif (ret == NULL) return NULL;\n\n ret->descr->setitem(op, ret->data, ret);\n\t\n if (PyErr_Occurred()) {\n array_dealloc(ret);\n return NULL;\n } else {\n return (PyObject *)ret;\n }\n}\n\n\nstatic PyObject *\nArray_FromSequence(PyObject *s, PyArray_Typecode *typecode, int min_depth, \n\t\t int max_depth)\n{\n PyArrayObject *r;\n int nd;\n\tintp *d;\n\tint stop_at_string;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->itemsize;\n\t\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 if (!((nd=discover_depth(s, MAX_DIMS+1, stop_at_string)) > 0)) {\n\t\tif (nd==0)\n\t\t\treturn Array_FromScalar(s, typecode);\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid input sequence\");\n return NULL;\n }\n\t\n if ((max_depth && nd > max_depth) ||\t\\\n\t (min_depth && nd < min_depth)) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid number of dimensions\");\n return NULL;\n }\n\t\n\tif ((d=PyDimMem_NEW(nd)) == NULL) {\n\t\treturn PyErr_NoMemory();\n }\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) {\n\t\tPyDimMem_FREE(d);\n\t\treturn NULL;\n\t}\n\tif (itemsize == 0 && PyTypeNum_ISFLEXIBLE(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) {\n\t\t\tPyDimMem_FREE(d);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n r=(PyArrayObject*)PyArray_New(&PyArray_Type, nd, d, \n\t\t\t\t type, NULL, NULL,\n\t\t\t\t itemsize, \n\t\t\t\t typecode->fortran, NULL);\n\n PyDimMem_FREE(d);\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\n\nstatic int \nPyArray_ValidType(int type) \n{\n\tPyArray_Descr *descr;\n\t\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr==NULL) return 0;\n\treturn 1;\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->itemsize;\n\tint nels = PyArray_BUFSIZE;\n\tint el;\n\tint inswap, outswap=0;\n\tint obuf=!PyArray_ISCARRAY(out);\n\tint oelsize = out->itemsize;\n\tPyArray_VectorUnaryFunc *castfunc;\n PyArray_CopySwapFunc *in_csn;\n PyArray_CopySwapFunc *out_csn;\n\tint retval = -1;\n\n\tcastfunc = in->descr->cast[out->descr->type_num];\n in_csn = in->descr->copyswap;\n out_csn = out->descr->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\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\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->itemsize * 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\n/* For backward compatibility */\n\nstatic PyObject *\nPyArray_Cast(PyArrayObject *mp, int type_num) \n{\n\tPyArray_Typecode type;\n\tPyArray_Descr *descr;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\ttype.itemsize = descr->elsize;\n\ttype.type_num = descr->type_num;\n\ttype.fortran = 0;\n\t\n\treturn PyArray_CastToType(mp, &type);\n}\n\nstatic PyObject * \nPyArray_CastToType(PyArrayObject *mp, PyArray_Typecode *at) \n{\n\tPyObject *out;\n\tint ret;\n\n\tif ((mp->descr->type_num == at->type_num) && \\\n\t (at->itemsize==0 || mp->itemsize == at->itemsize) &&\n\t PyArray_ISBEHAVED_RO(mp)) {\n\t\tPy_INCREF(mp);\n\t\treturn (PyObject *)mp;\n\t}\n\t\t\n\tif (at->itemsize == 0) {\n\t\tif (mp->descr->type_num == PyArray_STRING &&\t\\\n\t\t at->type_num == PyArray_UNICODE)\n\t\t\tat->itemsize = mp->itemsize*sizeof(Py_UNICODE);\n\t\tif (mp->descr->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING) \n\t\t\tat->itemsize = mp->itemsize/sizeof(Py_UNICODE);\n\t\tif (at->type_num == PyArray_VOID)\n\t\t\tat->itemsize = mp->itemsize;\n\t}\n\n\tout = PyArray_New(mp->ob_type, mp->nd, \n\t\t\t mp->dimensions, \n\t\t\t at->type_num,\n\t\t\t NULL, NULL, at->itemsize, \n\t\t\t at->fortran, (PyObject *)mp);\n\tif (out == NULL) return NULL;\n\tret = PyArray_CastTo((PyArrayObject *)out, mp);\n\tif (ret != -1) return out;\n\n\tPy_DECREF(out);\n\treturn NULL;\n\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\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\tsimple = ((PyArray_ISCARRAY(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY(mp) && PyArray_ISFARRAY(out)));\n\t\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->itemsize * outsize;\n\t\tintp ncopies = outsize / mpsize;\n\n\t\twhile(ncopies--) {\n\t\t\tinptr = mp->data;\n\t\t\tmp->descr->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\nstatic PyObject *\narray_fromarray(PyArrayObject *arr, PyArray_Typecode *typecode, int flags) \n{\n\t\n\tPyArrayObject *ret=NULL;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->itemsize;\n\tint copy = 0;\n\tint arrflags;\n\tPyArray_Typecode oldtype;\n\tchar *msg = \"cannot copy back to a read-only array\";\n PyTypeObject *subtype;\n\n\toldtype.type_num = PyArray_TYPE(arr);\n\toldtype.itemsize = PyArray_ITEMSIZE(arr);\n\toldtype.fortran = 0;\n\n subtype = arr->ob_type;\n\n\tif (type == PyArray_NOTYPE) type = arr->descr->type_num;\n\tif (itemsize == 0) itemsize = arr->itemsize;\n\ttypecode->type_num = type;\n\ttypecode->itemsize = itemsize;\n\n\t/* Don't copy if sizes are compatible */\n\tif (PyArray_EquivalentTypes(&oldtype, typecode)) {\n\t\tarrflags = arr->flags;\n\n\t\tcopy = (flags & ENSURECOPY) || \\\n\t\t\t((flags & CONTIGUOUS) && (!(arrflags & CONTIGUOUS))) \\\n\t\t\t|| (PyArray_ITEMSIZE(arr) != itemsize) || \\\n\t\t\t((flags & ALIGNED) && (!(arrflags & ALIGNED))) || \\\n\t\t\t((flags & NOTSWAPPED) && (!(arrflags & NOTSWAPPED))) \\\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 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_New(subtype, \n\t\t\t\t\t arr->nd, \n\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t arr->descr->type_num,\n\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t itemsize,\n\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t (PyObject *)arr);\n\t\t\tif (PyArray_CopyInto(ret, arr) == -1) 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 ret = (PyArrayObject *) \\\n PyArray_New(&PyArray_Type,\n arr->nd,\n arr->dimensions,\n arr->descr->type_num,\n arr->strides,\n arr->data,\n arr->itemsize,\n arr->flags,NULL);\n if (ret == NULL) return NULL;\n ret->base = (PyObject *)arr;\n ret->flags &= ~UPDATEIFCOPY;\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_CanCastSafely(PyArray_TYPE(arr), type)) {\n if ((flags & UPDATEIFCOPY) && \\\n (!PyArray_ISWRITEABLE(arr))) {\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_New(subtype, arr->nd,\n arr->dimensions, typecode->type_num,\n NULL, NULL, typecode->itemsize,\n typecode->fortran, \n (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\nstatic int\n_array_typecode_fromstr(char *str, int *swap, PyArray_Typecode *type)\n{\n int type_num;\n char typechar;\n int size;\n unsigned long number = 1;\n char *s;\n char msg[] = \"unsupported typestring\";\n \n s = (char *)&number; /* s[0] == 0 implies big-endian */\n\n *swap = 0;\n\n if (str[0] == '<' || str[0] == '>') {\n\tif ((str[0] == '<') && (s[0] == 0)) *swap = 1;\n\telse if ((str[0] == '>') && (s[0] != 0)) *swap = 1;\n }\n str += 1;\n \n#define _MY_FAIL {\t\t\t\t \\\n\t PyErr_SetString(PyExc_ValueError, msg); \\\n\t return -1;\t\t\t \\\n }\t\t\n\n typechar = str[0];\n size = atoi(str + 1);\n switch (typechar) {\n case 'b':\n\t if (size == sizeof(Bool))\n\t\t type_num = PyArray_BOOL;\t \n\t else _MY_FAIL \n\t break;\t\t \n case 'u':\n if (size == sizeof(uintp))\n type_num = PyArray_UINTP;\n\t else if (size == sizeof(char))\n\t\t type_num = PyArray_UBYTE;\n\t else if (size == sizeof(short)) \n\t\t type_num = PyArray_USHORT;\n\t else if (size == sizeof(int)) \n\t\t type_num = PyArray_UINT;\n\t else if (size == sizeof(ulong)) \n\t\t type_num = PyArray_ULONG;\n\t else if (size == sizeof(ulonglong))\n\t\t type_num = PyArray_ULONGLONG;\n\t else _MY_FAIL\n\t break;\t\t \n case 'i':\n if (size == sizeof(intp))\n type_num = PyArray_INTP;\n\t else if (size == sizeof(char)) \n\t\t type_num = PyArray_BYTE;\n\t else if (size == sizeof(short)) \n\t\t type_num = PyArray_SHORT;\n\t else if (size == sizeof(int))\n\t\t type_num = PyArray_INT;\n\t else if (size == sizeof(long)) \n\t\t type_num = PyArray_LONG;\n\t else if (size == sizeof(longlong))\n\t\t type_num = PyArray_LONGLONG;\n\t else _MY_FAIL\n\t break;\t\t \n case 'f':\n\t if (size == sizeof(float))\n\t\t type_num = PyArray_FLOAT;\n\t else if (size == sizeof(double))\n\t\t type_num = PyArray_DOUBLE;\n\t else if (size == sizeof(longdouble))\n\t\t type_num = PyArray_LONGDOUBLE;\n\t else _MY_FAIL\n\t break;\n case 'c':\n\t if (size == sizeof(float)*2)\n\t\t type_num = PyArray_CFLOAT;\n\t else if (size == sizeof(double)*2)\n\t\t type_num = PyArray_CDOUBLE;\n\t else if (size == sizeof(longdouble)*2)\n\t\t type_num = PyArray_CLONGDOUBLE;\n\t else _MY_FAIL\n\t break;\n case 'O':\n\t if (size == sizeof(PyObject *))\n\t\t type_num = PyArray_OBJECT;\n\t else _MY_FAIL\n\t break;\n case 'S':\n\t type_num = PyArray_STRING;\n\t break;\n case 'U':\n\t type_num = PyArray_UNICODE;\n\t size *= sizeof(Py_UNICODE);\n\t break;\t \n case 'V':\n\t type_num = PyArray_VOID;\n\t break;\n default:\n\t _MY_FAIL\n }\n\n#undef _MY_FAIL\n\n type->type_num = type_num;\n type->itemsize = size;\n type->fortran = 0;\n return 0;\n}\n\nstatic PyObject *\narray_frominterface(PyObject *input, PyArray_Typecode *intype, int flags)\n{\n\tPyObject *attr=NULL, *item=NULL, *r;\n\tPyArrayObject *ret=NULL;\n\tPyArray_Typecode type;\n\tchar *data;\n\tint buffer_len;\n\tint res, i, n;\n\tintp dims[MAX_DIMS], strides[MAX_DIMS];\n\tint swap;\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\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) {Py_XDECREF(attr); return NULL;}\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t}\n\telse {\n\t\tif (PyTuple_GET_SIZE(attr) != 2) {\n\t\t\tPy_DECREF(attr);\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\treturn NULL;\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\tPy_DECREF(attr);\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\treturn NULL;\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 = PyObject_GetAttrString(input, \"__array_typestr__\");\n\tif (!PyString_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_typestr__ must be a string\");\n\t\tPy_DECREF(attr);\n\t\treturn NULL;\t\n\t}\n\tres = _array_typecode_fromstr(PyString_AS_STRING(attr), &swap, &type);\n\tPy_DECREF(attr);\n\tif (res < 0) return NULL;\n \n\tattr = PyObject_GetAttrString(input, \"__array_shape__\");\n\tif (!PyTuple_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_shape__ must be a tuple\");\n\t\tPy_DECREF(attr);\n\t\treturn NULL;\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\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\treturn NULL;\n\t\t}\n\t\tfor (i=0; istrides, strides, n*sizeof(intp));\n\t}\n\n\tif (swap) {\n\t\tPyObject *tmp;\n tmp = PyArray_Byteswap(ret, TRUE);\n\t\tPy_DECREF(tmp);\n\t}\n\n\tPyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n\tr = array_fromarray(ret, intype, flags);\n\tPy_DECREF(ret);\n\treturn r;\n}\n\nstatic PyObject *\narray_fromattr(PyObject *op, PyArray_Typecode *typecode, int flags) \n{\n PyObject *new, *r;\n\t \n if (typecode->type_num == PyArray_NOTYPE) {\n new = PyObject_CallMethod(op, \"__array__\", NULL);\n } else {\n\t\tPyArray_Descr *descr;\n\t\tPyObject *obj;\n\n\t\tdescr = PyArray_DescrFromType(typecode->type_num);\n\t\tif (PyTypeNum_ISFLEXIBLE(typecode->type_num)) {\n\t\t\tobj = PyString_FromFormat(\"%c%d\", descr->type,\n\t\t\t\t\t\t typecode->itemsize);\n\t\t}\n\t\telse { \n\t\t\tobj = (PyObject *)(descr->typeobj); Py_INCREF(obj);\n\t\t}\n\t\tnew = PyObject_CallMethod(op, \"__array__\", \"N\", obj);\n }\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 r = array_fromarray((PyArrayObject *)new, typecode, flags);\n Py_DECREF(new);\n return r;\n} \n\n\nstatic PyObject *\narray_fromobject(PyObject *op, PyArray_Typecode *typecode, int min_depth, \n\t\t int max_depth, int flags) \n{\n /* This is the main code to make a NumPy array from a Python\n Object. It is called from lot's of different places which\n is why there are so many checks. The comments try to\n explain some of the checks. */\n\n\tint type = typecode->type_num;\n PyObject *r=NULL;\n\n\t/* Is input object already an array? */\n\t/* This is where the flags are used */\n if (PyArray_Check(op)) \n\t\tr = array_fromarray((PyArrayObject *)op, typecode, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, typecode);\n\t}\n\telse if (PyObject_HasAttrString(op, \"__array__\")) {\n\t\t/* Code that returns the object to convert for a non\n\t\t multiarray input object from the __array__ attribute of the\n\t\t object. */\n r = array_fromattr(op, typecode, flags);\n\t}\n\telse if (PyObject_HasAttrString(op, \"__array_shape__\") &&\n\t\t PyObject_HasAttrString(op, \"__array_typestr__\")) {\n\t\tr = array_frominterface(op, typecode, flags);\n\t}\n\telse {\n\t\tif (type == PyArray_NOTYPE) {\n\t\t\t_array_find_type(op, NULL, typecode, MAX_DIMS);\n\t\t}\n\t\tif (PySequence_Check(op))\n\t\t\tr = Array_FromSequence(op, typecode, \n\t\t\t\t\t min_depth, max_depth);\n\t\telse\n\t\t\tr = Array_FromScalar(op, typecode);\n\t}\n\n /* If we didn't succed return NULL */\n if (r == NULL) return NULL;\n\t\n\t/* Be sure we succeed here */\n\t\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"internal error: array_fromobject \"\\\n\t\t\t\t\"not producing an array\");\n\t\tPy_DECREF(r);\n return NULL;\n }\n\n if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {\n Py_DECREF(r);\n PyErr_SetString(PyExc_ValueError, \n \"object of too small depth for desired array\");\n return NULL;\n }\n if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {\n Py_DECREF(r);\n PyErr_SetString(PyExc_ValueError, \n \"object too deep for desired array\");\n return NULL;\n }\n return r;\n}\n\nstatic void\nPyArray_ArrayType(PyObject *op, PyArray_Typecode *intype, \n\t\t PyArray_Typecode *outtype) \n{\n\t_array_find_type(op, intype, outtype, MAX_DIMS);\n\treturn;\n}\n\nstatic int \nPyArray_ObjectType(PyObject *op, int minimum_type) \n{\n\tPyArray_Typecode intype, outtype;\n\tintype.type_num = minimum_type;\n\t_array_find_type(op, &intype, &outtype, MAX_DIMS);\n\treturn outtype.type_num;\n}\n\n\n\n/* flags is any of \n CONTIGUOUS, \n FORTRAN, (or set typecode->fortran=1)\n ALIGNED, \n NOTSWAPPED, \n WRITEABLE, \n ENSURECOPY, \n UPDATEIFCOPY,\n FORCECAST,\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, NOTSWAPPED, and WRITEABLE\n and therefore it is redundant to include those as well. \n\n BEHAVED_FLAGS == ALIGNED | NOTSWAPPED | WRITEABLE\n BEHAVED_FLAGS_RO == ALIGNED | NOTSWAPPED\n CARRAY_FLAGS = CONTIGUOUS | BEHAVED_FLAGS\n FARRAY_FLAGS = FORTRAN | BEHAVED_FLAGS\n \n By default, the returned array will be a copy of the object, \n (C) contiguous in memory, aligned, notswapped, and writeable.\n \n So CONTIGUOUS | ENSURECOPY passed in means that the returned\n array does not have to be CONTIGUOUS or a COPY but should be\n ALIGNED, NOTSWAPPED and WRITEABLE. \n\n typecode->fortran can be set to request a\n fortran-contiguous array. Fortran arrays are always behaved (aligned, \n notswapped, and writeable) and not (C) CONTIGUOUS. Note that either\n FORTRAN in the flag or typecode->fortran = 1 is enough to request\n a FORTRAN-style array. \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\nstatic PyObject *\nPyArray_FromAny(PyObject *op, PyArray_Typecode *typecode, int min_depth, \n\t\tint max_depth, int requires) \n{\n \tPyArray_Typecode mine = {PyArray_NOTYPE, 0, 0};\n\tPyArray_Typecode *type;\n\t\n\tif (typecode == NULL) type = &mine;\n\telse type = typecode;\n\t\t\n\tif (requires & ENSURECOPY) {\n\t\trequires |= DEFAULT_FLAGS;\n\t}\n\t/* Ensure that type->fortran and flags & FORTRAN are the\n\t same */\n\tif (requires & FORTRAN) typecode->fortran = 1;\n\tif (type->fortran == 1) {\n\t\trequires |= FARRAY_FLAGS;\n\t\tif (min_depth > 2) requires &= ~CONTIGUOUS;\n\t}\n\n\t/* make sure itemsize is not 0 unless warranted. */\n\tif ((type->itemsize == 0) && (type->type_num != PyArray_NOTYPE)) {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(type->type_num);\n\t\tif (descr != NULL) type->itemsize = descr->elsize;\n\t\telse return NULL;\n\t}\n\t\n\treturn array_fromobject(op, type, min_depth, max_depth, \n\t\t\t\trequires);\t\n}\n\n/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0, 0) */\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\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);\n Py_DECREF(op);\n return new;\n}\n\n/* These are all compressed into a single API */\n/* Deprecated calls -- Use PyArray_FromAny */\n\nstatic PyObject *\nPyArray_FromObject(PyObject *op, int type, int min_depth, int max_depth) \n{\n\tPyArray_Typecode typecode = {0, 0, 0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth,\n\t\t\t max_depth, BEHAVED_FLAGS | ENSUREARRAY);\n}\n\nstatic PyObject *\nPyArray_ContiguousFromObject(PyObject *op, int type, int min_depth, \n\t\t\t int max_depth) \n{\n\tPyArray_Typecode typecode = {0, 0, 0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth,\n\t\t\t max_depth, DEFAULT_FLAGS | ENSUREARRAY);\n}\n\nstatic PyObject *\nPyArray_CopyFromObject(PyObject *op, int type, int min_depth, \n\t\t int max_depth) \n{\n\tPyArray_Typecode typecode = {0, 0, 0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth, max_depth,\n\t\t\t ENSURECOPY | ENSUREARRAY);\n}\n\n/* End of deprecated */\n\nstatic PyObject *\nPyArray_ContiguousFromAny(PyObject *op, int type, int min_depth, \n\t\t\t int max_depth)\n{\n\tPyArray_Typecode typecode = {0,0,0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth,\n\t\t\t max_depth, DEFAULT_FLAGS);\n}\t\n\nstatic int \nPyArray_CanCastSafely(int fromtype, int totype) \n{\n\tPyArray_Descr *from, *to;\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\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 (to->elsize > from->elsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (to->elsize >= from->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (from->elsize < 8)\n return (to->elsize > from->elsize);\n else\n return (to->elsize >= from->elsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (from->elsize < 8)\n return ((to->elsize >> 1) > from->elsize);\n else\n return ((to->elsize >> 1) >= from->elsize);\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 (to->elsize > from->elsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (to->elsize >= from->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (from->elsize < 8)\n return (to->elsize > from->elsize);\n else\n return (to->elsize >= from->elsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (from->elsize < 8)\n return ((to->elsize >> 1) > from->elsize);\n else\n return ((to->elsize >> 1) >= from->elsize);\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 ((to->elsize >> 1) >= from->elsize);\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\nstatic Bool\nPyArray_CanCastTo(PyArray_Typecode *from, PyArray_Typecode *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->itemsize <= to->itemsize);\n\t\t\t}\n\t\t\telse if (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->itemsize * sizeof(Py_UNICODE)\\\n\t\t\t\t <= to->itemsize);\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->itemsize <= to->itemsize);\n\t\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 scipy's arraymap ****/\n/* and Python's array iterator ***/\n \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 = PyObject_GC_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 PyObject_GC_Track(it);\n return (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 PyObject_GC_UnTrack(it);\n Py_XDECREF(it->ao);\n PyObject_GC_Del(it);\n }\n\nstatic int\narrayiter_traverse(PyArrayIterObject *it, visitproc visit, void *arg)\n{\n if (it->ao != NULL)\n return visit((PyObject *)(it->ao), arg);\n return 0;\n}\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->itemsize;\n\tr = PyArray_New(self->ao->ob_type, 1, &count, \n\t\t\tself->ao->descr->type_num, NULL, NULL,\n\t\t\titemsize, 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->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->itemsize;\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\tr = PyArray_New(self->ao->ob_type, ind->nd, ind->dimensions,\n\t\t\tself->ao->descr->type_num, NULL, \n\t\t\tNULL, self->ao->itemsize, \n\t\t\t0, (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)->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\tint i;\n\tPyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tint 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\t\t\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\n\t/* Tuples 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\tr = PyArray_New(self->ao->ob_type, 1, &ii, \n\t\t\t\t\tself->ao->descr->type_num, NULL, \n\t\t\t\t\tNULL, self->ao->itemsize, 0,\n\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 */\n\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->itemsize;\n\t\tr = PyArray_New(self->ao->ob_type, 1, &n_steps, \n\t\t\t\tself->ao->descr->type_num, NULL, NULL,\n\t\t\t\tsize, 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)->copyswap;\n\t\twhile(n_steps--) {\n copyswap(dptr, self->dataptr, swap, size);\n\t\t\tfor(i=0; i< step_size; i++) \n\t\t\t\tPyArray_ITER_NEXT(self);\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\tif (PyArray_IsScalar(ind, Integer) || PyList_Check(ind)) {\n\t\tobj = PyArray_FromAny(ind, &indtype, 0, 0, FORCECAST);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tr = iter_subscript_Bool(self, (PyArrayObject *)obj);\n\t\t} \n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, &indtype, 0, 0, \n\t\t\t\t\t FORCECAST | BEHAVED_FLAGS);\n\t\t\tif (new==NULL) goto fail;\n\t\t\tobj = new;\n\t\t\tr = iter_subscript_int(self, (PyArrayObject *)obj);\n\t\t}\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\t\"unsupported iterator index\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPy_DECREF(obj);\n\t\treturn r;\n\t}\n\n\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\n fail:\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->itemsize;\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->copyswap;\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(self->dataptr, val->dataptr, swap,\n itemsize);\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t\tPyArray_ITER_NEXT(val);\n\t\tif (val->index==val->size) \n\t\t\tPyArray_ITER_RESET(val);\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_Typecode typecode;\n\tintp num;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\titemsize = typecode.itemsize = self->ao->itemsize;\n\ttypecode.type_num = self->ao->descr->type_num;\n copyswap = self->ao->descr->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\n\nstatic int\niter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val) \n{\n\tint i;\n\tPyObject *arrval=NULL;\n\tPyArrayIterObject *val_it=NULL;\n\tPyArray_Typecode type;\n\tPyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tint swap;\n\tint itemsize;\n\tint start, step_size;\n\tintp n_steps;\n\tPyObject *obj;\n PyArray_CopySwapFunc *copyswap;\n\t\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\ti = iter_ass_subscript(self, ind, val);\n\t\tPy_DECREF(ind);\n\t\treturn i;\n\t}\n\t\n\ttype.type_num = self->ao->descr->type_num;\n\titemsize = type.itemsize = self->ao->itemsize;\n\t\n\tarrval = PyArray_FromAny(val, &type, 0, 0, 0);\n\tif (arrval==NULL) return -1;\n\tval_it = (PyArrayIterObject *)PyArray_IterNew(arrval);\n\tif (val_it==NULL) goto fail;\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\n copyswap = PyArray_DESCR(arrval)->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\tgoto succeed;\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 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 copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, itemsize);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\tgoto succeed;\n\t\t}\n\t\twhile(n_steps--) {\n copyswap(self->dataptr, val_it->dataptr,\n swap, itemsize);\n\t\t\tfor(i=0; i < step_size; i++) \n\t\t\t\tPyArray_ITER_NEXT(self);\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\tgoto succeed;\n\t} \n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tif (PyArray_IsScalar(ind, Integer))\n\t\tobj = PyArray_FromScalar(ind, &indtype);\n\telse if (PyList_Check(ind)) {\n\t\tobj = PyArray_FromAny(ind, &indtype, 0, 0, FORCECAST);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tif (iter_ass_sub_Bool(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto fail;\n\t\t} \n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, &indtype, 0, 0, \n\t\t\t\t\t FORCECAST | BEHAVED_FLAGS);\n\t\t\tif (new==NULL) goto fail;\n\t\t\tPy_DECREF(obj);\n\t\t\tobj = new;\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 fail;\n\t\t}\n\t\telse goto fail;\n\t\tPy_DECREF(obj);\n\t\tgoto succeed;\n\t}\n\n\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\tgoto fail;\n\n succeed:\n\tPy_DECREF(val_it);\n\tPy_DECREF(arrval);\n\treturn 0;\n\n fail:\n\tPy_XDECREF(val_it);\n\tPy_XDECREF(arrval);\n\treturn -1;\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 if (PyArray_ISCONTIGUOUS(it->ao)) {\n r = PyArray_New(it->ao->ob_type, 1, &size, \n\t\t\t\tit->ao->descr->type_num,\n NULL, it->ao->data, it->ao->itemsize, \n\t\t\t\tit->ao->flags,\n (PyObject *)it->ao); \n\t\tif (r==NULL) return NULL;\n }\n else {\n r = PyArray_New(it->ao->ob_type, 1, &size, \n\t\t\t\tit->ao->descr->type_num,\n NULL, NULL, it->ao->itemsize, 0, \n (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\n\nstatic PyTypeObject PyArrayIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"scipy.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 | Py_TPFLAGS_HAVE_GC,/* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)arrayiter_traverse,\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)arrayiter_next,\t\t/* tp_iternext */\n iter_methods,\t\t\t\t/* tp_methods */\n};\n\n/** END of Array Iterator **/\n\n\n\n/*********************** Subscript Array Iterator *************************\n * *\n * This object handles subscript behavior for array objects. *\n * It is an iterator object with a next method *\n * It abstracts the n-dimensional mapping behavior to make the looping *\n * code more understandable (maybe) *\n * and so that indexing can be set up ahead of time *\n */ \n\n/* This checks the args for any fancy indexing objects */\n\n#define SOBJ_NOTFANCY 0 \n#define SOBJ_ISFANCY 1\n#define SOBJ_BADARRAY 2\n#define SOBJ_TOOMANY 3\n#define SOBJ_LISTTUP 4\n\nstatic int\nfancy_indexing_check(PyObject *args)\n{\n\tint i, n;\n\tPyObject *obj;\n\tint retval = SOBJ_NOTFANCY;\n\n\tif (PyTuple_Check(args)) {\n\t\tn = PyTuple_GET_SIZE(args);\n\t\tif (n >= MAX_DIMS) return SOBJ_TOOMANY;\n\t\tfor (i=0; i=MAX_DIMS) return SOBJ_ISFANCY;\n\t\tfor (i=0; i SOBJ_ISFANCY) return retval;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* convert an indexing object to an INTP indexing array iterator\n if possible -- otherwise, it is a Slice or Ellipsis object\n and has to be interpreted on bind to a particular \n array so leave it NULL for now.\n */\nstatic int\n_convert_obj(PyObject *obj, PyArrayIterObject **iter)\n{\n\tPyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tPyObject *arr;\n\n\tif (PySlice_Check(obj) || (obj == Py_Ellipsis))\n\t\t*iter = NULL;\n\telse {\n\t\tarr = PyArray_FromAny(obj, &indtype, 0, 0, FORCECAST);\n\t\tif (arr == NULL) return -1;\n\t\t*iter = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (*iter == NULL) return -1;\n\t}\n\treturn 0;\n}\n\n/* Adjust dimensionality and strides for index object iterators \n --- i.e. broadcast\n */\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->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->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=NULL, *obj=NULL;\n\tint i, j, n, curraxis, ellipexp, noellip;\n\tPyArrayIterObject *it;\n\tintp dimsize;\n\tintp *indptr;\n\n\t/* Remove old binding if any */\n\tPy_XDECREF(mit->ait);\n\tmit->ait = NULL;\n\n\tPy_XDECREF(mit->subspace);\n\tmit->subspace = NULL;\n\t\n\tsubnd = arr->nd - mit->numiter;\n\tif (subnd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"too many indices for array\");\n\t\treturn;\n\t}\n\n\tmit->ait = (PyArrayIterObject *)PyArray_IterNew((PyObject *)arr);\n\tif (mit->ait == NULL) return;\n\n\t/* If this is just a view, then do nothing more */\n\t/* views are handled by just adjusting the strides\n\t and dimensions of the object.\n\t*/\n\t \n\tif (mit->view) return;\n\n\t/* no subspace iteration needed. 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\tif (mit->subspace == NULL) goto fail;\n\tPy_DECREF(sub);\n\n\t/* Expand dimensions of result */\n\tn = mit->subspace->ao->nd;\n\tfor (i=0; idimensions[mit->nd+i] = mit->subspace->ao->dimensions[i];\n\tmit->nd += n;\n\n\t/* Now, we still need to interpret the ellipsis and slice objects \n\t to determine which axes the indexing arrays are referring to\n\t*/\n\tn = PyTuple_GET_SIZE(mit->indexobj);\n\n\t/* The number of dimensions an ellipsis takes up */\n\tellipexp = arr->nd - n + 1;\n\t/* Now fill in iteraxes -- remember indexing arrays have been \n converted to 0's in mit->indexobj */\n\tcurraxis = 0;\n\tj = 0;\n\tnoellip = 1; /* Only expand the first ellipsis */\n\tmemset(mit->bscoord, 0, sizeof(intp)*arr->nd);\n\tfor (i=0; iindexobj, i);\n\t\tif (PyInt_Check(obj) || PyLong_Check(obj)) \n\t\t\tmit->iteraxes[j++] = curraxis++;\n\t\telse if (noellip && obj == Py_Ellipsis) {\n\t\t\tcurraxis += ellipexp;\n\t\t\tnoellip = 0;\n\t\t}\n\t\telse {\n\t\t\tint start=0;\n\t\t\tint 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}\t\t\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn;\n\n fail:\n\tPy_XDECREF(sub);\n\tPy_XDECREF(mit->ait);\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_Typecode typecode = {PyArray_BOOL, 0, 0};\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\tba = (PyArrayObject *)PyArray_FromAny(myBool, &typecode, 0, 0, \n\t\t\t\t\t CARRAY_FLAGS);\n\tif (ba == NULL) return -1;\n\tnd = ba->nd;\n\tfor (j=0; jdata;\n\tcount = 0;\n\n\t/* pre-determine how many nonzero entries there are */\n\tfor (i=0; iao->data;\n\t\tcoords[j] = 0;\n\t\tdims_m1[j] = ba->dimensions[j]-1;\n\t}\n\n\tptr = (Bool *)ba->data;\n\n\tif (count == 0) return nd;\n\n\t/* Loop through the Boolean array and copy coordinates\n\t for non-zero entries */\n\tfor (i=0; i=0; j--) {\n\t\t\tif (coords[j] < dims_m1[j]) {\n\t\t\t\tcoords[j]++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcoords[j] = 0;\n\t\t\t}\n\t\t}\n\t}\n\treturn nd;\n\n fail:\n\tfor (j=0; jiters[i] = NULL;\n \tmit->view = 0;\n \tmit->index = 0;\n \tmit->ait = NULL;\n \tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tfancy = fancy_indexing_check(indexobj);\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\tif (fancy == SOBJ_NOTFANCY) { /* bail out */\n\t\tmit->view = 1;\n\t\tgoto ret;\n\t}\n\n\tif (fancy == SOBJ_BADARRAY) {\n\t\tPyErr_SetString(PyExc_TypeError,\t\t\t\\\n\t\t\t\t\"arrays used as indexes must be of \" \\\n\t\t\t\t\"integer type\");\n\t\tgoto fail;\n\t}\n\tif (fancy == SOBJ_TOOMANY) {\n\t\tPyErr_SetString(PyExc_TypeError, \"too many indicies\");\n\t\tgoto fail;\n\t}\n\n\tif (fancy == SOBJ_LISTTUP) {\n\t\tPyObject *newobj;\n\t\tnewobj = PySequence_Tuple(indexobj);\n\t\tif (newobj == NULL) goto fail;\n\t\tPy_DECREF(indexobj);\n\t\tindexobj = newobj;\n\t\tmit->indexobj = indexobj;\n\t}\n\n#undef SOBJ_NOTFANCY \n#undef SOBJ_ISFANCY \n#undef SOBJ_BADARRAY \n#undef SOBJ_TOOMANY \n#undef SOBJ_LISTTUP \n\n\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\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 (PyList_Check(indexobj) || PyArray_Check(indexobj)) {\n\t\tmit->numiter = 1;\n\t\tarr = PyArray_FromAny(indexobj, &indtype, 0, 0, FORCECAST);\n\t\tif (arr == NULL) goto fail;\n\t\tmit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (mit->iters[0] == NULL) 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(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\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = new;\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\t/* Store the number of iterators actually converted */\n\t\t/* These will be mapped to actual axes at bind time */\n\t\tif (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)\n\t\t\tgoto fail;\n\t}\n\n ret:\n PyObject_GC_Track(mit);\n return (PyObject *)mit;\n \n fail:\n\tPy_XDECREF(arr);\n\tPy_XDECREF(mit->indexobj);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n PyObject_GC_Del(mit);\n\treturn NULL;\n}\n\n\n/* return unbound mapiter object */\n\nstatic PyObject *\narraymapiter_new(PyTypeObject *type, PyObject *args, PyObject *kwds) \n{\n\tPyObject *newtup, *res;\n\tint n;\n\n\tif (!PyTuple_Check(args)) {\n\t\tPyErr_BadInternalCall();\n\t\treturn NULL;\n\t}\n\n\tn = PyTuple_GET_SIZE(args);\n\t\n\tif (n < 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"must be initialized with >= 1 argument\");\n\t\treturn NULL;\n\t}\n\t\n\tif (n > 1) {\n\t\tnewtup = PyTuple_GetSlice(args, 0, n);\n\t\tif (newtup == NULL) return NULL;\n\t\tres = PyArray_MapIterNew(newtup);\n\t\tPy_DECREF(newtup);\n\t}\n\telse { /* n == 1 */\n\t\tnewtup = PyTuple_GET_ITEM(args, 0);\n\t\tres = PyArray_MapIterNew(newtup);\n\t}\n\n\treturn res; \t\n}\n\n\n/* Returns a 0-dim array holding the element desired */\n/*\nstatic PyObject *\narraymapiter_next(PyArrayMapIterObject *mit)\n{\n\tPyObject *ret;\n\tif (mit->ait == NULL) return NULL;\n\tif (mit->view) return NULL;\n\tif (mit->index < mit->size) {\n\t\tret = PyArray_ToScalar(mit->dataptr, mit->ait->ao);\n\t\tPyArray_MapIterNext(mit);\n\t\treturn ret;\n\t}\n return NULL;\n}\n*/\n\nstatic void\narraymapiter_dealloc(PyArrayMapIterObject *mit)\n{\n\tint i;\n PyObject_GC_UnTrack(mit);\n Py_XDECREF(mit->ait);\n\tPy_XDECREF(mit->indexobj);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n PyObject_GC_Del(mit);\n}\n\nstatic int\narraymapiter_traverse(PyArrayMapIterObject *mit, visitproc visit, void *arg)\n{\n\tint ret, i;\n if (mit->ait != NULL)\n if ((ret = visit((PyObject *)(mit->ait), arg)) != 0) \n\t\t\treturn ret;\t\n\n\tif (mit->iters != NULL) \n\t\tfor (i=0; inumiter; i++) \n\t\t\tif (mit->iters[i] != NULL) \n\t\t\t\tif ((ret=visit((PyObject *)mit->iters[i], \n\t\t\t\t\t arg)) != 0)\n\t\t\t\t\treturn ret;\n\n\tif (mit->indexobj != NULL)\n\t\tif ((ret = visit(mit->indexobj, arg)) != 0) return ret;\n\t\n return 0;\n}\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 MapIterNew must be \n that does not work. 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 char doc_mapiter_bind[] = \"obj.bind(a)\\n Bind an array to the \"\\\n\t\"mapiter object\";\n\nstatic PyObject *\nmapiter_bind(PyArrayMapIterObject *mit, PyObject *args)\n{\n\tPyArrayObject *arr;\n\n if (!PyArg_ParseTuple(args, \"O!\", &PyArray_Type, &arr)) return NULL;\n\n \tPyArray_MapIterBind(mit, arr);\n\n\tif (mit->ait == NULL) return NULL;\n\t\n \tPyArray_MapIterReset(mit);\n\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyMethodDef mapiter_methods[] = {\n\t{\"bind\", (PyCFunction)mapiter_bind, 1, doc_mapiter_bind},\n {NULL,\t\tNULL}\t\t\n};\n*/\n\n\nstatic PyTypeObject PyArrayMapIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"scipy.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 | Py_TPFLAGS_HAVE_GC,/* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)arraymapiter_traverse,\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, /*arraymapiter_next,*/\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 (newfunc)arraymapiter_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n\n};\n\n/** END of Subscript Iterator **/\n\n\n\n", "methods": [ { "name": "PyArray_PyIntAsIntp", "long_name": "PyArray_PyIntAsIntp( PyObject * o)", "filename": "arrayobject.c", "nloc": 59, "complexity": 19, "token_count": 385, "parameters": [ "o" ], "start_line": 40, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 64, "top_nesting_level": 0 }, { "name": "PyArray_PyIntAsInt", "long_name": "PyArray_PyIntAsInt( PyObject * o)", "filename": "arrayobject.c", "nloc": 57, "complexity": 19, "token_count": 389, "parameters": [ "o" ], "start_line": 109, "end_line": 169, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 61, "top_nesting_level": 0 }, { "name": "PyArray_GetPriority", "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", "filename": "arrayobject.c", "nloc": 17, "complexity": 5, "token_count": 86, "parameters": [ "obj", "default_" ], "start_line": 173, "end_line": 191, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "PyArray_Zero", "long_name": "PyArray_Zero( PyArrayObject * arr)", "filename": "arrayobject.c", "nloc": 34, "complexity": 6, "token_count": 190, "parameters": [ "arr" ], "start_line": 208, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "PyArray_One", "long_name": "PyArray_One( PyArrayObject * arr)", "filename": "arrayobject.c", "nloc": 40, "complexity": 7, "token_count": 222, "parameters": [ "arr" ], "start_line": 246, "end_line": 289, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "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": 295, "end_line": 345, "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": 368, "end_line": 399, "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": 213, "parameters": [ "src" ], "start_line": 402, "end_line": 436, "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": 449, "end_line": 471, "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": 474, "end_line": 495, "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": 499, "end_line": 537, "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": 542, "end_line": 562, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "index2ptr", "long_name": "index2ptr( PyArrayObject * mp , int i)", "filename": "arrayobject.c", "nloc": 10, "complexity": 7, "token_count": 86, "parameters": [ "mp", "i" ], "start_line": 570, "end_line": 580, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "PyArray_Size", "long_name": "PyArray_Size( PyObject * op)", "filename": "arrayobject.c", "nloc": 9, "complexity": 2, "token_count": 33, "parameters": [ "op" ], "start_line": 583, "end_line": 591, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "PyArray_CopyInto", "long_name": "PyArray_CopyInto( PyArrayObject * dest , PyArrayObject * src)", "filename": "arrayobject.c", "nloc": 71, "complexity": 16, "token_count": 427, "parameters": [ "dest", "src" ], "start_line": 604, "end_line": 684, "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": 16, "complexity": 2, "token_count": 98, "parameters": [ "dest", "src_object" ], "start_line": 688, "end_line": 707, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "PyArray_FromDimsAndDataAndDescr", "long_name": "PyArray_FromDimsAndDataAndDescr( int nd , int * d , PyArray_Descr * descr , char * data)", "filename": "arrayobject.c", "nloc": 15, "complexity": 3, "token_count": 121, "parameters": [ "nd", "d", "descr", "data" ], "start_line": 715, "end_line": 734, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "PyArray_FromDimsAndData", "long_name": "PyArray_FromDimsAndData( int nd , int * d , int type , char * data)", "filename": "arrayobject.c", "nloc": 14, "complexity": 3, "token_count": 112, "parameters": [ "nd", "d", "type", "data" ], "start_line": 738, "end_line": 755, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "PyArray_FromDims", "long_name": "PyArray_FromDims( int nd , int * d , int type)", "filename": "arrayobject.c", "nloc": 14, "complexity": 5, "token_count": 133, "parameters": [ "nd", "d", "type" ], "start_line": 759, "end_line": 776, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "PyArray_Copy", "long_name": "PyArray_Copy( PyArrayObject * m1)", "filename": "arrayobject.c", "nloc": 11, "complexity": 2, "token_count": 77, "parameters": [ "m1" ], "start_line": 782, "end_line": 794, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "PyArray_Scalar", "long_name": "PyArray_Scalar( char * data , int type_num , int itemsize , int swap)", "filename": "arrayobject.c", "nloc": 48, "complexity": 8, "token_count": 289, "parameters": [ "data", "type_num", "itemsize", "swap" ], "start_line": 800, "end_line": 849, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "top_nesting_level": 0 }, { "name": "PyArray_ToScalar", "long_name": "PyArray_ToScalar( char * data , PyArrayObject * arr)", "filename": "arrayobject.c", "nloc": 7, "complexity": 1, "token_count": 51, "parameters": [ "data", "arr" ], "start_line": 856, "end_line": 863, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_Return", "long_name": "PyArray_Return( PyArrayObject * mp)", "filename": "arrayobject.c", "nloc": 17, "complexity": 5, "token_count": 85, "parameters": [ "mp" ], "start_line": 869, "end_line": 888, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "PyArray_RegisterDataType", "long_name": "PyArray_RegisterDataType( PyTypeObject * type)", "filename": "arrayobject.c", "nloc": 31, "complexity": 6, "token_count": 177, "parameters": [ "type" ], "start_line": 899, "end_line": 931, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "PyArray_RegisterDescrForType", "long_name": "PyArray_RegisterDescrForType( int typenum , PyArray_Descr * descr)", "filename": "arrayobject.c", "nloc": 32, "complexity": 3, "token_count": 167, "parameters": [ "typenum", "descr" ], "start_line": 941, "end_line": 984, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "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": 16, "token_count": 577, "parameters": [ "self", "fp", "sep", "format" ], "start_line": 988, "end_line": 1079, "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": 24, "complexity": 5, "token_count": 151, "parameters": [ "self" ], "start_line": 1082, "end_line": 1110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "PyArray_ToString", "long_name": "PyArray_ToString( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 34, "complexity": 6, "token_count": 191, "parameters": [ "self" ], "start_line": 1113, "end_line": 1148, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "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": 1157, "end_line": 1194, "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": 1201, "end_line": 1209, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "array_item", "long_name": "array_item( PyArrayObject * self , int i)", "filename": "arrayobject.c", "nloc": 22, "complexity": 4, "token_count": 150, "parameters": [ "self", "i" ], "start_line": 1213, "end_line": 1237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "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": 26, "parameters": [ "self", "i" ], "start_line": 1240, "end_line": 1243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "array_ass_item", "long_name": "array_ass_item( PyArrayObject * self , int i , PyObject * v)", "filename": "arrayobject.c", "nloc": 27, "complexity": 8, "token_count": 177, "parameters": [ "self", "i", "v" ], "start_line": 1247, "end_line": 1277, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "slice_coerce_index", "long_name": "slice_coerce_index( PyObject * o , int * v)", "filename": "arrayobject.c", "nloc": 9, "complexity": 2, "token_count": 40, "parameters": [ "o", "v" ], "start_line": 1281, "end_line": 1289, "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 , int length , int * start , int * stop , int * step , intp * slicelength)", "filename": "arrayobject.c", "nloc": 45, "complexity": 24, "token_count": 376, "parameters": [ "r", "length", "start", "stop", "step", "slicelength" ], "start_line": 1295, "end_line": 1345, "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 , int * step_size , intp * n_steps , int max)", "filename": "arrayobject.c", "nloc": 45, "complexity": 11, "token_count": 223, "parameters": [ "op", "step_size", "n_steps", "max" ], "start_line": 1352, "end_line": 1397, "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": 89, "complexity": 20, "token_count": 540, "parameters": [ "self", "op", "dimensions", "strides", "offset_ptr" ], "start_line": 1401, "end_line": 1496, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 96, "top_nesting_level": 0 }, { "name": "_swap_axes", "long_name": "_swap_axes( PyArrayMapIterObject * mit , PyArrayObject ** ret)", "filename": "arrayobject.c", "nloc": 24, "complexity": 4, "token_count": 187, "parameters": [ "mit", "ret" ], "start_line": 1499, "end_line": 1533, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "PyArray_GetMap", "long_name": "PyArray_GetMap( PyArrayMapIterObject * mit)", "filename": "arrayobject.c", "nloc": 36, "complexity": 8, "token_count": 252, "parameters": [ "mit" ], "start_line": 1538, "end_line": 1587, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "top_nesting_level": 0 }, { "name": "PyArray_SetMap", "long_name": "PyArray_SetMap( PyArrayMapIterObject * mit , PyObject * op)", "filename": "arrayobject.c", "nloc": 50, "complexity": 12, "token_count": 392, "parameters": [ "mit", "op" ], "start_line": 1590, "end_line": 1649, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 60, "top_nesting_level": 0 }, { "name": "array_subscript", "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", "filename": "arrayobject.c", "nloc": 61, "complexity": 19, "token_count": 425, "parameters": [ "self", "op" ], "start_line": 1670, "end_line": 1745, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 76, "top_nesting_level": 0 }, { "name": "array_ass_sub", "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", "filename": "arrayobject.c", "nloc": 43, "complexity": 9, "token_count": 251, "parameters": [ "self", "index", "op" ], "start_line": 1758, "end_line": 1810, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "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": 1818, "end_line": 1821, "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": 1840, "end_line": 1852, "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": 1855, "end_line": 1870, "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": 1874, "end_line": 1883, "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": 1886, "end_line": 1897, "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": 1965, "end_line": 1998, "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": 2005, "end_line": 2044, "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": 23, "complexity": 5, "token_count": 136, "parameters": [ "m1", "op", "axis", "rtype" ], "start_line": 2047, "end_line": 2069, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "PyArray_GenericAccumulateFunction", "long_name": "PyArray_GenericAccumulateFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", "filename": "arrayobject.c", "nloc": 23, "complexity": 5, "token_count": 136, "parameters": [ "m1", "op", "axis", "rtype" ], "start_line": 2073, "end_line": 2095, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "PyArray_GenericBinaryFunction", "long_name": "PyArray_GenericBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", "filename": "arrayobject.c", "nloc": 12, "complexity": 2, "token_count": 69, "parameters": [ "m1", "m2", "op" ], "start_line": 2099, "end_line": 2110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_GenericUnaryFunction", "long_name": "PyArray_GenericUnaryFunction( PyArrayObject * m1 , PyObject * op)", "filename": "arrayobject.c", "nloc": 12, "complexity": 2, "token_count": 63, "parameters": [ "m1", "op" ], "start_line": 2113, "end_line": 2124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_GenericInplaceBinaryFunction", "long_name": "PyArray_GenericInplaceBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", "filename": "arrayobject.c", "nloc": 13, "complexity": 2, "token_count": 71, "parameters": [ "m1", "m2", "op" ], "start_line": 2127, "end_line": 2139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 2142, "end_line": 2145, "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": 2148, "end_line": 2151, "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": 2154, "end_line": 2157, "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": 2160, "end_line": 2163, "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": 2166, "end_line": 2169, "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": 2172, "end_line": 2175, "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": 2178, "end_line": 2181, "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": 2184, "end_line": 2187, "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": 2190, "end_line": 2193, "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": 2196, "end_line": 2199, "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": 2202, "end_line": 2205, "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": 2208, "end_line": 2211, "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": 2214, "end_line": 2217, "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": 2220, "end_line": 2223, "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": 2226, "end_line": 2229, "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": 2232, "end_line": 2235, "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": 2238, "end_line": 2241, "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": 2244, "end_line": 2247, "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": 2250, "end_line": 2253, "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": 2256, "end_line": 2259, "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": 2262, "end_line": 2265, "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": 2268, "end_line": 2271, "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": 2274, "end_line": 2277, "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": 2280, "end_line": 2283, "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": 2286, "end_line": 2289, "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": 2292, "end_line": 2295, "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": 2298, "end_line": 2301, "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": 2304, "end_line": 2308, "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": 2311, "end_line": 2315, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "array_all_nonzero", "long_name": "array_all_nonzero( PyArrayObject * mp)", "filename": "arrayobject.c", "nloc": 18, "complexity": 4, "token_count": 93, "parameters": [ "mp" ], "start_line": 2319, "end_line": 2337, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "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": 2340, "end_line": 2355, "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": 143, "parameters": [ "v" ], "start_line": 2359, "end_line": 2385, "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": 143, "parameters": [ "v" ], "start_line": 2388, "end_line": 2413, "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": 124, "parameters": [ "v" ], "start_line": 2416, "end_line": 2438, "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": 124, "parameters": [ "v" ], "start_line": 2441, "end_line": 2463, "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": 124, "parameters": [ "v" ], "start_line": 2466, "end_line": 2488, "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": 2491, "end_line": 2495, "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": 34, "complexity": 11, "token_count": 258, "parameters": [ "self", "ilow", "ihigh" ], "start_line": 2556, "end_line": 2594, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "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": 2598, "end_line": 2619, "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": 4, "complexity": 1, "token_count": 26, "parameters": [ "self", "el" ], "start_line": 2622, "end_line": 2627, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "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": 308, "parameters": [ "string", "n", "max_n", "data", "nd", "dimensions", "strides", "self" ], "start_line": 2648, "end_line": 2695, "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": 222, "parameters": [ "self" ], "start_line": 2698, "end_line": 2734, "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": 2740, "end_line": 2757, "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": 2760, "end_line": 2772, "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": 2775, "end_line": 2787, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "array_richcompare", "long_name": "array_richcompare( PyArrayObject * self , PyObject * other , int cmp_op)", "filename": "arrayobject.c", "nloc": 61, "complexity": 13, "token_count": 273, "parameters": [ "self", "other", "cmp_op" ], "start_line": 2791, "end_line": 2868, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 78, "top_nesting_level": 0 }, { "name": "_check_axis", "long_name": "_check_axis( PyArrayObject * arr , int * axis , int flags)", "filename": "arrayobject.c", "nloc": 29, "complexity": 8, "token_count": 164, "parameters": [ "arr", "axis", "flags" ], "start_line": 2871, "end_line": 2900, "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": 17, "complexity": 4, "token_count": 91, "parameters": [ "len", "vals" ], "start_line": 2906, "end_line": 2922, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "PyArray_IntpFromSequence", "long_name": "PyArray_IntpFromSequence( PyObject * seq , intp * vals , int maxvals)", "filename": "arrayobject.c", "nloc": 21, "complexity": 7, "token_count": 161, "parameters": [ "seq", "vals", "maxvals" ], "start_line": 2927, "end_line": 2950, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "_IsContiguous", "long_name": "_IsContiguous( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 14, "complexity": 6, "token_count": 109, "parameters": [ "ap" ], "start_line": 2956, "end_line": 2972, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_IsFortranContiguous", "long_name": "_IsFortranContiguous( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 14, "complexity": 6, "token_count": 107, "parameters": [ "ap" ], "start_line": 2976, "end_line": 2992, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_IsAligned", "long_name": "_IsAligned( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 14, "complexity": 4, "token_count": 110, "parameters": [ "ap" ], "start_line": 2995, "end_line": 3011, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_IsWriteable", "long_name": "_IsWriteable( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 16, "complexity": 8, "token_count": 109, "parameters": [ "ap" ], "start_line": 3014, "end_line": 3047, "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": 22, "complexity": 9, "token_count": 129, "parameters": [ "ret", "flagmask" ], "start_line": 3051, "end_line": 3073, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "PyArray_CheckStrides", "long_name": "PyArray_CheckStrides( int elsize , int nd , intp numbytes , intp * dims , intp * newstrides)", "filename": "arrayobject.c", "nloc": 13, "complexity": 4, "token_count": 84, "parameters": [ "elsize", "nd", "numbytes", "dims", "newstrides" ], "start_line": 3080, "end_line": 3095, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "_array_fill_strides", "long_name": "_array_fill_strides( intp * strides , intp * dims , int nd , intp itemsize , int inflag , int * objflags)", "filename": "arrayobject.c", "nloc": 24, "complexity": 9, "token_count": 171, "parameters": [ "strides", "dims", "nd", "itemsize", "inflag", "objflags" ], "start_line": 3115, "end_line": 3139, "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 , char * data , int itemsize , int flags , PyObject * obj)", "filename": "arrayobject.c", "nloc": 117, "complexity": 27, "token_count": 713, "parameters": [ "subtype", "nd", "dims", "type_num", "strides", "data", "itemsize", "flags", "obj" ], "start_line": 3143, "end_line": 3293, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 151, "top_nesting_level": 0 }, { "name": "PyArray_Resize", "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape)", "filename": "arrayobject.c", "nloc": 87, "complexity": 15, "token_count": 501, "parameters": [ "self", "newshape" ], "start_line": 3298, "end_line": 3403, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 106, "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": 3408, "end_line": 3425, "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": 47, "complexity": 7, "token_count": 261, "parameters": [ "arr", "obj" ], "start_line": 3428, "end_line": 3480, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "top_nesting_level": 0 }, { "name": "array_new", "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", "filename": "arrayobject.c", "nloc": 100, "complexity": 20, "token_count": 589, "parameters": [ "subtype", "args", "kwds" ], "start_line": 3483, "end_line": 3598, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 116, "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": 3605, "end_line": 3608, "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": 10, "complexity": 3, "token_count": 57, "parameters": [ "self" ], "start_line": 3611, "end_line": 3621, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "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": 3694, "end_line": 3697, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "array_shape_set", "long_name": "array_shape_set( PyArrayObject * self , PyObject * val)", "filename": "arrayobject.c", "nloc": 33, "complexity": 6, "token_count": 206, "parameters": [ "self", "val" ], "start_line": 3701, "end_line": 3735, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "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": 3739, "end_line": 3742, "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": 32, "complexity": 7, "token_count": 209, "parameters": [ "self", "obj" ], "start_line": 3745, "end_line": 3778, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "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": 3782, "end_line": 3789, "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": 3792, "end_line": 3800, "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": 3804, "end_line": 3810, "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": 3813, "end_line": 3827, "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": 3830, "end_line": 3874, "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": 19, "parameters": [ "self" ], "start_line": 3878, "end_line": 3881, "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": 8, "complexity": 3, "token_count": 45, "parameters": [ "self" ], "start_line": 3884, "end_line": 3891, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "array_typechar_get", "long_name": "array_typechar_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 8, "complexity": 2, "token_count": 47, "parameters": [ "self" ], "start_line": 3895, "end_line": 3902, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "array_typestr_get", "long_name": "array_typestr_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 19, "complexity": 7, "token_count": 141, "parameters": [ "self" ], "start_line": 3905, "end_line": 3925, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "array_descr_get", "long_name": "array_descr_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 19, "complexity": 5, "token_count": 128, "parameters": [ "self" ], "start_line": 3928, "end_line": 3950, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "array_type_get", "long_name": "array_type_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 4, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 3954, "end_line": 3957, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "array_type_set", "long_name": "array_type_set( PyArrayObject * self , PyObject * arg)", "filename": "arrayobject.c", "nloc": 41, "complexity": 10, "token_count": 294, "parameters": [ "self", "arg" ], "start_line": 3969, "end_line": 4027, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 59, "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": 4032, "end_line": 4042, "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": 4046, "end_line": 4071, "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": 31, "complexity": 4, "token_count": 177, "parameters": [ "self", "val" ], "start_line": 4075, "end_line": 4107, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "array_imag_get", "long_name": "array_imag_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 34, "complexity": 3, "token_count": 200, "parameters": [ "self" ], "start_line": 4110, "end_line": 4145, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "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": 203, "parameters": [ "self", "val" ], "start_line": 4148, "end_line": 4185, "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": 4188, "end_line": 4191, "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": 51, "complexity": 9, "token_count": 368, "parameters": [ "self", "val" ], "start_line": 4194, "end_line": 4248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 55, "top_nesting_level": 0 }, { "name": "discover_depth", "long_name": "discover_depth( PyObject * s , int max , int stop_at_string)", "filename": "arrayobject.c", "nloc": 23, "complexity": 14, "token_count": 169, "parameters": [ "s", "max", "stop_at_string" ], "start_line": 4423, "end_line": 4448, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "discover_itemsize", "long_name": "discover_itemsize( PyObject * s , int nd , int * itemsize)", "filename": "arrayobject.c", "nloc": 21, "complexity": 9, "token_count": 161, "parameters": [ "s", "nd", "itemsize" ], "start_line": 4451, "end_line": 4473, "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": 4480, "end_line": 4506, "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( int chktype , int mintype , int chksize , int minsize , PyArray_Typecode * outtype)", "filename": "arrayobject.c", "nloc": 19, "complexity": 5, "token_count": 100, "parameters": [ "chktype", "mintype", "chksize", "minsize", "outtype" ], "start_line": 4509, "end_line": 4529, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "_array_find_type", "long_name": "_array_find_type( PyObject * op , PyArray_Typecode * minitype , PyArray_Typecode * outtype , int max)", "filename": "arrayobject.c", "nloc": 126, "complexity": 28, "token_count": 671, "parameters": [ "op", "minitype", "outtype", "max" ], "start_line": 4532, "end_line": 4673, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 142, "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": 4676, "end_line": 4699, "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_Typecode * typecode)", "filename": "arrayobject.c", "nloc": 19, "complexity": 4, "token_count": 120, "parameters": [ "op", "typecode" ], "start_line": 4703, "end_line": 4726, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "Array_FromSequence", "long_name": "Array_FromSequence( PyObject * s , PyArray_Typecode * typecode , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 51, "complexity": 17, "token_count": 313, "parameters": [ "s", "typecode", "min_depth", "max_depth" ], "start_line": 4730, "end_line": 4787, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 58, "top_nesting_level": 0 }, { "name": "PyArray_ValidType", "long_name": "PyArray_ValidType( int type)", "filename": "arrayobject.c", "nloc": 7, "complexity": 2, "token_count": 30, "parameters": [ "type" ], "start_line": 4791, "end_line": 4798, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "_bufferedcast", "long_name": "_bufferedcast( PyArrayObject * out , PyArrayObject * in)", "filename": "arrayobject.c", "nloc": 75, "complexity": 16, "token_count": 477, "parameters": [ "out", "in" ], "start_line": 4804, "end_line": 4894, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 91, "top_nesting_level": 0 }, { "name": "PyArray_Cast", "long_name": "PyArray_Cast( PyArrayObject * mp , int type_num)", "filename": "arrayobject.c", "nloc": 10, "complexity": 1, "token_count": 56, "parameters": [ "mp", "type_num" ], "start_line": 4900, "end_line": 4911, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_CastToType", "long_name": "PyArray_CastToType( PyArrayObject * mp , PyArray_Typecode * at)", "filename": "arrayobject.c", "nloc": 31, "complexity": 13, "token_count": 233, "parameters": [ "mp", "at" ], "start_line": 4914, "end_line": 4949, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "PyArray_CastTo", "long_name": "PyArray_CastTo( PyArrayObject * out , PyArrayObject * mp)", "filename": "arrayobject.c", "nloc": 40, "complexity": 10, "token_count": 214, "parameters": [ "out", "mp" ], "start_line": 4956, "end_line": 5002, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "array_fromarray", "long_name": "array_fromarray( PyArrayObject * arr , PyArray_Typecode * typecode , int flags)", "filename": "arrayobject.c", "nloc": 116, "complexity": 35, "token_count": 721, "parameters": [ "arr", "typecode", "flags" ], "start_line": 5005, "end_line": 5136, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 132, "top_nesting_level": 0 }, { "name": "_array_typecode_fromstr", "long_name": "_array_typecode_fromstr( char * str , int * swap , PyArray_Typecode * type)", "filename": "arrayobject.c", "nloc": 94, "complexity": 36, "token_count": 533, "parameters": [ "str", "swap", "type" ], "start_line": 5140, "end_line": 5245, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 106, "top_nesting_level": 0 }, { "name": "array_frominterface", "long_name": "array_frominterface( PyObject * input , PyArray_Typecode * intype , int flags)", "filename": "arrayobject.c", "nloc": 113, "complexity": 26, "token_count": 715, "parameters": [ "input", "intype", "flags" ], "start_line": 5248, "end_line": 5371, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 124, "top_nesting_level": 0 }, { "name": "array_fromattr", "long_name": "array_fromattr( PyObject * op , PyArray_Typecode * typecode , int flags)", "filename": "arrayobject.c", "nloc": 30, "complexity": 5, "token_count": 181, "parameters": [ "op", "typecode", "flags" ], "start_line": 5374, "end_line": 5405, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "array_fromobject", "long_name": "array_fromobject( PyObject * op , PyArray_Typecode * typecode , int min_depth , int max_depth , int flags)", "filename": "arrayobject.c", "nloc": 49, "complexity": 14, "token_count": 291, "parameters": [ "op", "typecode", "min_depth", "max_depth", "flags" ], "start_line": 5409, "end_line": 5474, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 66, "top_nesting_level": 0 }, { "name": "PyArray_ArrayType", "long_name": "PyArray_ArrayType( PyObject * op , PyArray_Typecode * intype , PyArray_Typecode * outtype)", "filename": "arrayobject.c", "nloc": 6, "complexity": 1, "token_count": 29, "parameters": [ "op", "intype", "outtype" ], "start_line": 5477, "end_line": 5482, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "PyArray_ObjectType", "long_name": "PyArray_ObjectType( PyObject * op , int minimum_type)", "filename": "arrayobject.c", "nloc": 7, "complexity": 1, "token_count": 40, "parameters": [ "op", "minimum_type" ], "start_line": 5485, "end_line": 5491, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "PyArray_FromAny", "long_name": "PyArray_FromAny( PyObject * op , PyArray_Typecode * typecode , int min_depth , int max_depth , int requires)", "filename": "arrayobject.c", "nloc": 24, "complexity": 9, "token_count": 165, "parameters": [ "op", "typecode", "min_depth", "max_depth", "requires" ], "start_line": 5545, "end_line": 5575, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "PyArray_EnsureArray", "long_name": "PyArray_EnsureArray( PyObject * op)", "filename": "arrayobject.c", "nloc": 14, "complexity": 5, "token_count": 87, "parameters": [ "op" ], "start_line": 5586, "end_line": 5602, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "PyArray_FromObject", "long_name": "PyArray_FromObject( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 7, "complexity": 1, "token_count": 51, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5608, "end_line": 5614, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "PyArray_ContiguousFromObject", "long_name": "PyArray_ContiguousFromObject( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 8, "complexity": 1, "token_count": 51, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5617, "end_line": 5624, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_CopyFromObject", "long_name": "PyArray_CopyFromObject( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 8, "complexity": 1, "token_count": 51, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5627, "end_line": 5634, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_ContiguousFromAny", "long_name": "PyArray_ContiguousFromAny( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 8, "complexity": 1, "token_count": 49, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5639, "end_line": 5646, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_CanCastSafely", "long_name": "PyArray_CanCastSafely( int fromtype , int totype)", "filename": "arrayobject.c", "nloc": 81, "complexity": 39, "token_count": 476, "parameters": [ "fromtype", "totype" ], "start_line": 5649, "end_line": 5732, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 84, "top_nesting_level": 0 }, { "name": "PyArray_CanCastTo", "long_name": "PyArray_CanCastTo( PyArray_Typecode * from , PyArray_Typecode * to)", "filename": "arrayobject.c", "nloc": 24, "complexity": 7, "token_count": 134, "parameters": [ "from", "to" ], "start_line": 5735, "end_line": 5759, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 }, { "name": "PyArray_IterNew", "long_name": "PyArray_IterNew( PyObject * obj)", "filename": "arrayobject.c", "nloc": 34, "complexity": 6, "token_count": 258, "parameters": [ "obj" ], "start_line": 5769, "end_line": 5806, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "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": 5811, "end_line": 5821, "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": 6, "complexity": 1, "token_count": 25, "parameters": [ "it" ], "start_line": 5824, "end_line": 5829, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "arrayiter_traverse", "long_name": "arrayiter_traverse( PyArrayIterObject * it , visitproc visit , * arg)", "filename": "arrayobject.c", "nloc": 6, "complexity": 2, "token_count": 42, "parameters": [ "it", "visit", "arg" ], "start_line": 5832, "end_line": 5837, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "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": 5841, "end_line": 5844, "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": 42, "complexity": 7, "token_count": 272, "parameters": [ "self", "ind" ], "start_line": 5848, "end_line": 5896, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "iter_subscript_int", "long_name": "iter_subscript_int( PyArrayIterObject * self , PyArrayObject * ind)", "filename": "arrayobject.c", "nloc": 51, "complexity": 8, "token_count": 347, "parameters": [ "self", "ind" ], "start_line": 5899, "end_line": 5952, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 0 }, { "name": "iter_subscript", "long_name": "iter_subscript( PyArrayIterObject * self , PyObject * ind)", "filename": "arrayobject.c", "nloc": 97, "complexity": 20, "token_count": 593, "parameters": [ "self", "ind" ], "start_line": 5956, "end_line": 6075, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 120, "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": 176, "parameters": [ "self", "ind", "val", "swap" ], "start_line": 6079, "end_line": 6111, "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": 289, "parameters": [ "self", "ind", "val", "swap" ], "start_line": 6114, "end_line": 6156, "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": 103, "complexity": 24, "token_count": 636, "parameters": [ "self", "ind", "val" ], "start_line": 6160, "end_line": 6282, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 123, "top_nesting_level": 0 }, { "name": "iter_array", "long_name": "iter_array( PyArrayIterObject * it , PyObject * op)", "filename": "arrayobject.c", "nloc": 30, "complexity": 5, "token_count": 221, "parameters": [ "it", "op" ], "start_line": 6295, "end_line": 6337, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "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": 6342, "end_line": 6346, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "fancy_indexing_check", "long_name": "fancy_indexing_check( PyObject * args)", "filename": "arrayobject.c", "nloc": 55, "complexity": 22, "token_count": 293, "parameters": [ "args" ], "start_line": 6411, "end_line": 6472, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 62, "top_nesting_level": 0 }, { "name": "_convert_obj", "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", "filename": "arrayobject.c", "nloc": 15, "complexity": 5, "token_count": 105, "parameters": [ "obj", "iter" ], "start_line": 6480, "end_line": 6495, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "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": 6501, "end_line": 6570, "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": 261, "parameters": [ "mit" ], "start_line": 6574, "end_line": 6611, "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": 296, "parameters": [ "mit" ], "start_line": 6617, "end_line": 6661, "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": 102, "complexity": 22, "token_count": 690, "parameters": [ "mit", "arr" ], "start_line": 6679, "end_line": 6815, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 137, "top_nesting_level": 0 }, { "name": "_nonzero_indices", "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", "filename": "arrayobject.c", "nloc": 57, "complexity": 15, "token_count": 454, "parameters": [ "myBool", "iters" ], "start_line": 6821, "end_line": 6890, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 70, "top_nesting_level": 0 }, { "name": "PyArray_MapIterNew", "long_name": "PyArray_MapIterNew( PyObject * indexobj)", "filename": "arrayobject.c", "nloc": 111, "complexity": 24, "token_count": 745, "parameters": [ "indexobj" ], "start_line": 6893, "end_line": 7026, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 134, "top_nesting_level": 0 }, { "name": "arraymapiter_new", "long_name": "arraymapiter_new( PyTypeObject * type , PyObject * args , PyObject * kwds)", "filename": "arrayobject.c", "nloc": 26, "complexity": 5, "token_count": 130, "parameters": [ "type", "args", "kwds" ], "start_line": 7032, "end_line": 7062, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "arraymapiter_dealloc", "long_name": "arraymapiter_dealloc( PyArrayMapIterObject * mit)", "filename": "arrayobject.c", "nloc": 10, "complexity": 2, "token_count": 60, "parameters": [ "mit" ], "start_line": 7083, "end_line": 7092, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "arraymapiter_traverse", "long_name": "arraymapiter_traverse( PyArrayMapIterObject * mit , visitproc visit , * arg)", "filename": "arrayobject.c", "nloc": 16, "complexity": 9, "token_count": 146, "parameters": [ "mit", "visit", "arg" ], "start_line": 7095, "end_line": 7113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 } ], "methods_before": [ { "name": "PyArray_PyIntAsIntp", "long_name": "PyArray_PyIntAsIntp( PyObject * o)", "filename": "arrayobject.c", "nloc": 59, "complexity": 19, "token_count": 385, "parameters": [ "o" ], "start_line": 40, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 64, "top_nesting_level": 0 }, { "name": "PyArray_PyIntAsInt", "long_name": "PyArray_PyIntAsInt( PyObject * o)", "filename": "arrayobject.c", "nloc": 57, "complexity": 19, "token_count": 389, "parameters": [ "o" ], "start_line": 109, "end_line": 169, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 61, "top_nesting_level": 0 }, { "name": "PyArray_GetPriority", "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", "filename": "arrayobject.c", "nloc": 17, "complexity": 5, "token_count": 86, "parameters": [ "obj", "default_" ], "start_line": 173, "end_line": 191, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "PyArray_Zero", "long_name": "PyArray_Zero( PyArrayObject * arr)", "filename": "arrayobject.c", "nloc": 34, "complexity": 6, "token_count": 190, "parameters": [ "arr" ], "start_line": 208, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "PyArray_One", "long_name": "PyArray_One( PyArrayObject * arr)", "filename": "arrayobject.c", "nloc": 40, "complexity": 7, "token_count": 222, "parameters": [ "arr" ], "start_line": 246, "end_line": 289, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "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": 295, "end_line": 345, "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": 368, "end_line": 399, "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": 213, "parameters": [ "src" ], "start_line": 402, "end_line": 436, "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": 449, "end_line": 471, "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": 474, "end_line": 495, "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": 499, "end_line": 537, "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": 542, "end_line": 562, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "index2ptr", "long_name": "index2ptr( PyArrayObject * mp , int i)", "filename": "arrayobject.c", "nloc": 10, "complexity": 7, "token_count": 86, "parameters": [ "mp", "i" ], "start_line": 570, "end_line": 580, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "PyArray_Size", "long_name": "PyArray_Size( PyObject * op)", "filename": "arrayobject.c", "nloc": 9, "complexity": 2, "token_count": 33, "parameters": [ "op" ], "start_line": 583, "end_line": 591, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "PyArray_CopyInto", "long_name": "PyArray_CopyInto( PyArrayObject * dest , PyArrayObject * src)", "filename": "arrayobject.c", "nloc": 71, "complexity": 16, "token_count": 427, "parameters": [ "dest", "src" ], "start_line": 604, "end_line": 684, "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": 16, "complexity": 2, "token_count": 98, "parameters": [ "dest", "src_object" ], "start_line": 688, "end_line": 707, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "PyArray_FromDimsAndDataAndDescr", "long_name": "PyArray_FromDimsAndDataAndDescr( int nd , int * d , PyArray_Descr * descr , char * data)", "filename": "arrayobject.c", "nloc": 15, "complexity": 3, "token_count": 121, "parameters": [ "nd", "d", "descr", "data" ], "start_line": 715, "end_line": 734, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "PyArray_FromDimsAndData", "long_name": "PyArray_FromDimsAndData( int nd , int * d , int type , char * data)", "filename": "arrayobject.c", "nloc": 14, "complexity": 3, "token_count": 112, "parameters": [ "nd", "d", "type", "data" ], "start_line": 738, "end_line": 755, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "PyArray_FromDims", "long_name": "PyArray_FromDims( int nd , int * d , int type)", "filename": "arrayobject.c", "nloc": 14, "complexity": 5, "token_count": 133, "parameters": [ "nd", "d", "type" ], "start_line": 759, "end_line": 776, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "PyArray_Copy", "long_name": "PyArray_Copy( PyArrayObject * m1)", "filename": "arrayobject.c", "nloc": 11, "complexity": 2, "token_count": 77, "parameters": [ "m1" ], "start_line": 782, "end_line": 794, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "PyArray_Scalar", "long_name": "PyArray_Scalar( char * data , int type_num , int itemsize , int swap)", "filename": "arrayobject.c", "nloc": 48, "complexity": 8, "token_count": 289, "parameters": [ "data", "type_num", "itemsize", "swap" ], "start_line": 800, "end_line": 849, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "top_nesting_level": 0 }, { "name": "PyArray_ToScalar", "long_name": "PyArray_ToScalar( char * data , PyArrayObject * arr)", "filename": "arrayobject.c", "nloc": 7, "complexity": 1, "token_count": 51, "parameters": [ "data", "arr" ], "start_line": 856, "end_line": 863, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_Return", "long_name": "PyArray_Return( PyArrayObject * mp)", "filename": "arrayobject.c", "nloc": 17, "complexity": 5, "token_count": 85, "parameters": [ "mp" ], "start_line": 869, "end_line": 888, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "PyArray_RegisterDataType", "long_name": "PyArray_RegisterDataType( PyTypeObject * type)", "filename": "arrayobject.c", "nloc": 31, "complexity": 6, "token_count": 177, "parameters": [ "type" ], "start_line": 899, "end_line": 931, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "PyArray_RegisterDescrForType", "long_name": "PyArray_RegisterDescrForType( int typenum , PyArray_Descr * descr)", "filename": "arrayobject.c", "nloc": 32, "complexity": 3, "token_count": 167, "parameters": [ "typenum", "descr" ], "start_line": 941, "end_line": 984, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "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": 16, "token_count": 577, "parameters": [ "self", "fp", "sep", "format" ], "start_line": 988, "end_line": 1079, "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": 24, "complexity": 5, "token_count": 151, "parameters": [ "self" ], "start_line": 1082, "end_line": 1110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "PyArray_ToString", "long_name": "PyArray_ToString( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 34, "complexity": 6, "token_count": 191, "parameters": [ "self" ], "start_line": 1113, "end_line": 1148, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "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": 1157, "end_line": 1194, "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": 1201, "end_line": 1209, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "array_item", "long_name": "array_item( PyArrayObject * self , int i)", "filename": "arrayobject.c", "nloc": 22, "complexity": 4, "token_count": 150, "parameters": [ "self", "i" ], "start_line": 1213, "end_line": 1237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "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": 26, "parameters": [ "self", "i" ], "start_line": 1240, "end_line": 1243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "array_ass_item", "long_name": "array_ass_item( PyArrayObject * self , int i , PyObject * v)", "filename": "arrayobject.c", "nloc": 27, "complexity": 8, "token_count": 177, "parameters": [ "self", "i", "v" ], "start_line": 1247, "end_line": 1277, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "slice_coerce_index", "long_name": "slice_coerce_index( PyObject * o , int * v)", "filename": "arrayobject.c", "nloc": 9, "complexity": 2, "token_count": 40, "parameters": [ "o", "v" ], "start_line": 1281, "end_line": 1289, "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 , int length , int * start , int * stop , int * step , intp * slicelength)", "filename": "arrayobject.c", "nloc": 45, "complexity": 24, "token_count": 376, "parameters": [ "r", "length", "start", "stop", "step", "slicelength" ], "start_line": 1295, "end_line": 1345, "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 , int * step_size , intp * n_steps , int max)", "filename": "arrayobject.c", "nloc": 45, "complexity": 11, "token_count": 223, "parameters": [ "op", "step_size", "n_steps", "max" ], "start_line": 1352, "end_line": 1397, "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": 89, "complexity": 20, "token_count": 540, "parameters": [ "self", "op", "dimensions", "strides", "offset_ptr" ], "start_line": 1401, "end_line": 1496, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 96, "top_nesting_level": 0 }, { "name": "_swap_axes", "long_name": "_swap_axes( PyArrayMapIterObject * mit , PyArrayObject ** ret)", "filename": "arrayobject.c", "nloc": 24, "complexity": 4, "token_count": 187, "parameters": [ "mit", "ret" ], "start_line": 1499, "end_line": 1533, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "PyArray_GetMap", "long_name": "PyArray_GetMap( PyArrayMapIterObject * mit)", "filename": "arrayobject.c", "nloc": 36, "complexity": 8, "token_count": 252, "parameters": [ "mit" ], "start_line": 1538, "end_line": 1587, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "top_nesting_level": 0 }, { "name": "PyArray_SetMap", "long_name": "PyArray_SetMap( PyArrayMapIterObject * mit , PyObject * op)", "filename": "arrayobject.c", "nloc": 50, "complexity": 12, "token_count": 392, "parameters": [ "mit", "op" ], "start_line": 1590, "end_line": 1649, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 60, "top_nesting_level": 0 }, { "name": "array_subscript", "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", "filename": "arrayobject.c", "nloc": 61, "complexity": 19, "token_count": 425, "parameters": [ "self", "op" ], "start_line": 1670, "end_line": 1745, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 76, "top_nesting_level": 0 }, { "name": "array_ass_sub", "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", "filename": "arrayobject.c", "nloc": 43, "complexity": 9, "token_count": 251, "parameters": [ "self", "index", "op" ], "start_line": 1758, "end_line": 1810, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "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": 1818, "end_line": 1821, "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": 1840, "end_line": 1852, "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": 1855, "end_line": 1870, "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": 1874, "end_line": 1883, "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": 1886, "end_line": 1897, "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": 1965, "end_line": 1998, "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": 2005, "end_line": 2044, "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": 23, "complexity": 5, "token_count": 136, "parameters": [ "m1", "op", "axis", "rtype" ], "start_line": 2047, "end_line": 2069, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "PyArray_GenericAccumulateFunction", "long_name": "PyArray_GenericAccumulateFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", "filename": "arrayobject.c", "nloc": 23, "complexity": 5, "token_count": 136, "parameters": [ "m1", "op", "axis", "rtype" ], "start_line": 2073, "end_line": 2095, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "PyArray_GenericBinaryFunction", "long_name": "PyArray_GenericBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", "filename": "arrayobject.c", "nloc": 12, "complexity": 2, "token_count": 69, "parameters": [ "m1", "m2", "op" ], "start_line": 2099, "end_line": 2110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_GenericUnaryFunction", "long_name": "PyArray_GenericUnaryFunction( PyArrayObject * m1 , PyObject * op)", "filename": "arrayobject.c", "nloc": 12, "complexity": 2, "token_count": 63, "parameters": [ "m1", "op" ], "start_line": 2113, "end_line": 2124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_GenericInplaceBinaryFunction", "long_name": "PyArray_GenericInplaceBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", "filename": "arrayobject.c", "nloc": 13, "complexity": 2, "token_count": 71, "parameters": [ "m1", "m2", "op" ], "start_line": 2127, "end_line": 2139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 2142, "end_line": 2145, "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": 2148, "end_line": 2151, "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": 2154, "end_line": 2157, "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": 2160, "end_line": 2163, "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": 2166, "end_line": 2169, "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": 2172, "end_line": 2175, "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": 2178, "end_line": 2181, "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": 2184, "end_line": 2187, "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": 2190, "end_line": 2193, "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": 2196, "end_line": 2199, "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": 2202, "end_line": 2205, "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": 2208, "end_line": 2211, "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": 2214, "end_line": 2217, "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": 2220, "end_line": 2223, "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": 2226, "end_line": 2229, "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": 2232, "end_line": 2235, "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": 2238, "end_line": 2241, "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": 2244, "end_line": 2247, "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": 2250, "end_line": 2253, "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": 2256, "end_line": 2259, "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": 2262, "end_line": 2265, "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": 2268, "end_line": 2271, "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": 2274, "end_line": 2277, "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": 2280, "end_line": 2283, "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": 2286, "end_line": 2289, "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": 2292, "end_line": 2295, "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": 2298, "end_line": 2301, "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": 2304, "end_line": 2308, "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": 2311, "end_line": 2315, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "array_all_nonzero", "long_name": "array_all_nonzero( PyArrayObject * mp)", "filename": "arrayobject.c", "nloc": 18, "complexity": 4, "token_count": 93, "parameters": [ "mp" ], "start_line": 2319, "end_line": 2337, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "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": 2340, "end_line": 2355, "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": 143, "parameters": [ "v" ], "start_line": 2359, "end_line": 2385, "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": 143, "parameters": [ "v" ], "start_line": 2388, "end_line": 2413, "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": 124, "parameters": [ "v" ], "start_line": 2416, "end_line": 2438, "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": 124, "parameters": [ "v" ], "start_line": 2441, "end_line": 2463, "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": 124, "parameters": [ "v" ], "start_line": 2466, "end_line": 2488, "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": 2491, "end_line": 2495, "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": 34, "complexity": 11, "token_count": 258, "parameters": [ "self", "ilow", "ihigh" ], "start_line": 2556, "end_line": 2594, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "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": 2598, "end_line": 2619, "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": 4, "complexity": 1, "token_count": 26, "parameters": [ "self", "el" ], "start_line": 2622, "end_line": 2627, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "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": 308, "parameters": [ "string", "n", "max_n", "data", "nd", "dimensions", "strides", "self" ], "start_line": 2648, "end_line": 2695, "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": 222, "parameters": [ "self" ], "start_line": 2698, "end_line": 2734, "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": 2740, "end_line": 2757, "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": 2760, "end_line": 2772, "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": 2775, "end_line": 2787, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "array_richcompare", "long_name": "array_richcompare( PyArrayObject * self , PyObject * other , int cmp_op)", "filename": "arrayobject.c", "nloc": 61, "complexity": 13, "token_count": 273, "parameters": [ "self", "other", "cmp_op" ], "start_line": 2791, "end_line": 2868, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 78, "top_nesting_level": 0 }, { "name": "_check_axis", "long_name": "_check_axis( PyArrayObject * arr , int * axis , int flags)", "filename": "arrayobject.c", "nloc": 29, "complexity": 8, "token_count": 164, "parameters": [ "arr", "axis", "flags" ], "start_line": 2871, "end_line": 2900, "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": 17, "complexity": 4, "token_count": 91, "parameters": [ "len", "vals" ], "start_line": 2906, "end_line": 2922, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "PyArray_IntpFromSequence", "long_name": "PyArray_IntpFromSequence( PyObject * seq , intp * vals , int maxvals)", "filename": "arrayobject.c", "nloc": 21, "complexity": 7, "token_count": 161, "parameters": [ "seq", "vals", "maxvals" ], "start_line": 2927, "end_line": 2950, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "_IsContiguous", "long_name": "_IsContiguous( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 14, "complexity": 6, "token_count": 109, "parameters": [ "ap" ], "start_line": 2956, "end_line": 2972, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_IsFortranContiguous", "long_name": "_IsFortranContiguous( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 14, "complexity": 6, "token_count": 107, "parameters": [ "ap" ], "start_line": 2976, "end_line": 2992, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_IsAligned", "long_name": "_IsAligned( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 14, "complexity": 4, "token_count": 110, "parameters": [ "ap" ], "start_line": 2995, "end_line": 3011, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_IsWriteable", "long_name": "_IsWriteable( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 16, "complexity": 8, "token_count": 109, "parameters": [ "ap" ], "start_line": 3014, "end_line": 3047, "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": 22, "complexity": 9, "token_count": 129, "parameters": [ "ret", "flagmask" ], "start_line": 3051, "end_line": 3073, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "PyArray_CheckStrides", "long_name": "PyArray_CheckStrides( int elsize , int nd , intp numbytes , intp * dims , intp * newstrides)", "filename": "arrayobject.c", "nloc": 13, "complexity": 4, "token_count": 84, "parameters": [ "elsize", "nd", "numbytes", "dims", "newstrides" ], "start_line": 3080, "end_line": 3095, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "_array_fill_strides", "long_name": "_array_fill_strides( intp * strides , intp * dims , int nd , intp itemsize , int inflag , int * objflags)", "filename": "arrayobject.c", "nloc": 24, "complexity": 9, "token_count": 171, "parameters": [ "strides", "dims", "nd", "itemsize", "inflag", "objflags" ], "start_line": 3115, "end_line": 3139, "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 , char * data , int itemsize , int flags , PyObject * obj)", "filename": "arrayobject.c", "nloc": 117, "complexity": 27, "token_count": 713, "parameters": [ "subtype", "nd", "dims", "type_num", "strides", "data", "itemsize", "flags", "obj" ], "start_line": 3143, "end_line": 3293, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 151, "top_nesting_level": 0 }, { "name": "PyArray_Resize", "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape)", "filename": "arrayobject.c", "nloc": 87, "complexity": 15, "token_count": 501, "parameters": [ "self", "newshape" ], "start_line": 3298, "end_line": 3403, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 106, "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": 3408, "end_line": 3425, "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": 47, "complexity": 7, "token_count": 261, "parameters": [ "arr", "obj" ], "start_line": 3428, "end_line": 3480, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "top_nesting_level": 0 }, { "name": "array_new", "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", "filename": "arrayobject.c", "nloc": 100, "complexity": 20, "token_count": 589, "parameters": [ "subtype", "args", "kwds" ], "start_line": 3483, "end_line": 3598, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 116, "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": 3605, "end_line": 3608, "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": 10, "complexity": 3, "token_count": 57, "parameters": [ "self" ], "start_line": 3611, "end_line": 3621, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "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": 3694, "end_line": 3697, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "array_shape_set", "long_name": "array_shape_set( PyArrayObject * self , PyObject * val)", "filename": "arrayobject.c", "nloc": 33, "complexity": 6, "token_count": 206, "parameters": [ "self", "val" ], "start_line": 3701, "end_line": 3735, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "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": 3739, "end_line": 3742, "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": 32, "complexity": 7, "token_count": 209, "parameters": [ "self", "obj" ], "start_line": 3745, "end_line": 3778, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "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": 3782, "end_line": 3789, "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": 3792, "end_line": 3800, "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": 3804, "end_line": 3810, "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": 3813, "end_line": 3827, "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": 3830, "end_line": 3874, "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": 19, "parameters": [ "self" ], "start_line": 3878, "end_line": 3881, "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": 8, "complexity": 3, "token_count": 45, "parameters": [ "self" ], "start_line": 3884, "end_line": 3891, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "array_typechar_get", "long_name": "array_typechar_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 8, "complexity": 2, "token_count": 47, "parameters": [ "self" ], "start_line": 3895, "end_line": 3902, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "array_typestr_get", "long_name": "array_typestr_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 19, "complexity": 7, "token_count": 141, "parameters": [ "self" ], "start_line": 3905, "end_line": 3925, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "array_descr_get", "long_name": "array_descr_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 19, "complexity": 5, "token_count": 128, "parameters": [ "self" ], "start_line": 3928, "end_line": 3950, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "array_type_get", "long_name": "array_type_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 4, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 3954, "end_line": 3957, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "array_type_set", "long_name": "array_type_set( PyArrayObject * self , PyObject * arg)", "filename": "arrayobject.c", "nloc": 41, "complexity": 10, "token_count": 294, "parameters": [ "self", "arg" ], "start_line": 3969, "end_line": 4027, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 59, "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": 4032, "end_line": 4042, "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": 4046, "end_line": 4071, "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": 31, "complexity": 4, "token_count": 177, "parameters": [ "self", "val" ], "start_line": 4075, "end_line": 4107, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "array_imag_get", "long_name": "array_imag_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 34, "complexity": 3, "token_count": 200, "parameters": [ "self" ], "start_line": 4110, "end_line": 4145, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "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": 203, "parameters": [ "self", "val" ], "start_line": 4148, "end_line": 4185, "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": 4188, "end_line": 4191, "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": 51, "complexity": 9, "token_count": 368, "parameters": [ "self", "val" ], "start_line": 4194, "end_line": 4248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 55, "top_nesting_level": 0 }, { "name": "discover_depth", "long_name": "discover_depth( PyObject * s , int max , int stop_at_string)", "filename": "arrayobject.c", "nloc": 23, "complexity": 14, "token_count": 169, "parameters": [ "s", "max", "stop_at_string" ], "start_line": 4423, "end_line": 4448, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "discover_itemsize", "long_name": "discover_itemsize( PyObject * s , int nd , int * itemsize)", "filename": "arrayobject.c", "nloc": 21, "complexity": 9, "token_count": 161, "parameters": [ "s", "nd", "itemsize" ], "start_line": 4451, "end_line": 4473, "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": 4480, "end_line": 4506, "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( int chktype , int mintype , int chksize , int minsize , PyArray_Typecode * outtype)", "filename": "arrayobject.c", "nloc": 19, "complexity": 5, "token_count": 100, "parameters": [ "chktype", "mintype", "chksize", "minsize", "outtype" ], "start_line": 4509, "end_line": 4529, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "_array_find_type", "long_name": "_array_find_type( PyObject * op , PyArray_Typecode * minitype , PyArray_Typecode * outtype , int max)", "filename": "arrayobject.c", "nloc": 126, "complexity": 28, "token_count": 671, "parameters": [ "op", "minitype", "outtype", "max" ], "start_line": 4532, "end_line": 4673, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 142, "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": 4676, "end_line": 4699, "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_Typecode * typecode)", "filename": "arrayobject.c", "nloc": 19, "complexity": 4, "token_count": 120, "parameters": [ "op", "typecode" ], "start_line": 4703, "end_line": 4726, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "Array_FromSequence", "long_name": "Array_FromSequence( PyObject * s , PyArray_Typecode * typecode , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 51, "complexity": 17, "token_count": 313, "parameters": [ "s", "typecode", "min_depth", "max_depth" ], "start_line": 4730, "end_line": 4787, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 58, "top_nesting_level": 0 }, { "name": "PyArray_ValidType", "long_name": "PyArray_ValidType( int type)", "filename": "arrayobject.c", "nloc": 7, "complexity": 2, "token_count": 30, "parameters": [ "type" ], "start_line": 4791, "end_line": 4798, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "_bufferedcast", "long_name": "_bufferedcast( PyArrayObject * out , PyArrayObject * in)", "filename": "arrayobject.c", "nloc": 75, "complexity": 16, "token_count": 477, "parameters": [ "out", "in" ], "start_line": 4804, "end_line": 4894, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 91, "top_nesting_level": 0 }, { "name": "PyArray_Cast", "long_name": "PyArray_Cast( PyArrayObject * mp , int type_num)", "filename": "arrayobject.c", "nloc": 10, "complexity": 1, "token_count": 56, "parameters": [ "mp", "type_num" ], "start_line": 4900, "end_line": 4911, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_CastToType", "long_name": "PyArray_CastToType( PyArrayObject * mp , PyArray_Typecode * at)", "filename": "arrayobject.c", "nloc": 31, "complexity": 13, "token_count": 233, "parameters": [ "mp", "at" ], "start_line": 4914, "end_line": 4949, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "PyArray_CastTo", "long_name": "PyArray_CastTo( PyArrayObject * out , PyArrayObject * mp)", "filename": "arrayobject.c", "nloc": 40, "complexity": 10, "token_count": 214, "parameters": [ "out", "mp" ], "start_line": 4956, "end_line": 5002, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "array_fromarray", "long_name": "array_fromarray( PyArrayObject * arr , PyArray_Typecode * typecode , int flags)", "filename": "arrayobject.c", "nloc": 116, "complexity": 35, "token_count": 725, "parameters": [ "arr", "typecode", "flags" ], "start_line": 5005, "end_line": 5136, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 132, "top_nesting_level": 0 }, { "name": "_array_typecode_fromstr", "long_name": "_array_typecode_fromstr( char * str , int * swap , PyArray_Typecode * type)", "filename": "arrayobject.c", "nloc": 94, "complexity": 36, "token_count": 533, "parameters": [ "str", "swap", "type" ], "start_line": 5140, "end_line": 5245, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 106, "top_nesting_level": 0 }, { "name": "array_frominterface", "long_name": "array_frominterface( PyObject * input , PyArray_Typecode * intype , int flags)", "filename": "arrayobject.c", "nloc": 113, "complexity": 26, "token_count": 715, "parameters": [ "input", "intype", "flags" ], "start_line": 5248, "end_line": 5371, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 124, "top_nesting_level": 0 }, { "name": "array_fromattr", "long_name": "array_fromattr( PyObject * op , PyArray_Typecode * typecode , int flags)", "filename": "arrayobject.c", "nloc": 30, "complexity": 5, "token_count": 181, "parameters": [ "op", "typecode", "flags" ], "start_line": 5374, "end_line": 5405, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "array_fromobject", "long_name": "array_fromobject( PyObject * op , PyArray_Typecode * typecode , int min_depth , int max_depth , int flags)", "filename": "arrayobject.c", "nloc": 49, "complexity": 14, "token_count": 291, "parameters": [ "op", "typecode", "min_depth", "max_depth", "flags" ], "start_line": 5409, "end_line": 5474, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 66, "top_nesting_level": 0 }, { "name": "PyArray_ArrayType", "long_name": "PyArray_ArrayType( PyObject * op , PyArray_Typecode * intype , PyArray_Typecode * outtype)", "filename": "arrayobject.c", "nloc": 6, "complexity": 1, "token_count": 29, "parameters": [ "op", "intype", "outtype" ], "start_line": 5477, "end_line": 5482, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "PyArray_ObjectType", "long_name": "PyArray_ObjectType( PyObject * op , int minimum_type)", "filename": "arrayobject.c", "nloc": 7, "complexity": 1, "token_count": 40, "parameters": [ "op", "minimum_type" ], "start_line": 5485, "end_line": 5491, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "PyArray_FromAny", "long_name": "PyArray_FromAny( PyObject * op , PyArray_Typecode * typecode , int min_depth , int max_depth , int requires)", "filename": "arrayobject.c", "nloc": 24, "complexity": 9, "token_count": 165, "parameters": [ "op", "typecode", "min_depth", "max_depth", "requires" ], "start_line": 5545, "end_line": 5575, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "PyArray_EnsureArray", "long_name": "PyArray_EnsureArray( PyObject * op)", "filename": "arrayobject.c", "nloc": 14, "complexity": 5, "token_count": 87, "parameters": [ "op" ], "start_line": 5586, "end_line": 5602, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "PyArray_FromObject", "long_name": "PyArray_FromObject( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 7, "complexity": 1, "token_count": 51, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5608, "end_line": 5614, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "PyArray_ContiguousFromObject", "long_name": "PyArray_ContiguousFromObject( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 8, "complexity": 1, "token_count": 51, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5617, "end_line": 5624, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_CopyFromObject", "long_name": "PyArray_CopyFromObject( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 8, "complexity": 1, "token_count": 51, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5627, "end_line": 5634, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_ContiguousFromAny", "long_name": "PyArray_ContiguousFromAny( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 8, "complexity": 1, "token_count": 49, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5639, "end_line": 5646, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_CanCastSafely", "long_name": "PyArray_CanCastSafely( int fromtype , int totype)", "filename": "arrayobject.c", "nloc": 81, "complexity": 39, "token_count": 476, "parameters": [ "fromtype", "totype" ], "start_line": 5649, "end_line": 5732, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 84, "top_nesting_level": 0 }, { "name": "PyArray_CanCastTo", "long_name": "PyArray_CanCastTo( PyArray_Typecode * from , PyArray_Typecode * to)", "filename": "arrayobject.c", "nloc": 24, "complexity": 7, "token_count": 134, "parameters": [ "from", "to" ], "start_line": 5735, "end_line": 5759, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 }, { "name": "PyArray_IterNew", "long_name": "PyArray_IterNew( PyObject * obj)", "filename": "arrayobject.c", "nloc": 34, "complexity": 6, "token_count": 258, "parameters": [ "obj" ], "start_line": 5769, "end_line": 5806, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "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": 5811, "end_line": 5821, "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": 6, "complexity": 1, "token_count": 25, "parameters": [ "it" ], "start_line": 5824, "end_line": 5829, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "arrayiter_traverse", "long_name": "arrayiter_traverse( PyArrayIterObject * it , visitproc visit , * arg)", "filename": "arrayobject.c", "nloc": 6, "complexity": 2, "token_count": 42, "parameters": [ "it", "visit", "arg" ], "start_line": 5832, "end_line": 5837, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "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": 5841, "end_line": 5844, "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": 42, "complexity": 7, "token_count": 272, "parameters": [ "self", "ind" ], "start_line": 5848, "end_line": 5896, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "iter_subscript_int", "long_name": "iter_subscript_int( PyArrayIterObject * self , PyArrayObject * ind)", "filename": "arrayobject.c", "nloc": 51, "complexity": 8, "token_count": 347, "parameters": [ "self", "ind" ], "start_line": 5899, "end_line": 5952, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 0 }, { "name": "iter_subscript", "long_name": "iter_subscript( PyArrayIterObject * self , PyObject * ind)", "filename": "arrayobject.c", "nloc": 97, "complexity": 20, "token_count": 593, "parameters": [ "self", "ind" ], "start_line": 5956, "end_line": 6075, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 120, "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": 176, "parameters": [ "self", "ind", "val", "swap" ], "start_line": 6079, "end_line": 6111, "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": 289, "parameters": [ "self", "ind", "val", "swap" ], "start_line": 6114, "end_line": 6156, "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": 103, "complexity": 24, "token_count": 636, "parameters": [ "self", "ind", "val" ], "start_line": 6160, "end_line": 6282, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 123, "top_nesting_level": 0 }, { "name": "iter_array", "long_name": "iter_array( PyArrayIterObject * it , PyObject * op)", "filename": "arrayobject.c", "nloc": 30, "complexity": 5, "token_count": 221, "parameters": [ "it", "op" ], "start_line": 6295, "end_line": 6337, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "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": 6342, "end_line": 6346, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "fancy_indexing_check", "long_name": "fancy_indexing_check( PyObject * args)", "filename": "arrayobject.c", "nloc": 55, "complexity": 22, "token_count": 293, "parameters": [ "args" ], "start_line": 6411, "end_line": 6472, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 62, "top_nesting_level": 0 }, { "name": "_convert_obj", "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", "filename": "arrayobject.c", "nloc": 15, "complexity": 5, "token_count": 105, "parameters": [ "obj", "iter" ], "start_line": 6480, "end_line": 6495, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "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": 6501, "end_line": 6570, "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": 261, "parameters": [ "mit" ], "start_line": 6574, "end_line": 6611, "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": 296, "parameters": [ "mit" ], "start_line": 6617, "end_line": 6661, "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": 102, "complexity": 22, "token_count": 690, "parameters": [ "mit", "arr" ], "start_line": 6679, "end_line": 6815, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 137, "top_nesting_level": 0 }, { "name": "_nonzero_indices", "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", "filename": "arrayobject.c", "nloc": 57, "complexity": 15, "token_count": 454, "parameters": [ "myBool", "iters" ], "start_line": 6821, "end_line": 6890, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 70, "top_nesting_level": 0 }, { "name": "PyArray_MapIterNew", "long_name": "PyArray_MapIterNew( PyObject * indexobj)", "filename": "arrayobject.c", "nloc": 111, "complexity": 24, "token_count": 745, "parameters": [ "indexobj" ], "start_line": 6893, "end_line": 7026, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 134, "top_nesting_level": 0 }, { "name": "arraymapiter_new", "long_name": "arraymapiter_new( PyTypeObject * type , PyObject * args , PyObject * kwds)", "filename": "arrayobject.c", "nloc": 26, "complexity": 5, "token_count": 130, "parameters": [ "type", "args", "kwds" ], "start_line": 7032, "end_line": 7062, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "arraymapiter_dealloc", "long_name": "arraymapiter_dealloc( PyArrayMapIterObject * mit)", "filename": "arrayobject.c", "nloc": 10, "complexity": 2, "token_count": 60, "parameters": [ "mit" ], "start_line": 7083, "end_line": 7092, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "arraymapiter_traverse", "long_name": "arraymapiter_traverse( PyArrayMapIterObject * mit , visitproc visit , * arg)", "filename": "arrayobject.c", "nloc": 16, "complexity": 9, "token_count": 146, "parameters": [ "mit", "visit", "arg" ], "start_line": 7095, "end_line": 7113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "array_fromarray", "long_name": "array_fromarray( PyArrayObject * arr , PyArray_Typecode * typecode , int flags)", "filename": "arrayobject.c", "nloc": 116, "complexity": 35, "token_count": 721, "parameters": [ "arr", "typecode", "flags" ], "start_line": 5005, "end_line": 5136, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 132, "top_nesting_level": 0 } ], "nloc": 5641, "complexity": 1232, "token_count": 33713, "diff_parsed": { "added": [ "\t\t\t\t\t type," ], "deleted": [ "\t\t\t\t\t arr->descr->type_num," ] } } ] }, { "hash": "72c2028abbdc2add6948a0551d4231852d7390b0", "msg": "Unittests for new array_from_pyobj in f2py.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2005-10-25T21:41:12+00:00", "author_timezone": 0, "committer_date": "2005-10-25T21:41:12+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "3696fd0515c0aa8a144a34e53748f4eee143f15c" ], "project_name": "repo_copy", "project_path": "/tmp/tmpn4cqam_6/repo_copy", "deletions": 0, "insertions": 521, "lines": 521, "files": 4, "dmm_unit_size": 0.5, "dmm_unit_complexity": 0.8103448275862069, "dmm_unit_interfacing": 0.8419540229885057, "modified_files": [ { "old_path": "scipy/f2py2e/tests/array_from_pyobj/__init__.py", "new_path": "scipy/f2py2e/tests/array_from_pyobj/__init__.py", "filename": "__init__.py", "extension": "py", "change_type": "ADD", "diff": "", "added_lines": 0, "deleted_lines": 0, "source_code": null, "source_code_before": null, "methods": [], "methods_before": [], "changed_methods": [], "nloc": null, "complexity": null, "token_count": null, "diff_parsed": { "added": [], "deleted": [] } }, { "old_path": null, "new_path": "scipy/f2py2e/tests/array_from_pyobj/setup.py", "filename": "setup.py", "extension": "py", "change_type": "ADD", "diff": "@@ -0,0 +1,22 @@\n+\n+import os\n+def configuration(parent_name='',top_path=None):\n+ from scipy.distutils.misc_util import Configuration\n+ import scipy.f2py as f2py\n+ f2pydir=os.path.dirname(os.path.abspath(f2py.__file__))\n+ f2pydir=os.path.abspath('../../')\n+ fobjhsrc = os.path.join(f2pydir,'src','fortranobject.h')\n+ fobjcsrc = os.path.join(f2pydir,'src','fortranobject.c')\n+ config = Configuration('array_from_pyobj',parent_name,top_path)\n+ config.add_extension('wrap',\n+ sources = ['wrapmodule.c',fobjcsrc],\n+ include_dirs = [os.path.dirname(fobjhsrc)],\n+ depends = [fobjhsrc,fobjcsrc],\n+ define_macros = [('DEBUG_COPY_ND_ARRAY',1)]\n+ )\n+\n+ return config\n+\n+if __name__ == \"__main__\":\n+ from scipy.distutils.core import setup\n+ setup(**configuration(top_path='').todict())\n", "added_lines": 22, "deleted_lines": 0, "source_code": "\nimport os\ndef configuration(parent_name='',top_path=None):\n from scipy.distutils.misc_util import Configuration\n import scipy.f2py as f2py\n f2pydir=os.path.dirname(os.path.abspath(f2py.__file__))\n f2pydir=os.path.abspath('../../')\n fobjhsrc = os.path.join(f2pydir,'src','fortranobject.h')\n fobjcsrc = os.path.join(f2pydir,'src','fortranobject.c')\n config = Configuration('array_from_pyobj',parent_name,top_path)\n config.add_extension('wrap',\n sources = ['wrapmodule.c',fobjcsrc],\n include_dirs = [os.path.dirname(fobjhsrc)],\n depends = [fobjhsrc,fobjcsrc],\n define_macros = [('DEBUG_COPY_ND_ARRAY',1)]\n )\n\n return config\n\nif __name__ == \"__main__\":\n from scipy.distutils.core import setup\n setup(**configuration(top_path='').todict())\n", "source_code_before": null, "methods": [ { "name": "configuration", "long_name": "configuration( parent_name = '' , top_path = None )", "filename": "setup.py", "nloc": 15, "complexity": 1, "token_count": 139, "parameters": [ "parent_name", "top_path" ], "start_line": 3, "end_line": 18, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 } ], "methods_before": [], "changed_methods": [ { "name": "configuration", "long_name": "configuration( parent_name = '' , top_path = None )", "filename": "setup.py", "nloc": 15, "complexity": 1, "token_count": 139, "parameters": [ "parent_name", "top_path" ], "start_line": 3, "end_line": 18, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 } ], "nloc": 19, "complexity": 1, "token_count": 169, "diff_parsed": { "added": [ "", "import os", "def configuration(parent_name='',top_path=None):", " from scipy.distutils.misc_util import Configuration", " import scipy.f2py as f2py", " f2pydir=os.path.dirname(os.path.abspath(f2py.__file__))", " f2pydir=os.path.abspath('../../')", " fobjhsrc = os.path.join(f2pydir,'src','fortranobject.h')", " fobjcsrc = os.path.join(f2pydir,'src','fortranobject.c')", " config = Configuration('array_from_pyobj',parent_name,top_path)", " config.add_extension('wrap',", " sources = ['wrapmodule.c',fobjcsrc],", " include_dirs = [os.path.dirname(fobjhsrc)],", " depends = [fobjhsrc,fobjcsrc],", " define_macros = [('DEBUG_COPY_ND_ARRAY',1)]", " )", "", " return config", "", "if __name__ == \"__main__\":", " from scipy.distutils.core import setup", " setup(**configuration(top_path='').todict())" ], "deleted": [] } }, { "old_path": null, "new_path": "scipy/f2py2e/tests/array_from_pyobj/tests/test_array_from_pyobj.py", "filename": "test_array_from_pyobj.py", "extension": "py", "change_type": "ADD", "diff": "@@ -0,0 +1,309 @@\n+import unittest\n+import sys\n+import copy\n+\n+from scipy.test.testing import *\n+from scipy.base import array, typeinfo, alltrue, ndarray, asarray, can_cast\n+set_package_path()\n+from array_from_pyobj import wrap\n+del sys.path[0]\n+\n+def flags_info(arr):\n+ flags = wrap.array_attrs(arr)[6]\n+ return flags2names(flags)\n+\n+def flags2names(flags):\n+ info = []\n+ for flagname in ['CONTIGUOUS','FORTRAN','OWNDATA','ENSURECOPY',\n+ 'ENSUREARRAY','ALIGNED','NOTSWAPPED','WRITEABLE',\n+ 'UPDATEIFCOPY','BEHAVED_FLAGS','BEHAVED_FLAGS_RO',\n+ 'CARRAY_FLAGS','FARRAY_FLAGS'\n+ ]:\n+ if abs(flags) & getattr(wrap,flagname):\n+ info.append(flagname)\n+ return info\n+\n+class Intent:\n+ def __init__(self,intent_list=[]):\n+ self.intent_list = intent_list[:]\n+ flags = 0\n+ for i in intent_list:\n+ if i=='optional':\n+ flags |= wrap.F2PY_OPTIONAL\n+ else:\n+ flags |= getattr(wrap,'F2PY_INTENT_'+i.upper())\n+ self.flags = flags\n+ def __getattr__(self,name):\n+ name = name.lower()\n+ if name=='in_': name='in'\n+ return self.__class__(self.intent_list+[name])\n+ def __str__(self):\n+ return 'intent(%s)' % (','.join(self.intent_list))\n+ def __repr__(self):\n+ return 'Intent(%r)' % (self.intent_list)\n+ def is_intent(self,*names):\n+ for name in names:\n+ if name not in self.intent_list:\n+ return False\n+ return True\n+ def is_intent_exact(self,*names):\n+ return len(self.intent_list)==len(names) and self.is_intent(*names)\n+\n+intent = Intent()\n+\n+class Type(object):\n+\n+ _type_names = ['BOOL','BYTE','UBYTE','SHORT','USHORT','INT','UINT',\n+ 'LONG','ULONG','LONGLONG','ULONGLONG',\n+ 'FLOAT','DOUBLE','LONGDOUBLE','CFLOAT','CDOUBLE',\n+ 'CLONGDOUBLE']\n+ _type_cache = {}\n+\n+ _cast_dict = {'BOOL':['BOOL']}\n+ _cast_dict['BYTE'] = _cast_dict['BOOL'] + ['BYTE']\n+ _cast_dict['UBYTE'] = _cast_dict['BOOL'] + ['UBYTE']\n+ _cast_dict['BYTE'] = ['BYTE']\n+ _cast_dict['UBYTE'] = ['UBYTE']\n+ _cast_dict['SHORT'] = _cast_dict['BYTE'] + ['UBYTE','SHORT']\n+ _cast_dict['USHORT'] = _cast_dict['UBYTE'] + ['BYTE','USHORT']\n+ _cast_dict['INT'] = _cast_dict['SHORT'] + ['USHORT','INT']\n+ _cast_dict['UINT'] = _cast_dict['USHORT'] + ['SHORT','UINT']\n+\n+ _cast_dict['LONG'] = _cast_dict['INT'] + ['LONG']\n+ _cast_dict['ULONG'] = _cast_dict['UINT'] + ['ULONG']\n+\n+ _cast_dict['LONGLONG'] = _cast_dict['LONG'] + ['ULONG','LONGLONG']\n+ _cast_dict['ULONGLONG'] = _cast_dict['ULONG'] + ['LONG','ULONGLONG']\n+\n+ _cast_dict['FLOAT'] = _cast_dict['SHORT'] + ['USHORT','FLOAT']\n+ _cast_dict['DOUBLE'] = _cast_dict['INT'] + ['UINT','FLOAT','DOUBLE']\n+ _cast_dict['LONGDOUBLE'] = _cast_dict['LONG'] + ['ULONG','FLOAT','DOUBLE','LONGDOUBLE']\n+\n+ _cast_dict['CFLOAT'] = _cast_dict['FLOAT'] + ['CFLOAT']\n+ _cast_dict['CDOUBLE'] = _cast_dict['DOUBLE'] + ['CFLOAT','CDOUBLE']\n+ _cast_dict['CLONGDOUBLE'] = _cast_dict['LONGDOUBLE'] + ['CFLOAT','CDOUBLE','CLONGDOUBLE']\n+ \n+ \n+ def __new__(cls,name):\n+ if isinstance(name,type):\n+ dtype = name\n+ name = None\n+ for n,i in typeinfo.items():\n+ if isinstance(i,tuple) and dtype is i[-1]:\n+ name = n\n+ break\n+ obj = cls._type_cache.get(name.upper(),None)\n+ if obj is not None:\n+ return obj\n+ obj = object.__new__(cls)\n+ obj._init(name)\n+ cls._type_cache[name.upper()] = obj\n+ return obj\n+ \n+ def _init(self,name):\n+ self.NAME = name.upper()\n+ self.type_num = getattr(wrap,'PyArray_'+self.NAME)\n+ assert_equal(self.type_num,typeinfo[self.NAME][1])\n+ self.dtype = typeinfo[self.NAME][-1]\n+ self.elsize = typeinfo[self.NAME][2] / 8\n+ self.dtypechar = typeinfo[self.NAME][0]\n+\n+ def cast_types(self):\n+ return map(Type,self._cast_dict[self.NAME])\n+\n+ def smaller_types(self):\n+ bits = typeinfo[self.NAME][3]\n+ types = []\n+ for name in self._type_names:\n+ if typeinfo[name][3]bits:\n+ types.append(Type(name))\n+ return types\n+\n+class Array:\n+ def __init__(self,typ,dims,intent,obj):\n+ self.type = typ\n+ self.dims = dims\n+ self.intent = intent\n+ self.obj_copy = copy.deepcopy(obj)\n+ self.obj = obj\n+\n+ self.pyarr = array(array(obj,\n+ dtype = typ.dtypechar).reshape(*dims),\n+ fortran=not self.intent.is_intent('c'))\n+ assert self.pyarr.dtypechar==typ.dtypechar,\\\n+ `self.pyarr.dtypechar,typ.dtypechar`\n+ assert self.pyarr.flags['OWNDATA']\n+ self.pyarr_attr = wrap.array_attrs(self.pyarr)\n+\n+ if len(dims)>1:\n+ if self.intent.is_intent('c'):\n+ assert not self.pyarr.flags['FORTRAN']\n+ assert self.pyarr.flags['CONTIGUOUS']\n+ assert not self.pyarr_attr[6] & wrap.FORTRAN\n+ else:\n+ assert self.pyarr.flags['FORTRAN']\n+ assert not self.pyarr.flags['CONTIGUOUS']\n+ assert self.pyarr_attr[6] & wrap.FORTRAN\n+\n+ # arr.dtypechar may be different from typ.dtypechar\n+ self.arr = wrap.call(typ.type_num,dims,intent.flags,obj)\n+\n+ self.arr_attr = wrap.array_attrs(self.arr)\n+\n+ if len(dims)>1:\n+ if self.intent.is_intent('c'):\n+ assert intent.flags & wrap.F2PY_INTENT_C\n+ assert not self.arr.flags['FORTRAN'],`self.arr.flags,obj.flags`\n+ assert self.arr.flags['CONTIGUOUS']\n+ assert not self.arr_attr[6] & wrap.FORTRAN\n+ else:\n+ assert not intent.flags & wrap.F2PY_INTENT_C\n+ assert self.arr.flags['FORTRAN']\n+ assert not self.arr.flags['CONTIGUOUS']\n+ assert self.arr_attr[6] & wrap.FORTRAN\n+\n+ assert self.arr_attr[1]==self.pyarr_attr[1] # nd\n+ assert self.arr_attr[2]==self.pyarr_attr[2] # dimensions\n+ if self.arr_attr[1]<=1:\n+ assert self.arr_attr[3]==self.pyarr_attr[3],\\\n+ `self.arr_attr[3],self.pyarr_attr[3],self.arr.tostring(),self.pyarr.tostring()` # strides\n+ assert self.arr_attr[5][-2:]==self.pyarr_attr[5][-2:],\\\n+ `self.arr_attr[5],self.pyarr_attr[5]` # descr\n+ assert self.arr_attr[6]==self.pyarr_attr[6],\\\n+ `self.arr_attr[6],self.pyarr_attr[6],flags2names(0*self.arr_attr[6]-self.pyarr_attr[6]),flags2names(self.arr_attr[6]),intent` # flags\n+\n+ assert self.arr_attr[5][3]==self.type.elsize,\\\n+ `self.arr_attr[5][3],self.type.elsize`\n+ assert self.arr_equal(self.pyarr,self.arr)\n+ \n+ if isinstance(self.obj,ndarray):\n+ if typ.elsize==Type(obj.dtype).elsize:\n+ if not intent.is_intent('copy') and self.arr_attr[1]<=1:\n+ assert self.has_shared_memory()\n+\n+ def arr_equal(self,arr1,arr2):\n+ if arr1.shape != arr2.shape:\n+ return False\n+ return alltrue(arr1==arr2)\n+\n+ def __str__(self):\n+ return str(self.arr)\n+\n+ def has_shared_memory(self):\n+ \"\"\"Check that created array shares data with input array.\n+ \"\"\"\n+ if self.obj is self.arr:\n+ return True\n+ if not isinstance(self.obj,ndarray):\n+ return False\n+ obj_attr = wrap.array_attrs(self.obj)\n+ return obj_attr[0]==self.arr_attr[0]\n+\n+##################################################\n+\n+class test_intent(unittest.TestCase):\n+ def check_in_out(self):\n+ assert_equal(str(intent.in_.out),'intent(in,out)')\n+ assert intent.in_.c.is_intent('c')\n+ assert not intent.in_.c.is_intent_exact('c')\n+ assert intent.in_.c.is_intent_exact('c','in')\n+ assert intent.in_.c.is_intent_exact('in','c')\n+ assert not intent.in_.is_intent('c')\n+\n+class _test_shared_memory:\n+ num2seq = [1,2]\n+ num23seq = [[1,2,3],[4,5,6]]\n+ def check_in_from_2seq(self):\n+ a = self.array([2],intent.in_,self.num2seq)\n+ assert not a.has_shared_memory()\n+\n+ def check_in_from_2casttype(self):\n+ for t in self.type.cast_types():\n+ obj = array(self.num2seq,dtype=t.dtype)\n+ a = self.array([len(self.num2seq)],intent.in_,obj)\n+ if t.elsize==self.type.elsize:\n+ assert a.has_shared_memory(),`self.type.dtype,t.dtype`\n+ else:\n+ assert not a.has_shared_memory(),`t.dtype`\n+\n+ def check_in_copy_from_2casttype(self):\n+ for t in self.type.cast_types():\n+ obj = array(self.num2seq,dtype=t.dtype)\n+ a = self.array([len(self.num2seq)],intent.in_.copy,obj)\n+ assert not a.has_shared_memory(),`t.dtype`\n+\n+ def check_c_in_from_23seq(self):\n+ a = self.array([len(self.num23seq),len(self.num23seq[0])],\n+ intent.in_,self.num23seq)\n+ assert not a.has_shared_memory()\n+\n+ def check_in_from_23casttype(self):\n+ for t in self.type.cast_types():\n+ obj = array(self.num23seq,dtype=t.dtype)\n+ a = self.array([len(self.num23seq),len(self.num23seq[0])],\n+ intent.in_,obj)\n+ assert not a.has_shared_memory(),`t.dtype`\n+\n+ def check_f_in_from_23casttype(self):\n+ for t in self.type.cast_types():\n+ obj = array(self.num23seq,dtype=t.dtype,fortran=1)\n+ a = self.array([len(self.num23seq),len(self.num23seq[0])],\n+ intent.in_,obj)\n+ if t.elsize==self.type.elsize:\n+ assert a.has_shared_memory(),`t.dtype`\n+ else:\n+ assert not a.has_shared_memory(),`t.dtype`\n+\n+ def check_c_in_from_23casttype(self):\n+ for t in self.type.cast_types():\n+ obj = array(self.num23seq,dtype=t.dtype)\n+ a = self.array([len(self.num23seq),len(self.num23seq[0])],\n+ intent.in_.c,obj)\n+ if t.elsize==self.type.elsize:\n+ assert a.has_shared_memory(),`t.dtype`\n+ else:\n+ assert not a.has_shared_memory(),`t.dtype`\n+\n+ def check_f_copy_in_from_23casttype(self):\n+ for t in self.type.cast_types():\n+ obj = array(self.num23seq,dtype=t.dtype,fortran=1)\n+ a = self.array([len(self.num23seq),len(self.num23seq[0])],\n+ intent.in_.copy,obj)\n+ assert not a.has_shared_memory(),`t.dtype`\n+\n+ def check_c_copy_in_from_23casttype(self):\n+ for t in self.type.cast_types():\n+ obj = array(self.num23seq,dtype=t.dtype)\n+ a = self.array([len(self.num23seq),len(self.num23seq[0])],\n+ intent.in_.c.copy,obj)\n+ assert not a.has_shared_memory(),`t.dtype`\n+\n+\n+for t in Type._type_names:\n+ exec '''\\\n+class test_%s(unittest.TestCase,\n+ _test_shared_memory\n+ ):\n+ type = Type(%r)\n+ array = lambda self,dims,intent,obj: Array(Type(%r),dims,intent,obj)\n+''' % (t,t,t)\n+\n+if __name__ == \"__main__\":\n+ ScipyTest().run()\n", "added_lines": 309, "deleted_lines": 0, "source_code": "import unittest\nimport sys\nimport copy\n\nfrom scipy.test.testing import *\nfrom scipy.base import array, typeinfo, alltrue, ndarray, asarray, can_cast\nset_package_path()\nfrom array_from_pyobj import wrap\ndel sys.path[0]\n\ndef flags_info(arr):\n flags = wrap.array_attrs(arr)[6]\n return flags2names(flags)\n\ndef flags2names(flags):\n info = []\n for flagname in ['CONTIGUOUS','FORTRAN','OWNDATA','ENSURECOPY',\n 'ENSUREARRAY','ALIGNED','NOTSWAPPED','WRITEABLE',\n 'UPDATEIFCOPY','BEHAVED_FLAGS','BEHAVED_FLAGS_RO',\n 'CARRAY_FLAGS','FARRAY_FLAGS'\n ]:\n if abs(flags) & getattr(wrap,flagname):\n info.append(flagname)\n return info\n\nclass Intent:\n def __init__(self,intent_list=[]):\n self.intent_list = intent_list[:]\n flags = 0\n for i in intent_list:\n if i=='optional':\n flags |= wrap.F2PY_OPTIONAL\n else:\n flags |= getattr(wrap,'F2PY_INTENT_'+i.upper())\n self.flags = flags\n def __getattr__(self,name):\n name = name.lower()\n if name=='in_': name='in'\n return self.__class__(self.intent_list+[name])\n def __str__(self):\n return 'intent(%s)' % (','.join(self.intent_list))\n def __repr__(self):\n return 'Intent(%r)' % (self.intent_list)\n def is_intent(self,*names):\n for name in names:\n if name not in self.intent_list:\n return False\n return True\n def is_intent_exact(self,*names):\n return len(self.intent_list)==len(names) and self.is_intent(*names)\n\nintent = Intent()\n\nclass Type(object):\n\n _type_names = ['BOOL','BYTE','UBYTE','SHORT','USHORT','INT','UINT',\n 'LONG','ULONG','LONGLONG','ULONGLONG',\n 'FLOAT','DOUBLE','LONGDOUBLE','CFLOAT','CDOUBLE',\n 'CLONGDOUBLE']\n _type_cache = {}\n\n _cast_dict = {'BOOL':['BOOL']}\n _cast_dict['BYTE'] = _cast_dict['BOOL'] + ['BYTE']\n _cast_dict['UBYTE'] = _cast_dict['BOOL'] + ['UBYTE']\n _cast_dict['BYTE'] = ['BYTE']\n _cast_dict['UBYTE'] = ['UBYTE']\n _cast_dict['SHORT'] = _cast_dict['BYTE'] + ['UBYTE','SHORT']\n _cast_dict['USHORT'] = _cast_dict['UBYTE'] + ['BYTE','USHORT']\n _cast_dict['INT'] = _cast_dict['SHORT'] + ['USHORT','INT']\n _cast_dict['UINT'] = _cast_dict['USHORT'] + ['SHORT','UINT']\n\n _cast_dict['LONG'] = _cast_dict['INT'] + ['LONG']\n _cast_dict['ULONG'] = _cast_dict['UINT'] + ['ULONG']\n\n _cast_dict['LONGLONG'] = _cast_dict['LONG'] + ['ULONG','LONGLONG']\n _cast_dict['ULONGLONG'] = _cast_dict['ULONG'] + ['LONG','ULONGLONG']\n\n _cast_dict['FLOAT'] = _cast_dict['SHORT'] + ['USHORT','FLOAT']\n _cast_dict['DOUBLE'] = _cast_dict['INT'] + ['UINT','FLOAT','DOUBLE']\n _cast_dict['LONGDOUBLE'] = _cast_dict['LONG'] + ['ULONG','FLOAT','DOUBLE','LONGDOUBLE']\n\n _cast_dict['CFLOAT'] = _cast_dict['FLOAT'] + ['CFLOAT']\n _cast_dict['CDOUBLE'] = _cast_dict['DOUBLE'] + ['CFLOAT','CDOUBLE']\n _cast_dict['CLONGDOUBLE'] = _cast_dict['LONGDOUBLE'] + ['CFLOAT','CDOUBLE','CLONGDOUBLE']\n \n \n def __new__(cls,name):\n if isinstance(name,type):\n dtype = name\n name = None\n for n,i in typeinfo.items():\n if isinstance(i,tuple) and dtype is i[-1]:\n name = n\n break\n obj = cls._type_cache.get(name.upper(),None)\n if obj is not None:\n return obj\n obj = object.__new__(cls)\n obj._init(name)\n cls._type_cache[name.upper()] = obj\n return obj\n \n def _init(self,name):\n self.NAME = name.upper()\n self.type_num = getattr(wrap,'PyArray_'+self.NAME)\n assert_equal(self.type_num,typeinfo[self.NAME][1])\n self.dtype = typeinfo[self.NAME][-1]\n self.elsize = typeinfo[self.NAME][2] / 8\n self.dtypechar = typeinfo[self.NAME][0]\n\n def cast_types(self):\n return map(Type,self._cast_dict[self.NAME])\n\n def smaller_types(self):\n bits = typeinfo[self.NAME][3]\n types = []\n for name in self._type_names:\n if typeinfo[name][3]bits:\n types.append(Type(name))\n return types\n\nclass Array:\n def __init__(self,typ,dims,intent,obj):\n self.type = typ\n self.dims = dims\n self.intent = intent\n self.obj_copy = copy.deepcopy(obj)\n self.obj = obj\n\n self.pyarr = array(array(obj,\n dtype = typ.dtypechar).reshape(*dims),\n fortran=not self.intent.is_intent('c'))\n assert self.pyarr.dtypechar==typ.dtypechar,\\\n `self.pyarr.dtypechar,typ.dtypechar`\n assert self.pyarr.flags['OWNDATA']\n self.pyarr_attr = wrap.array_attrs(self.pyarr)\n\n if len(dims)>1:\n if self.intent.is_intent('c'):\n assert not self.pyarr.flags['FORTRAN']\n assert self.pyarr.flags['CONTIGUOUS']\n assert not self.pyarr_attr[6] & wrap.FORTRAN\n else:\n assert self.pyarr.flags['FORTRAN']\n assert not self.pyarr.flags['CONTIGUOUS']\n assert self.pyarr_attr[6] & wrap.FORTRAN\n\n # arr.dtypechar may be different from typ.dtypechar\n self.arr = wrap.call(typ.type_num,dims,intent.flags,obj)\n\n self.arr_attr = wrap.array_attrs(self.arr)\n\n if len(dims)>1:\n if self.intent.is_intent('c'):\n assert intent.flags & wrap.F2PY_INTENT_C\n assert not self.arr.flags['FORTRAN'],`self.arr.flags,obj.flags`\n assert self.arr.flags['CONTIGUOUS']\n assert not self.arr_attr[6] & wrap.FORTRAN\n else:\n assert not intent.flags & wrap.F2PY_INTENT_C\n assert self.arr.flags['FORTRAN']\n assert not self.arr.flags['CONTIGUOUS']\n assert self.arr_attr[6] & wrap.FORTRAN\n\n assert self.arr_attr[1]==self.pyarr_attr[1] # nd\n assert self.arr_attr[2]==self.pyarr_attr[2] # dimensions\n if self.arr_attr[1]<=1:\n assert self.arr_attr[3]==self.pyarr_attr[3],\\\n `self.arr_attr[3],self.pyarr_attr[3],self.arr.tostring(),self.pyarr.tostring()` # strides\n assert self.arr_attr[5][-2:]==self.pyarr_attr[5][-2:],\\\n `self.arr_attr[5],self.pyarr_attr[5]` # descr\n assert self.arr_attr[6]==self.pyarr_attr[6],\\\n `self.arr_attr[6],self.pyarr_attr[6],flags2names(0*self.arr_attr[6]-self.pyarr_attr[6]),flags2names(self.arr_attr[6]),intent` # flags\n\n assert self.arr_attr[5][3]==self.type.elsize,\\\n `self.arr_attr[5][3],self.type.elsize`\n assert self.arr_equal(self.pyarr,self.arr)\n \n if isinstance(self.obj,ndarray):\n if typ.elsize==Type(obj.dtype).elsize:\n if not intent.is_intent('copy') and self.arr_attr[1]<=1:\n assert self.has_shared_memory()\n\n def arr_equal(self,arr1,arr2):\n if arr1.shape != arr2.shape:\n return False\n return alltrue(arr1==arr2)\n\n def __str__(self):\n return str(self.arr)\n\n def has_shared_memory(self):\n \"\"\"Check that created array shares data with input array.\n \"\"\"\n if self.obj is self.arr:\n return True\n if not isinstance(self.obj,ndarray):\n return False\n obj_attr = wrap.array_attrs(self.obj)\n return obj_attr[0]==self.arr_attr[0]\n\n##################################################\n\nclass test_intent(unittest.TestCase):\n def check_in_out(self):\n assert_equal(str(intent.in_.out),'intent(in,out)')\n assert intent.in_.c.is_intent('c')\n assert not intent.in_.c.is_intent_exact('c')\n assert intent.in_.c.is_intent_exact('c','in')\n assert intent.in_.c.is_intent_exact('in','c')\n assert not intent.in_.is_intent('c')\n\nclass _test_shared_memory:\n num2seq = [1,2]\n num23seq = [[1,2,3],[4,5,6]]\n def check_in_from_2seq(self):\n a = self.array([2],intent.in_,self.num2seq)\n assert not a.has_shared_memory()\n\n def check_in_from_2casttype(self):\n for t in self.type.cast_types():\n obj = array(self.num2seq,dtype=t.dtype)\n a = self.array([len(self.num2seq)],intent.in_,obj)\n if t.elsize==self.type.elsize:\n assert a.has_shared_memory(),`self.type.dtype,t.dtype`\n else:\n assert not a.has_shared_memory(),`t.dtype`\n\n def check_in_copy_from_2casttype(self):\n for t in self.type.cast_types():\n obj = array(self.num2seq,dtype=t.dtype)\n a = self.array([len(self.num2seq)],intent.in_.copy,obj)\n assert not a.has_shared_memory(),`t.dtype`\n\n def check_c_in_from_23seq(self):\n a = self.array([len(self.num23seq),len(self.num23seq[0])],\n intent.in_,self.num23seq)\n assert not a.has_shared_memory()\n\n def check_in_from_23casttype(self):\n for t in self.type.cast_types():\n obj = array(self.num23seq,dtype=t.dtype)\n a = self.array([len(self.num23seq),len(self.num23seq[0])],\n intent.in_,obj)\n assert not a.has_shared_memory(),`t.dtype`\n\n def check_f_in_from_23casttype(self):\n for t in self.type.cast_types():\n obj = array(self.num23seq,dtype=t.dtype,fortran=1)\n a = self.array([len(self.num23seq),len(self.num23seq[0])],\n intent.in_,obj)\n if t.elsize==self.type.elsize:\n assert a.has_shared_memory(),`t.dtype`\n else:\n assert not a.has_shared_memory(),`t.dtype`\n\n def check_c_in_from_23casttype(self):\n for t in self.type.cast_types():\n obj = array(self.num23seq,dtype=t.dtype)\n a = self.array([len(self.num23seq),len(self.num23seq[0])],\n intent.in_.c,obj)\n if t.elsize==self.type.elsize:\n assert a.has_shared_memory(),`t.dtype`\n else:\n assert not a.has_shared_memory(),`t.dtype`\n\n def check_f_copy_in_from_23casttype(self):\n for t in self.type.cast_types():\n obj = array(self.num23seq,dtype=t.dtype,fortran=1)\n a = self.array([len(self.num23seq),len(self.num23seq[0])],\n intent.in_.copy,obj)\n assert not a.has_shared_memory(),`t.dtype`\n\n def check_c_copy_in_from_23casttype(self):\n for t in self.type.cast_types():\n obj = array(self.num23seq,dtype=t.dtype)\n a = self.array([len(self.num23seq),len(self.num23seq[0])],\n intent.in_.c.copy,obj)\n assert not a.has_shared_memory(),`t.dtype`\n\n\nfor t in Type._type_names:\n exec '''\\\nclass test_%s(unittest.TestCase,\n _test_shared_memory\n ):\n type = Type(%r)\n array = lambda self,dims,intent,obj: Array(Type(%r),dims,intent,obj)\n''' % (t,t,t)\n\nif __name__ == \"__main__\":\n ScipyTest().run()\n", "source_code_before": null, "methods": [ { "name": "flags_info", "long_name": "flags_info( arr )", "filename": "test_array_from_pyobj.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "arr" ], "start_line": 11, "end_line": 13, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "flags2names", "long_name": "flags2names( flags )", "filename": "test_array_from_pyobj.py", "nloc": 10, "complexity": 3, "token_count": 61, "parameters": [ "flags" ], "start_line": 15, "end_line": 24, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , intent_list = [ ] )", "filename": "test_array_from_pyobj.py", "nloc": 9, "complexity": 3, "token_count": 57, "parameters": [ "self", "intent_list" ], "start_line": 27, "end_line": 35, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "test_array_from_pyobj.py", "nloc": 4, "complexity": 2, "token_count": 35, "parameters": [ "self", "name" ], "start_line": 36, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "test_array_from_pyobj.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 40, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "test_array_from_pyobj.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 42, "end_line": 43, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "is_intent", "long_name": "is_intent( self , * names )", "filename": "test_array_from_pyobj.py", "nloc": 5, "complexity": 3, "token_count": 25, "parameters": [ "self", "names" ], "start_line": 44, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "is_intent_exact", "long_name": "is_intent_exact( self , * names )", "filename": "test_array_from_pyobj.py", "nloc": 2, "complexity": 2, "token_count": 28, "parameters": [ "self", "names" ], "start_line": 49, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__new__", "long_name": "__new__( cls , name )", "filename": "test_array_from_pyobj.py", "nloc": 15, "complexity": 6, "token_count": 104, "parameters": [ "cls", "name" ], "start_line": 87, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "_init", "long_name": "_init( self , name )", "filename": "test_array_from_pyobj.py", "nloc": 7, "complexity": 1, "token_count": 88, "parameters": [ "self", "name" ], "start_line": 103, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "cast_types", "long_name": "cast_types( self )", "filename": "test_array_from_pyobj.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 111, "end_line": 112, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "smaller_types", "long_name": "smaller_types( self )", "filename": "test_array_from_pyobj.py", "nloc": 7, "complexity": 3, "token_count": 49, "parameters": [ "self" ], "start_line": 114, "end_line": 120, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "equal_types", "long_name": "equal_types( self )", "filename": "test_array_from_pyobj.py", "nloc": 8, "complexity": 4, "token_count": 57, "parameters": [ "self" ], "start_line": 122, "end_line": 129, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "larger_types", "long_name": "larger_types( self )", "filename": "test_array_from_pyobj.py", "nloc": 7, "complexity": 3, "token_count": 49, "parameters": [ "self" ], "start_line": 131, "end_line": 137, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , typ , dims , intent , obj )", "filename": "test_array_from_pyobj.py", "nloc": 51, "complexity": 10, "token_count": 629, "parameters": [ "self", "typ", "dims", "intent", "obj" ], "start_line": 140, "end_line": 199, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 60, "top_nesting_level": 1 }, { "name": "arr_equal", "long_name": "arr_equal( self , arr1 , arr2 )", "filename": "test_array_from_pyobj.py", "nloc": 4, "complexity": 2, "token_count": 27, "parameters": [ "self", "arr1", "arr2" ], "start_line": 201, "end_line": 204, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "test_array_from_pyobj.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 206, "end_line": 207, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "has_shared_memory", "long_name": "has_shared_memory( self )", "filename": "test_array_from_pyobj.py", "nloc": 7, "complexity": 3, "token_count": 52, "parameters": [ "self" ], "start_line": 209, "end_line": 217, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_in_out", "long_name": "check_in_out( self )", "filename": "test_array_from_pyobj.py", "nloc": 7, "complexity": 1, "token_count": 77, "parameters": [ "self" ], "start_line": 222, "end_line": 228, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_in_from_2seq", "long_name": "check_in_from_2seq( self )", "filename": "test_array_from_pyobj.py", "nloc": 3, "complexity": 1, "token_count": 30, "parameters": [ "self" ], "start_line": 233, "end_line": 235, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_in_from_2casttype", "long_name": "check_in_from_2casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 8, "complexity": 3, "token_count": 95, "parameters": [ "self" ], "start_line": 237, "end_line": 244, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_in_copy_from_2casttype", "long_name": "check_in_copy_from_2casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 5, "complexity": 2, "token_count": 66, "parameters": [ "self" ], "start_line": 246, "end_line": 250, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_c_in_from_23seq", "long_name": "check_c_in_from_23seq( self )", "filename": "test_array_from_pyobj.py", "nloc": 4, "complexity": 1, "token_count": 45, "parameters": [ "self" ], "start_line": 252, "end_line": 255, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_in_from_23casttype", "long_name": "check_in_from_23casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 6, "complexity": 2, "token_count": 74, "parameters": [ "self" ], "start_line": 257, "end_line": 262, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_f_in_from_23casttype", "long_name": "check_f_in_from_23casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 9, "complexity": 3, "token_count": 103, "parameters": [ "self" ], "start_line": 264, "end_line": 272, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_c_in_from_23casttype", "long_name": "check_c_in_from_23casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 9, "complexity": 3, "token_count": 101, "parameters": [ "self" ], "start_line": 274, "end_line": 282, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_f_copy_in_from_23casttype", "long_name": "check_f_copy_in_from_23casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 6, "complexity": 2, "token_count": 80, "parameters": [ "self" ], "start_line": 284, "end_line": 289, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_c_copy_in_from_23casttype", "long_name": "check_c_copy_in_from_23casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 6, "complexity": 2, "token_count": 78, "parameters": [ "self" ], "start_line": 291, "end_line": 296, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 } ], "methods_before": [], "changed_methods": [ { "name": "cast_types", "long_name": "cast_types( self )", "filename": "test_array_from_pyobj.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 111, "end_line": 112, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_in_copy_from_2casttype", "long_name": "check_in_copy_from_2casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 5, "complexity": 2, "token_count": 66, "parameters": [ "self" ], "start_line": 246, "end_line": 250, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_c_in_from_23casttype", "long_name": "check_c_in_from_23casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 9, "complexity": 3, "token_count": 101, "parameters": [ "self" ], "start_line": 274, "end_line": 282, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "_init", "long_name": "_init( self , name )", "filename": "test_array_from_pyobj.py", "nloc": 7, "complexity": 1, "token_count": 88, "parameters": [ "self", "name" ], "start_line": 103, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_in_from_2seq", "long_name": "check_in_from_2seq( self )", "filename": "test_array_from_pyobj.py", "nloc": 3, "complexity": 1, "token_count": 30, "parameters": [ "self" ], "start_line": 233, "end_line": 235, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "flags2names", "long_name": "flags2names( flags )", "filename": "test_array_from_pyobj.py", "nloc": 10, "complexity": 3, "token_count": 61, "parameters": [ "flags" ], "start_line": 15, "end_line": 24, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "test_array_from_pyobj.py", "nloc": 4, "complexity": 2, "token_count": 35, "parameters": [ "self", "name" ], "start_line": 36, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "test_array_from_pyobj.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 42, "end_line": 43, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , typ , dims , intent , obj )", "filename": "test_array_from_pyobj.py", "nloc": 51, "complexity": 10, "token_count": 629, "parameters": [ "self", "typ", "dims", "intent", "obj" ], "start_line": 140, "end_line": 199, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 60, "top_nesting_level": 1 }, { "name": "check_f_in_from_23casttype", "long_name": "check_f_in_from_23casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 9, "complexity": 3, "token_count": 103, "parameters": [ "self" ], "start_line": 264, "end_line": 272, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , intent_list = [ ] )", "filename": "test_array_from_pyobj.py", "nloc": 9, "complexity": 3, "token_count": 57, "parameters": [ "self", "intent_list" ], "start_line": 27, "end_line": 35, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "test_array_from_pyobj.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 40, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_f_copy_in_from_23casttype", "long_name": "check_f_copy_in_from_23casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 6, "complexity": 2, "token_count": 80, "parameters": [ "self" ], "start_line": 284, "end_line": 289, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_in_from_23casttype", "long_name": "check_in_from_23casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 6, "complexity": 2, "token_count": 74, "parameters": [ "self" ], "start_line": 257, "end_line": 262, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_c_copy_in_from_23casttype", "long_name": "check_c_copy_in_from_23casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 6, "complexity": 2, "token_count": 78, "parameters": [ "self" ], "start_line": 291, "end_line": 296, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "has_shared_memory", "long_name": "has_shared_memory( self )", "filename": "test_array_from_pyobj.py", "nloc": 7, "complexity": 3, "token_count": 52, "parameters": [ "self" ], "start_line": 209, "end_line": 217, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_c_in_from_23seq", "long_name": "check_c_in_from_23seq( self )", "filename": "test_array_from_pyobj.py", "nloc": 4, "complexity": 1, "token_count": 45, "parameters": [ "self" ], "start_line": 252, "end_line": 255, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "is_intent_exact", "long_name": "is_intent_exact( self , * names )", "filename": "test_array_from_pyobj.py", "nloc": 2, "complexity": 2, "token_count": 28, "parameters": [ "self", "names" ], "start_line": 49, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_in_from_2casttype", "long_name": "check_in_from_2casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 8, "complexity": 3, "token_count": 95, "parameters": [ "self" ], "start_line": 237, "end_line": 244, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "is_intent", "long_name": "is_intent( self , * names )", "filename": "test_array_from_pyobj.py", "nloc": 5, "complexity": 3, "token_count": 25, "parameters": [ "self", "names" ], "start_line": 44, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "__new__", "long_name": "__new__( cls , name )", "filename": "test_array_from_pyobj.py", "nloc": 15, "complexity": 6, "token_count": 104, "parameters": [ "cls", "name" ], "start_line": 87, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "check_in_out", "long_name": "check_in_out( self )", "filename": "test_array_from_pyobj.py", "nloc": 7, "complexity": 1, "token_count": 77, "parameters": [ "self" ], "start_line": 222, "end_line": 228, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "arr_equal", "long_name": "arr_equal( self , arr1 , arr2 )", "filename": "test_array_from_pyobj.py", "nloc": 4, "complexity": 2, "token_count": 27, "parameters": [ "self", "arr1", "arr2" ], "start_line": 201, "end_line": 204, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "smaller_types", "long_name": "smaller_types( self )", "filename": "test_array_from_pyobj.py", "nloc": 7, "complexity": 3, "token_count": 49, "parameters": [ "self" ], "start_line": 114, "end_line": 120, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "larger_types", "long_name": "larger_types( self )", "filename": "test_array_from_pyobj.py", "nloc": 7, "complexity": 3, "token_count": 49, "parameters": [ "self" ], "start_line": 131, "end_line": 137, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "flags_info", "long_name": "flags_info( arr )", "filename": "test_array_from_pyobj.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "arr" ], "start_line": 11, "end_line": 13, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "equal_types", "long_name": "equal_types( self )", "filename": "test_array_from_pyobj.py", "nloc": 8, "complexity": 4, "token_count": 57, "parameters": [ "self" ], "start_line": 122, "end_line": 129, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 } ], "nloc": 260, "complexity": 70, "token_count": 2552, "diff_parsed": { "added": [ "import unittest", "import sys", "import copy", "", "from scipy.test.testing import *", "from scipy.base import array, typeinfo, alltrue, ndarray, asarray, can_cast", "set_package_path()", "from array_from_pyobj import wrap", "del sys.path[0]", "", "def flags_info(arr):", " flags = wrap.array_attrs(arr)[6]", " return flags2names(flags)", "", "def flags2names(flags):", " info = []", " for flagname in ['CONTIGUOUS','FORTRAN','OWNDATA','ENSURECOPY',", " 'ENSUREARRAY','ALIGNED','NOTSWAPPED','WRITEABLE',", " 'UPDATEIFCOPY','BEHAVED_FLAGS','BEHAVED_FLAGS_RO',", " 'CARRAY_FLAGS','FARRAY_FLAGS'", " ]:", " if abs(flags) & getattr(wrap,flagname):", " info.append(flagname)", " return info", "", "class Intent:", " def __init__(self,intent_list=[]):", " self.intent_list = intent_list[:]", " flags = 0", " for i in intent_list:", " if i=='optional':", " flags |= wrap.F2PY_OPTIONAL", " else:", " flags |= getattr(wrap,'F2PY_INTENT_'+i.upper())", " self.flags = flags", " def __getattr__(self,name):", " name = name.lower()", " if name=='in_': name='in'", " return self.__class__(self.intent_list+[name])", " def __str__(self):", " return 'intent(%s)' % (','.join(self.intent_list))", " def __repr__(self):", " return 'Intent(%r)' % (self.intent_list)", " def is_intent(self,*names):", " for name in names:", " if name not in self.intent_list:", " return False", " return True", " def is_intent_exact(self,*names):", " return len(self.intent_list)==len(names) and self.is_intent(*names)", "", "intent = Intent()", "", "class Type(object):", "", " _type_names = ['BOOL','BYTE','UBYTE','SHORT','USHORT','INT','UINT',", " 'LONG','ULONG','LONGLONG','ULONGLONG',", " 'FLOAT','DOUBLE','LONGDOUBLE','CFLOAT','CDOUBLE',", " 'CLONGDOUBLE']", " _type_cache = {}", "", " _cast_dict = {'BOOL':['BOOL']}", " _cast_dict['BYTE'] = _cast_dict['BOOL'] + ['BYTE']", " _cast_dict['UBYTE'] = _cast_dict['BOOL'] + ['UBYTE']", " _cast_dict['BYTE'] = ['BYTE']", " _cast_dict['UBYTE'] = ['UBYTE']", " _cast_dict['SHORT'] = _cast_dict['BYTE'] + ['UBYTE','SHORT']", " _cast_dict['USHORT'] = _cast_dict['UBYTE'] + ['BYTE','USHORT']", " _cast_dict['INT'] = _cast_dict['SHORT'] + ['USHORT','INT']", " _cast_dict['UINT'] = _cast_dict['USHORT'] + ['SHORT','UINT']", "", " _cast_dict['LONG'] = _cast_dict['INT'] + ['LONG']", " _cast_dict['ULONG'] = _cast_dict['UINT'] + ['ULONG']", "", " _cast_dict['LONGLONG'] = _cast_dict['LONG'] + ['ULONG','LONGLONG']", " _cast_dict['ULONGLONG'] = _cast_dict['ULONG'] + ['LONG','ULONGLONG']", "", " _cast_dict['FLOAT'] = _cast_dict['SHORT'] + ['USHORT','FLOAT']", " _cast_dict['DOUBLE'] = _cast_dict['INT'] + ['UINT','FLOAT','DOUBLE']", " _cast_dict['LONGDOUBLE'] = _cast_dict['LONG'] + ['ULONG','FLOAT','DOUBLE','LONGDOUBLE']", "", " _cast_dict['CFLOAT'] = _cast_dict['FLOAT'] + ['CFLOAT']", " _cast_dict['CDOUBLE'] = _cast_dict['DOUBLE'] + ['CFLOAT','CDOUBLE']", " _cast_dict['CLONGDOUBLE'] = _cast_dict['LONGDOUBLE'] + ['CFLOAT','CDOUBLE','CLONGDOUBLE']", "", "", " def __new__(cls,name):", " if isinstance(name,type):", " dtype = name", " name = None", " for n,i in typeinfo.items():", " if isinstance(i,tuple) and dtype is i[-1]:", " name = n", " break", " obj = cls._type_cache.get(name.upper(),None)", " if obj is not None:", " return obj", " obj = object.__new__(cls)", " obj._init(name)", " cls._type_cache[name.upper()] = obj", " return obj", "", " def _init(self,name):", " self.NAME = name.upper()", " self.type_num = getattr(wrap,'PyArray_'+self.NAME)", " assert_equal(self.type_num,typeinfo[self.NAME][1])", " self.dtype = typeinfo[self.NAME][-1]", " self.elsize = typeinfo[self.NAME][2] / 8", " self.dtypechar = typeinfo[self.NAME][0]", "", " def cast_types(self):", " return map(Type,self._cast_dict[self.NAME])", "", " def smaller_types(self):", " bits = typeinfo[self.NAME][3]", " types = []", " for name in self._type_names:", " if typeinfo[name][3]bits:", " types.append(Type(name))", " return types", "", "class Array:", " def __init__(self,typ,dims,intent,obj):", " self.type = typ", " self.dims = dims", " self.intent = intent", " self.obj_copy = copy.deepcopy(obj)", " self.obj = obj", "", " self.pyarr = array(array(obj,", " dtype = typ.dtypechar).reshape(*dims),", " fortran=not self.intent.is_intent('c'))", " assert self.pyarr.dtypechar==typ.dtypechar,\\", " `self.pyarr.dtypechar,typ.dtypechar`", " assert self.pyarr.flags['OWNDATA']", " self.pyarr_attr = wrap.array_attrs(self.pyarr)", "", " if len(dims)>1:", " if self.intent.is_intent('c'):", " assert not self.pyarr.flags['FORTRAN']", " assert self.pyarr.flags['CONTIGUOUS']", " assert not self.pyarr_attr[6] & wrap.FORTRAN", " else:", " assert self.pyarr.flags['FORTRAN']", " assert not self.pyarr.flags['CONTIGUOUS']", " assert self.pyarr_attr[6] & wrap.FORTRAN", "", " # arr.dtypechar may be different from typ.dtypechar", " self.arr = wrap.call(typ.type_num,dims,intent.flags,obj)", "", " self.arr_attr = wrap.array_attrs(self.arr)", "", " if len(dims)>1:", " if self.intent.is_intent('c'):", " assert intent.flags & wrap.F2PY_INTENT_C", " assert not self.arr.flags['FORTRAN'],`self.arr.flags,obj.flags`", " assert self.arr.flags['CONTIGUOUS']", " assert not self.arr_attr[6] & wrap.FORTRAN", " else:", " assert not intent.flags & wrap.F2PY_INTENT_C", " assert self.arr.flags['FORTRAN']", " assert not self.arr.flags['CONTIGUOUS']", " assert self.arr_attr[6] & wrap.FORTRAN", "", " assert self.arr_attr[1]==self.pyarr_attr[1] # nd", " assert self.arr_attr[2]==self.pyarr_attr[2] # dimensions", " if self.arr_attr[1]<=1:", " assert self.arr_attr[3]==self.pyarr_attr[3],\\", " `self.arr_attr[3],self.pyarr_attr[3],self.arr.tostring(),self.pyarr.tostring()` # strides", " assert self.arr_attr[5][-2:]==self.pyarr_attr[5][-2:],\\", " `self.arr_attr[5],self.pyarr_attr[5]` # descr", " assert self.arr_attr[6]==self.pyarr_attr[6],\\", " `self.arr_attr[6],self.pyarr_attr[6],flags2names(0*self.arr_attr[6]-self.pyarr_attr[6]),flags2names(self.arr_attr[6]),intent` # flags", "", " assert self.arr_attr[5][3]==self.type.elsize,\\", " `self.arr_attr[5][3],self.type.elsize`", " assert self.arr_equal(self.pyarr,self.arr)", "", " if isinstance(self.obj,ndarray):", " if typ.elsize==Type(obj.dtype).elsize:", " if not intent.is_intent('copy') and self.arr_attr[1]<=1:", " assert self.has_shared_memory()", "", " def arr_equal(self,arr1,arr2):", " if arr1.shape != arr2.shape:", " return False", " return alltrue(arr1==arr2)", "", " def __str__(self):", " return str(self.arr)", "", " def has_shared_memory(self):", " \"\"\"Check that created array shares data with input array.", " \"\"\"", " if self.obj is self.arr:", " return True", " if not isinstance(self.obj,ndarray):", " return False", " obj_attr = wrap.array_attrs(self.obj)", " return obj_attr[0]==self.arr_attr[0]", "", "##################################################", "", "class test_intent(unittest.TestCase):", " def check_in_out(self):", " assert_equal(str(intent.in_.out),'intent(in,out)')", " assert intent.in_.c.is_intent('c')", " assert not intent.in_.c.is_intent_exact('c')", " assert intent.in_.c.is_intent_exact('c','in')", " assert intent.in_.c.is_intent_exact('in','c')", " assert not intent.in_.is_intent('c')", "", "class _test_shared_memory:", " num2seq = [1,2]", " num23seq = [[1,2,3],[4,5,6]]", " def check_in_from_2seq(self):", " a = self.array([2],intent.in_,self.num2seq)", " assert not a.has_shared_memory()", "", " def check_in_from_2casttype(self):", " for t in self.type.cast_types():", " obj = array(self.num2seq,dtype=t.dtype)", " a = self.array([len(self.num2seq)],intent.in_,obj)", " if t.elsize==self.type.elsize:", " assert a.has_shared_memory(),`self.type.dtype,t.dtype`", " else:", " assert not a.has_shared_memory(),`t.dtype`", "", " def check_in_copy_from_2casttype(self):", " for t in self.type.cast_types():", " obj = array(self.num2seq,dtype=t.dtype)", " a = self.array([len(self.num2seq)],intent.in_.copy,obj)", " assert not a.has_shared_memory(),`t.dtype`", "", " def check_c_in_from_23seq(self):", " a = self.array([len(self.num23seq),len(self.num23seq[0])],", " intent.in_,self.num23seq)", " assert not a.has_shared_memory()", "", " def check_in_from_23casttype(self):", " for t in self.type.cast_types():", " obj = array(self.num23seq,dtype=t.dtype)", " a = self.array([len(self.num23seq),len(self.num23seq[0])],", " intent.in_,obj)", " assert not a.has_shared_memory(),`t.dtype`", "", " def check_f_in_from_23casttype(self):", " for t in self.type.cast_types():", " obj = array(self.num23seq,dtype=t.dtype,fortran=1)", " a = self.array([len(self.num23seq),len(self.num23seq[0])],", " intent.in_,obj)", " if t.elsize==self.type.elsize:", " assert a.has_shared_memory(),`t.dtype`", " else:", " assert not a.has_shared_memory(),`t.dtype`", "", " def check_c_in_from_23casttype(self):", " for t in self.type.cast_types():", " obj = array(self.num23seq,dtype=t.dtype)", " a = self.array([len(self.num23seq),len(self.num23seq[0])],", " intent.in_.c,obj)", " if t.elsize==self.type.elsize:", " assert a.has_shared_memory(),`t.dtype`", " else:", " assert not a.has_shared_memory(),`t.dtype`", "", " def check_f_copy_in_from_23casttype(self):", " for t in self.type.cast_types():", " obj = array(self.num23seq,dtype=t.dtype,fortran=1)", " a = self.array([len(self.num23seq),len(self.num23seq[0])],", " intent.in_.copy,obj)", " assert not a.has_shared_memory(),`t.dtype`", "", " def check_c_copy_in_from_23casttype(self):", " for t in self.type.cast_types():", " obj = array(self.num23seq,dtype=t.dtype)", " a = self.array([len(self.num23seq),len(self.num23seq[0])],", " intent.in_.c.copy,obj)", " assert not a.has_shared_memory(),`t.dtype`", "", "", "for t in Type._type_names:", " exec '''\\", "class test_%s(unittest.TestCase,", " _test_shared_memory", " ):", " type = Type(%r)", " array = lambda self,dims,intent,obj: Array(Type(%r),dims,intent,obj)", "''' % (t,t,t)", "", "if __name__ == \"__main__\":", " ScipyTest().run()" ], "deleted": [] } }, { "old_path": null, "new_path": "scipy/f2py2e/tests/array_from_pyobj/wrapmodule.c", "filename": "wrapmodule.c", "extension": "c", "change_type": "ADD", "diff": "@@ -0,0 +1,190 @@\n+/* File: wrapmodule.c\n+ * This file is auto-generated with f2py (version:2_1330).\n+ * Hand edited by Pearu.\n+ * f2py is a Fortran to Python Interface Generator (FPIG), Second Edition,\n+ * written by Pearu Peterson .\n+ * See http://cens.ioc.ee/projects/f2py2e/\n+ * Generation date: Fri Oct 21 22:41:12 2005\n+ * $Revision:$\n+ * $Date:$\n+ * Do not edit this file directly unless you know what you are doing!!!\n+ */\n+#ifdef __cplusplus\n+extern \"C\" {\n+#endif\n+\n+/*********************** See f2py2e/cfuncs.py: includes ***********************/\n+#include \"Python.h\"\n+#include \"fortranobject.h\"\n+#include \n+\n+static PyObject *wrap_error;\n+static PyObject *wrap_module;\n+\n+/************************************ call ************************************/\n+static char doc_f2py_rout_wrap_call[] = \"\\\n+Function signature:\\n\\\n+ arr = call(type_num,dims,intent,obj)\\n\\\n+Required arguments:\\n\"\n+\" type_num : input int\\n\"\n+\" dims : input int-sequence\\n\"\n+\" intent : input int\\n\"\n+\" obj : input python object\\n\"\n+\"Return objects:\\n\"\n+\" arr : array\";\n+static PyObject *f2py_rout_wrap_call(PyObject *capi_self,\n+\t\t\t\t PyObject *capi_args) {\n+ PyObject * volatile capi_buildvalue = NULL;\n+ int type_num = 0;\n+ intp *dims = NULL;\n+ PyObject *dims_capi = Py_None;\n+ int rank = 0;\n+ int intent = 0;\n+ PyArrayObject *capi_arr_tmp = NULL;\n+ PyObject *arr_capi = Py_None;\n+ int i;\n+\n+ if (!PyArg_ParseTuple(capi_args,\"iOiO|:wrap.call\",\\\n+\t\t\t&type_num,&dims_capi,&intent,&arr_capi))\n+ return NULL;\n+ rank = PySequence_Length(dims_capi);\n+ dims = malloc(rank*sizeof(intp));\n+ for (i=0;idata);\n+ dimensions = PyTuple_New(arr->nd);\n+ strides = PyTuple_New(arr->nd);\n+ for (i=0;ind;++i) {\n+ PyTuple_SetItem(dimensions,i,PyInt_FromLong(arr->dimensions[i]));\n+ PyTuple_SetItem(strides,i,PyInt_FromLong(arr->strides[i]));\n+ }\n+ return Py_BuildValue(\"siOOO(cciii)ii\",s,arr->nd,\n+\t\t dimensions,strides,\n+\t\t (arr->base==NULL?Py_None:arr->base),\n+\t\t arr->descr->kind,\n+\t\t arr->descr->type,\n+\t\t arr->descr->type_num,\n+\t\t arr->descr->elsize,\n+\t\t arr->descr->alignment,\n+\t\t arr->flags,\n+\t\t arr->itemsize);\n+}\n+\n+static PyMethodDef f2py_module_methods[] = {\n+\n+ {\"call\",f2py_rout_wrap_call,METH_VARARGS,doc_f2py_rout_wrap_call},\n+ {\"array_attrs\",f2py_rout_wrap_attrs,METH_VARARGS,doc_f2py_rout_wrap_attrs},\n+ {NULL,NULL}\n+};\n+\n+DL_EXPORT(void) initwrap(void) {\n+ PyObject *m,*d, *s;\n+ m = wrap_module = Py_InitModule(\"wrap\", f2py_module_methods);\n+ PyFortran_Type.ob_type = &PyType_Type;\n+ import_array();\n+ if (PyErr_Occurred())\n+ Py_FatalError(\"can't initialize module wrap (failed to import scipy.base)\");\n+ d = PyModule_GetDict(m);\n+ s = PyString_FromString(\"This module 'wrap' is auto-generated with f2py (version:2_1330).\\nFunctions:\\n\"\n+\" arr = call(type_num,dims,intent,obj)\\n\"\n+\".\");\n+ PyDict_SetItemString(d, \"__doc__\", s);\n+ wrap_error = PyErr_NewException (\"wrap.error\", NULL, NULL);\n+ Py_DECREF(s);\n+ PyDict_SetItemString(d, \"F2PY_INTENT_IN\", PyInt_FromLong(F2PY_INTENT_IN));\n+ PyDict_SetItemString(d, \"F2PY_INTENT_INOUT\", PyInt_FromLong(F2PY_INTENT_INOUT));\n+ PyDict_SetItemString(d, \"F2PY_INTENT_OUT\", PyInt_FromLong(F2PY_INTENT_OUT));\n+ PyDict_SetItemString(d, \"F2PY_INTENT_HIDE\", PyInt_FromLong(F2PY_INTENT_HIDE));\n+ PyDict_SetItemString(d, \"F2PY_INTENT_CACHE\", PyInt_FromLong(F2PY_INTENT_CACHE));\n+ PyDict_SetItemString(d, \"F2PY_INTENT_COPY\", PyInt_FromLong(F2PY_INTENT_COPY));\n+ PyDict_SetItemString(d, \"F2PY_INTENT_C\", PyInt_FromLong(F2PY_INTENT_C));\n+ PyDict_SetItemString(d, \"F2PY_OPTIONAL\", PyInt_FromLong(F2PY_OPTIONAL));\n+ PyDict_SetItemString(d, \"F2PY_INTENT_INPLACE\", PyInt_FromLong(F2PY_INTENT_INPLACE));\n+ PyDict_SetItemString(d, \"PyArray_BOOL\", PyInt_FromLong(PyArray_BOOL));\n+ PyDict_SetItemString(d, \"PyArray_BYTE\", PyInt_FromLong(PyArray_BYTE));\n+ PyDict_SetItemString(d, \"PyArray_UBYTE\", PyInt_FromLong(PyArray_UBYTE));\n+ PyDict_SetItemString(d, \"PyArray_SHORT\", PyInt_FromLong(PyArray_SHORT));\n+ PyDict_SetItemString(d, \"PyArray_USHORT\", PyInt_FromLong(PyArray_USHORT));\n+ PyDict_SetItemString(d, \"PyArray_INT\", PyInt_FromLong(PyArray_INT));\n+ PyDict_SetItemString(d, \"PyArray_UINT\", PyInt_FromLong(PyArray_UINT));\n+ PyDict_SetItemString(d, \"PyArray_INTP\", PyInt_FromLong(PyArray_INTP));\n+ PyDict_SetItemString(d, \"PyArray_UINTP\", PyInt_FromLong(PyArray_UINTP));\n+ PyDict_SetItemString(d, \"PyArray_LONG\", PyInt_FromLong(PyArray_LONG));\n+ PyDict_SetItemString(d, \"PyArray_ULONG\", PyInt_FromLong(PyArray_ULONG));\n+ PyDict_SetItemString(d, \"PyArray_LONGLONG\", PyInt_FromLong(PyArray_LONGLONG));\n+ PyDict_SetItemString(d, \"PyArray_ULONGLONG\", PyInt_FromLong(PyArray_ULONGLONG));\n+ PyDict_SetItemString(d, \"PyArray_FLOAT\", PyInt_FromLong(PyArray_FLOAT));\n+ PyDict_SetItemString(d, \"PyArray_DOUBLE\", PyInt_FromLong(PyArray_DOUBLE));\n+ PyDict_SetItemString(d, \"PyArray_LONGDOUBLE\", PyInt_FromLong(PyArray_LONGDOUBLE));\n+ PyDict_SetItemString(d, \"PyArray_CFLOAT\", PyInt_FromLong(PyArray_CFLOAT));\n+ PyDict_SetItemString(d, \"PyArray_CDOUBLE\", PyInt_FromLong(PyArray_CDOUBLE));\n+ PyDict_SetItemString(d, \"PyArray_CLONGDOUBLE\", PyInt_FromLong(PyArray_CLONGDOUBLE));\n+ PyDict_SetItemString(d, \"PyArray_OBJECT\", PyInt_FromLong(PyArray_OBJECT));\n+ PyDict_SetItemString(d, \"PyArray_STRING\", PyInt_FromLong(PyArray_STRING));\n+ PyDict_SetItemString(d, \"PyArray_UNICODE\", PyInt_FromLong(PyArray_UNICODE));\n+ PyDict_SetItemString(d, \"PyArray_VOID\", PyInt_FromLong(PyArray_VOID));\n+ PyDict_SetItemString(d, \"PyArray_NTYPES\", PyInt_FromLong(PyArray_NTYPES));\n+ PyDict_SetItemString(d, \"PyArray_NOTYPE\", PyInt_FromLong(PyArray_NOTYPE));\n+ PyDict_SetItemString(d, \"PyArray_UDERDEF\", PyInt_FromLong(PyArray_USERDEF));\n+\n+ PyDict_SetItemString(d, \"CONTIGUOUS\", PyInt_FromLong(CONTIGUOUS));\n+ PyDict_SetItemString(d, \"FORTRAN\", PyInt_FromLong(FORTRAN));\n+ PyDict_SetItemString(d, \"OWNDATA\", PyInt_FromLong(OWNDATA));\n+ PyDict_SetItemString(d, \"ENSURECOPY\", PyInt_FromLong(ENSURECOPY));\n+ PyDict_SetItemString(d, \"ENSUREARRAY\", PyInt_FromLong(ENSUREARRAY));\n+ PyDict_SetItemString(d, \"ALIGNED\", PyInt_FromLong(ALIGNED));\n+ PyDict_SetItemString(d, \"NOTSWAPPED\", PyInt_FromLong(NOTSWAPPED));\n+ PyDict_SetItemString(d, \"WRITEABLE\", PyInt_FromLong(WRITEABLE));\n+ PyDict_SetItemString(d, \"UPDATEIFCOPY\", PyInt_FromLong(UPDATEIFCOPY));\n+\n+ PyDict_SetItemString(d, \"BEHAVED_FLAGS\", PyInt_FromLong(BEHAVED_FLAGS));\n+ PyDict_SetItemString(d, \"BEHAVED_FLAGS_RO\", PyInt_FromLong(BEHAVED_FLAGS_RO));\n+ PyDict_SetItemString(d, \"CARRAY_FLAGS\", PyInt_FromLong(CARRAY_FLAGS));\n+ PyDict_SetItemString(d, \"FARRAY_FLAGS\", PyInt_FromLong(FARRAY_FLAGS));\n+ PyDict_SetItemString(d, \"DEFAULT_FLAGS\", PyInt_FromLong(DEFAULT_FLAGS));\n+ PyDict_SetItemString(d, \"UPDATE_ALL_FLAGS\", PyInt_FromLong(UPDATE_ALL_FLAGS));\n+\n+ if (PyErr_Occurred())\n+ Py_FatalError(\"can't initialize module wrap\");\n+\n+}\n+#ifdef __cplusplus\n+}\n+#endif\n", "added_lines": 190, "deleted_lines": 0, "source_code": "/* File: wrapmodule.c\n * This file is auto-generated with f2py (version:2_1330).\n * Hand edited by Pearu.\n * f2py is a Fortran to Python Interface Generator (FPIG), Second Edition,\n * written by Pearu Peterson .\n * See http://cens.ioc.ee/projects/f2py2e/\n * Generation date: Fri Oct 21 22:41:12 2005\n * $Revision:$\n * $Date:$\n * Do not edit this file directly unless you know what you are doing!!!\n */\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n/*********************** See f2py2e/cfuncs.py: includes ***********************/\n#include \"Python.h\"\n#include \"fortranobject.h\"\n#include \n\nstatic PyObject *wrap_error;\nstatic PyObject *wrap_module;\n\n/************************************ call ************************************/\nstatic char doc_f2py_rout_wrap_call[] = \"\\\nFunction signature:\\n\\\n arr = call(type_num,dims,intent,obj)\\n\\\nRequired arguments:\\n\"\n\" type_num : input int\\n\"\n\" dims : input int-sequence\\n\"\n\" intent : input int\\n\"\n\" obj : input python object\\n\"\n\"Return objects:\\n\"\n\" arr : array\";\nstatic PyObject *f2py_rout_wrap_call(PyObject *capi_self,\n\t\t\t\t PyObject *capi_args) {\n PyObject * volatile capi_buildvalue = NULL;\n int type_num = 0;\n intp *dims = NULL;\n PyObject *dims_capi = Py_None;\n int rank = 0;\n int intent = 0;\n PyArrayObject *capi_arr_tmp = NULL;\n PyObject *arr_capi = Py_None;\n int i;\n\n if (!PyArg_ParseTuple(capi_args,\"iOiO|:wrap.call\",\\\n\t\t\t&type_num,&dims_capi,&intent,&arr_capi))\n return NULL;\n rank = PySequence_Length(dims_capi);\n dims = malloc(rank*sizeof(intp));\n for (i=0;idata);\n dimensions = PyTuple_New(arr->nd);\n strides = PyTuple_New(arr->nd);\n for (i=0;ind;++i) {\n PyTuple_SetItem(dimensions,i,PyInt_FromLong(arr->dimensions[i]));\n PyTuple_SetItem(strides,i,PyInt_FromLong(arr->strides[i]));\n }\n return Py_BuildValue(\"siOOO(cciii)ii\",s,arr->nd,\n\t\t dimensions,strides,\n\t\t (arr->base==NULL?Py_None:arr->base),\n\t\t arr->descr->kind,\n\t\t arr->descr->type,\n\t\t arr->descr->type_num,\n\t\t arr->descr->elsize,\n\t\t arr->descr->alignment,\n\t\t arr->flags,\n\t\t arr->itemsize);\n}\n\nstatic PyMethodDef f2py_module_methods[] = {\n\n {\"call\",f2py_rout_wrap_call,METH_VARARGS,doc_f2py_rout_wrap_call},\n {\"array_attrs\",f2py_rout_wrap_attrs,METH_VARARGS,doc_f2py_rout_wrap_attrs},\n {NULL,NULL}\n};\n\nDL_EXPORT(void) initwrap(void) {\n PyObject *m,*d, *s;\n m = wrap_module = Py_InitModule(\"wrap\", f2py_module_methods);\n PyFortran_Type.ob_type = &PyType_Type;\n import_array();\n if (PyErr_Occurred())\n Py_FatalError(\"can't initialize module wrap (failed to import scipy.base)\");\n d = PyModule_GetDict(m);\n s = PyString_FromString(\"This module 'wrap' is auto-generated with f2py (version:2_1330).\\nFunctions:\\n\"\n\" arr = call(type_num,dims,intent,obj)\\n\"\n\".\");\n PyDict_SetItemString(d, \"__doc__\", s);\n wrap_error = PyErr_NewException (\"wrap.error\", NULL, NULL);\n Py_DECREF(s);\n PyDict_SetItemString(d, \"F2PY_INTENT_IN\", PyInt_FromLong(F2PY_INTENT_IN));\n PyDict_SetItemString(d, \"F2PY_INTENT_INOUT\", PyInt_FromLong(F2PY_INTENT_INOUT));\n PyDict_SetItemString(d, \"F2PY_INTENT_OUT\", PyInt_FromLong(F2PY_INTENT_OUT));\n PyDict_SetItemString(d, \"F2PY_INTENT_HIDE\", PyInt_FromLong(F2PY_INTENT_HIDE));\n PyDict_SetItemString(d, \"F2PY_INTENT_CACHE\", PyInt_FromLong(F2PY_INTENT_CACHE));\n PyDict_SetItemString(d, \"F2PY_INTENT_COPY\", PyInt_FromLong(F2PY_INTENT_COPY));\n PyDict_SetItemString(d, \"F2PY_INTENT_C\", PyInt_FromLong(F2PY_INTENT_C));\n PyDict_SetItemString(d, \"F2PY_OPTIONAL\", PyInt_FromLong(F2PY_OPTIONAL));\n PyDict_SetItemString(d, \"F2PY_INTENT_INPLACE\", PyInt_FromLong(F2PY_INTENT_INPLACE));\n PyDict_SetItemString(d, \"PyArray_BOOL\", PyInt_FromLong(PyArray_BOOL));\n PyDict_SetItemString(d, \"PyArray_BYTE\", PyInt_FromLong(PyArray_BYTE));\n PyDict_SetItemString(d, \"PyArray_UBYTE\", PyInt_FromLong(PyArray_UBYTE));\n PyDict_SetItemString(d, \"PyArray_SHORT\", PyInt_FromLong(PyArray_SHORT));\n PyDict_SetItemString(d, \"PyArray_USHORT\", PyInt_FromLong(PyArray_USHORT));\n PyDict_SetItemString(d, \"PyArray_INT\", PyInt_FromLong(PyArray_INT));\n PyDict_SetItemString(d, \"PyArray_UINT\", PyInt_FromLong(PyArray_UINT));\n PyDict_SetItemString(d, \"PyArray_INTP\", PyInt_FromLong(PyArray_INTP));\n PyDict_SetItemString(d, \"PyArray_UINTP\", PyInt_FromLong(PyArray_UINTP));\n PyDict_SetItemString(d, \"PyArray_LONG\", PyInt_FromLong(PyArray_LONG));\n PyDict_SetItemString(d, \"PyArray_ULONG\", PyInt_FromLong(PyArray_ULONG));\n PyDict_SetItemString(d, \"PyArray_LONGLONG\", PyInt_FromLong(PyArray_LONGLONG));\n PyDict_SetItemString(d, \"PyArray_ULONGLONG\", PyInt_FromLong(PyArray_ULONGLONG));\n PyDict_SetItemString(d, \"PyArray_FLOAT\", PyInt_FromLong(PyArray_FLOAT));\n PyDict_SetItemString(d, \"PyArray_DOUBLE\", PyInt_FromLong(PyArray_DOUBLE));\n PyDict_SetItemString(d, \"PyArray_LONGDOUBLE\", PyInt_FromLong(PyArray_LONGDOUBLE));\n PyDict_SetItemString(d, \"PyArray_CFLOAT\", PyInt_FromLong(PyArray_CFLOAT));\n PyDict_SetItemString(d, \"PyArray_CDOUBLE\", PyInt_FromLong(PyArray_CDOUBLE));\n PyDict_SetItemString(d, \"PyArray_CLONGDOUBLE\", PyInt_FromLong(PyArray_CLONGDOUBLE));\n PyDict_SetItemString(d, \"PyArray_OBJECT\", PyInt_FromLong(PyArray_OBJECT));\n PyDict_SetItemString(d, \"PyArray_STRING\", PyInt_FromLong(PyArray_STRING));\n PyDict_SetItemString(d, \"PyArray_UNICODE\", PyInt_FromLong(PyArray_UNICODE));\n PyDict_SetItemString(d, \"PyArray_VOID\", PyInt_FromLong(PyArray_VOID));\n PyDict_SetItemString(d, \"PyArray_NTYPES\", PyInt_FromLong(PyArray_NTYPES));\n PyDict_SetItemString(d, \"PyArray_NOTYPE\", PyInt_FromLong(PyArray_NOTYPE));\n PyDict_SetItemString(d, \"PyArray_UDERDEF\", PyInt_FromLong(PyArray_USERDEF));\n\n PyDict_SetItemString(d, \"CONTIGUOUS\", PyInt_FromLong(CONTIGUOUS));\n PyDict_SetItemString(d, \"FORTRAN\", PyInt_FromLong(FORTRAN));\n PyDict_SetItemString(d, \"OWNDATA\", PyInt_FromLong(OWNDATA));\n PyDict_SetItemString(d, \"ENSURECOPY\", PyInt_FromLong(ENSURECOPY));\n PyDict_SetItemString(d, \"ENSUREARRAY\", PyInt_FromLong(ENSUREARRAY));\n PyDict_SetItemString(d, \"ALIGNED\", PyInt_FromLong(ALIGNED));\n PyDict_SetItemString(d, \"NOTSWAPPED\", PyInt_FromLong(NOTSWAPPED));\n PyDict_SetItemString(d, \"WRITEABLE\", PyInt_FromLong(WRITEABLE));\n PyDict_SetItemString(d, \"UPDATEIFCOPY\", PyInt_FromLong(UPDATEIFCOPY));\n\n PyDict_SetItemString(d, \"BEHAVED_FLAGS\", PyInt_FromLong(BEHAVED_FLAGS));\n PyDict_SetItemString(d, \"BEHAVED_FLAGS_RO\", PyInt_FromLong(BEHAVED_FLAGS_RO));\n PyDict_SetItemString(d, \"CARRAY_FLAGS\", PyInt_FromLong(CARRAY_FLAGS));\n PyDict_SetItemString(d, \"FARRAY_FLAGS\", PyInt_FromLong(FARRAY_FLAGS));\n PyDict_SetItemString(d, \"DEFAULT_FLAGS\", PyInt_FromLong(DEFAULT_FLAGS));\n PyDict_SetItemString(d, \"UPDATE_ALL_FLAGS\", PyInt_FromLong(UPDATE_ALL_FLAGS));\n\n if (PyErr_Occurred())\n Py_FatalError(\"can't initialize module wrap\");\n\n}\n#ifdef __cplusplus\n}\n#endif\n", "source_code_before": null, "methods": [ { "name": "f2py_rout_wrap_call", "long_name": "f2py_rout_wrap_call( PyObject * capi_self , PyObject * capi_args)", "filename": "wrapmodule.c", "nloc": 25, "complexity": 4, "token_count": 180, "parameters": [ "capi_self", "capi_args" ], "start_line": 35, "end_line": 61, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 1 }, { "name": "f2py_rout_wrap_attrs", "long_name": "f2py_rout_wrap_attrs( PyObject * capi_self , PyObject * capi_args)", "filename": "wrapmodule.c", "nloc": 31, "complexity": 4, "token_count": 234, "parameters": [ "capi_self", "capi_args" ], "start_line": 78, "end_line": 108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 1 }, { "name": "initwrap", "long_name": "initwrap()", "filename": "wrapmodule.c", "nloc": 67, "complexity": 3, "token_count": 700, "parameters": [], "start_line": 117, "end_line": 187, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 71, "top_nesting_level": 1 } ], "methods_before": [], "changed_methods": [ { "name": "f2py_rout_wrap_attrs", "long_name": "f2py_rout_wrap_attrs( PyObject * capi_self , PyObject * capi_args)", "filename": "wrapmodule.c", "nloc": 31, "complexity": 4, "token_count": 234, "parameters": [ "capi_self", "capi_args" ], "start_line": 78, "end_line": 108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 1 }, { "name": "initwrap", "long_name": "initwrap()", "filename": "wrapmodule.c", "nloc": 67, "complexity": 3, "token_count": 700, "parameters": [], "start_line": 117, "end_line": 187, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 71, "top_nesting_level": 1 }, { "name": "f2py_rout_wrap_call", "long_name": "f2py_rout_wrap_call( PyObject * capi_self , PyObject * capi_args)", "filename": "wrapmodule.c", "nloc": 25, "complexity": 4, "token_count": 180, "parameters": [ "capi_self", "capi_args" ], "start_line": 35, "end_line": 61, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 1 } ], "nloc": 160, "complexity": 11, "token_count": 1211, "diff_parsed": { "added": [ "/* File: wrapmodule.c", " * This file is auto-generated with f2py (version:2_1330).", " * Hand edited by Pearu.", " * f2py is a Fortran to Python Interface Generator (FPIG), Second Edition,", " * written by Pearu Peterson .", " * See http://cens.ioc.ee/projects/f2py2e/", " * Generation date: Fri Oct 21 22:41:12 2005", " * $Revision:$", " * $Date:$", " * Do not edit this file directly unless you know what you are doing!!!", " */", "#ifdef __cplusplus", "extern \"C\" {", "#endif", "", "/*********************** See f2py2e/cfuncs.py: includes ***********************/", "#include \"Python.h\"", "#include \"fortranobject.h\"", "#include ", "", "static PyObject *wrap_error;", "static PyObject *wrap_module;", "", "/************************************ call ************************************/", "static char doc_f2py_rout_wrap_call[] = \"\\", "Function signature:\\n\\", " arr = call(type_num,dims,intent,obj)\\n\\", "Required arguments:\\n\"", "\" type_num : input int\\n\"", "\" dims : input int-sequence\\n\"", "\" intent : input int\\n\"", "\" obj : input python object\\n\"", "\"Return objects:\\n\"", "\" arr : array\";", "static PyObject *f2py_rout_wrap_call(PyObject *capi_self,", "\t\t\t\t PyObject *capi_args) {", " PyObject * volatile capi_buildvalue = NULL;", " int type_num = 0;", " intp *dims = NULL;", " PyObject *dims_capi = Py_None;", " int rank = 0;", " int intent = 0;", " PyArrayObject *capi_arr_tmp = NULL;", " PyObject *arr_capi = Py_None;", " int i;", "", " if (!PyArg_ParseTuple(capi_args,\"iOiO|:wrap.call\",\\", "\t\t\t&type_num,&dims_capi,&intent,&arr_capi))", " return NULL;", " rank = PySequence_Length(dims_capi);", " dims = malloc(rank*sizeof(intp));", " for (i=0;idata);", " dimensions = PyTuple_New(arr->nd);", " strides = PyTuple_New(arr->nd);", " for (i=0;ind;++i) {", " PyTuple_SetItem(dimensions,i,PyInt_FromLong(arr->dimensions[i]));", " PyTuple_SetItem(strides,i,PyInt_FromLong(arr->strides[i]));", " }", " return Py_BuildValue(\"siOOO(cciii)ii\",s,arr->nd,", "\t\t dimensions,strides,", "\t\t (arr->base==NULL?Py_None:arr->base),", "\t\t arr->descr->kind,", "\t\t arr->descr->type,", "\t\t arr->descr->type_num,", "\t\t arr->descr->elsize,", "\t\t arr->descr->alignment,", "\t\t arr->flags,", "\t\t arr->itemsize);", "}", "", "static PyMethodDef f2py_module_methods[] = {", "", " {\"call\",f2py_rout_wrap_call,METH_VARARGS,doc_f2py_rout_wrap_call},", " {\"array_attrs\",f2py_rout_wrap_attrs,METH_VARARGS,doc_f2py_rout_wrap_attrs},", " {NULL,NULL}", "};", "", "DL_EXPORT(void) initwrap(void) {", " PyObject *m,*d, *s;", " m = wrap_module = Py_InitModule(\"wrap\", f2py_module_methods);", " PyFortran_Type.ob_type = &PyType_Type;", " import_array();", " if (PyErr_Occurred())", " Py_FatalError(\"can't initialize module wrap (failed to import scipy.base)\");", " d = PyModule_GetDict(m);", " s = PyString_FromString(\"This module 'wrap' is auto-generated with f2py (version:2_1330).\\nFunctions:\\n\"", "\" arr = call(type_num,dims,intent,obj)\\n\"", "\".\");", " PyDict_SetItemString(d, \"__doc__\", s);", " wrap_error = PyErr_NewException (\"wrap.error\", NULL, NULL);", " Py_DECREF(s);", " PyDict_SetItemString(d, \"F2PY_INTENT_IN\", PyInt_FromLong(F2PY_INTENT_IN));", " PyDict_SetItemString(d, \"F2PY_INTENT_INOUT\", PyInt_FromLong(F2PY_INTENT_INOUT));", " PyDict_SetItemString(d, \"F2PY_INTENT_OUT\", PyInt_FromLong(F2PY_INTENT_OUT));", " PyDict_SetItemString(d, \"F2PY_INTENT_HIDE\", PyInt_FromLong(F2PY_INTENT_HIDE));", " PyDict_SetItemString(d, \"F2PY_INTENT_CACHE\", PyInt_FromLong(F2PY_INTENT_CACHE));", " PyDict_SetItemString(d, \"F2PY_INTENT_COPY\", PyInt_FromLong(F2PY_INTENT_COPY));", " PyDict_SetItemString(d, \"F2PY_INTENT_C\", PyInt_FromLong(F2PY_INTENT_C));", " PyDict_SetItemString(d, \"F2PY_OPTIONAL\", PyInt_FromLong(F2PY_OPTIONAL));", " PyDict_SetItemString(d, \"F2PY_INTENT_INPLACE\", PyInt_FromLong(F2PY_INTENT_INPLACE));", " PyDict_SetItemString(d, \"PyArray_BOOL\", PyInt_FromLong(PyArray_BOOL));", " PyDict_SetItemString(d, \"PyArray_BYTE\", PyInt_FromLong(PyArray_BYTE));", " PyDict_SetItemString(d, \"PyArray_UBYTE\", PyInt_FromLong(PyArray_UBYTE));", " PyDict_SetItemString(d, \"PyArray_SHORT\", PyInt_FromLong(PyArray_SHORT));", " PyDict_SetItemString(d, \"PyArray_USHORT\", PyInt_FromLong(PyArray_USHORT));", " PyDict_SetItemString(d, \"PyArray_INT\", PyInt_FromLong(PyArray_INT));", " PyDict_SetItemString(d, \"PyArray_UINT\", PyInt_FromLong(PyArray_UINT));", " PyDict_SetItemString(d, \"PyArray_INTP\", PyInt_FromLong(PyArray_INTP));", " PyDict_SetItemString(d, \"PyArray_UINTP\", PyInt_FromLong(PyArray_UINTP));", " PyDict_SetItemString(d, \"PyArray_LONG\", PyInt_FromLong(PyArray_LONG));", " PyDict_SetItemString(d, \"PyArray_ULONG\", PyInt_FromLong(PyArray_ULONG));", " PyDict_SetItemString(d, \"PyArray_LONGLONG\", PyInt_FromLong(PyArray_LONGLONG));", " PyDict_SetItemString(d, \"PyArray_ULONGLONG\", PyInt_FromLong(PyArray_ULONGLONG));", " PyDict_SetItemString(d, \"PyArray_FLOAT\", PyInt_FromLong(PyArray_FLOAT));", " PyDict_SetItemString(d, \"PyArray_DOUBLE\", PyInt_FromLong(PyArray_DOUBLE));", " PyDict_SetItemString(d, \"PyArray_LONGDOUBLE\", PyInt_FromLong(PyArray_LONGDOUBLE));", " PyDict_SetItemString(d, \"PyArray_CFLOAT\", PyInt_FromLong(PyArray_CFLOAT));", " PyDict_SetItemString(d, \"PyArray_CDOUBLE\", PyInt_FromLong(PyArray_CDOUBLE));", " PyDict_SetItemString(d, \"PyArray_CLONGDOUBLE\", PyInt_FromLong(PyArray_CLONGDOUBLE));", " PyDict_SetItemString(d, \"PyArray_OBJECT\", PyInt_FromLong(PyArray_OBJECT));", " PyDict_SetItemString(d, \"PyArray_STRING\", PyInt_FromLong(PyArray_STRING));", " PyDict_SetItemString(d, \"PyArray_UNICODE\", PyInt_FromLong(PyArray_UNICODE));", " PyDict_SetItemString(d, \"PyArray_VOID\", PyInt_FromLong(PyArray_VOID));", " PyDict_SetItemString(d, \"PyArray_NTYPES\", PyInt_FromLong(PyArray_NTYPES));", " PyDict_SetItemString(d, \"PyArray_NOTYPE\", PyInt_FromLong(PyArray_NOTYPE));", " PyDict_SetItemString(d, \"PyArray_UDERDEF\", PyInt_FromLong(PyArray_USERDEF));", "", " PyDict_SetItemString(d, \"CONTIGUOUS\", PyInt_FromLong(CONTIGUOUS));", " PyDict_SetItemString(d, \"FORTRAN\", PyInt_FromLong(FORTRAN));", " PyDict_SetItemString(d, \"OWNDATA\", PyInt_FromLong(OWNDATA));", " PyDict_SetItemString(d, \"ENSURECOPY\", PyInt_FromLong(ENSURECOPY));", " PyDict_SetItemString(d, \"ENSUREARRAY\", PyInt_FromLong(ENSUREARRAY));", " PyDict_SetItemString(d, \"ALIGNED\", PyInt_FromLong(ALIGNED));", " PyDict_SetItemString(d, \"NOTSWAPPED\", PyInt_FromLong(NOTSWAPPED));", " PyDict_SetItemString(d, \"WRITEABLE\", PyInt_FromLong(WRITEABLE));", " PyDict_SetItemString(d, \"UPDATEIFCOPY\", PyInt_FromLong(UPDATEIFCOPY));", "", " PyDict_SetItemString(d, \"BEHAVED_FLAGS\", PyInt_FromLong(BEHAVED_FLAGS));", " PyDict_SetItemString(d, \"BEHAVED_FLAGS_RO\", PyInt_FromLong(BEHAVED_FLAGS_RO));", " PyDict_SetItemString(d, \"CARRAY_FLAGS\", PyInt_FromLong(CARRAY_FLAGS));", " PyDict_SetItemString(d, \"FARRAY_FLAGS\", PyInt_FromLong(FARRAY_FLAGS));", " PyDict_SetItemString(d, \"DEFAULT_FLAGS\", PyInt_FromLong(DEFAULT_FLAGS));", " PyDict_SetItemString(d, \"UPDATE_ALL_FLAGS\", PyInt_FromLong(UPDATE_ALL_FLAGS));", "", " if (PyErr_Occurred())", " Py_FatalError(\"can't initialize module wrap\");", "", "}", "#ifdef __cplusplus", "}", "#endif" ], "deleted": [] } } ] }, { "hash": "878d5355b9e5ef92db78a51daff325f34d295690", "msg": "Reimplemented array_from_pyobj using scipy.base CAPI.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2005-10-25T21:42:41+00:00", "author_timezone": 0, "committer_date": "2005-10-25T21:42:41+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "72c2028abbdc2add6948a0551d4231852d7390b0" ], "project_name": "repo_copy", "project_path": "/tmp/tmpn4cqam_6/repo_copy", "deletions": 0, "insertions": 127, "lines": 127, "files": 1, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 0.0, "modified_files": [ { "old_path": "scipy/f2py2e/src/fortranobject.c", "new_path": "scipy/f2py2e/src/fortranobject.c", "filename": "fortranobject.c", "extension": "c", "change_type": "MODIFY", "diff": "@@ -549,6 +549,133 @@ PyArrayObject* array_from_pyobj(const int type_num,\n Py_BuildValue(\"N\",arr).\n Otherwise, if obj!=arr then the caller must call Py_DECREF(arr).\n */\n+\n+ if (intent & F2PY_INTENT_CACHE) {\n+ /* Don't expect correct storage order or anything reasonable when\n+ returning intent(cache) array. */ \n+ if ((intent & F2PY_INTENT_HIDE)\n+\t|| (obj==Py_None)) {\n+ PyArrayObject *arr = NULL;\n+ CHECK_DIMS_DEFINED(rank,dims,\"optional,intent(cache) must\"\n+\t\t\t \" have defined dimensions.\\n\");\n+ arr = (PyArrayObject *)PyArray_SimpleNew(rank,dims,type_num);\n+ ARR_IS_NULL(arr==NULL,\"PyArray_SimpleNew failed: optional,intent(cache)\\n\");\n+ return arr;\n+ }\n+ if (PyArray_Check(obj) \n+\t&& PyArray_ISONESEGMENT(obj)\n+\t&& HAS_PROPER_ELSIZE((PyArrayObject *)obj,type_num)\n+\t) {\n+ if (check_and_fix_dimensions((PyArrayObject *)obj,rank,dims))\n+\treturn NULL; /*XXX: set exception */\n+ {\n+\tif (intent & F2PY_INTENT_OUT)\n+\t Py_INCREF(obj);\n+\treturn (PyArrayObject *)obj;\n+ }\n+ }\n+ ARR_IS_NULL(1,\"intent(cache) must be contiguous array with a proper elsize.\\n\");\n+ }\n+\n+ if (intent & F2PY_INTENT_HIDE) {\n+ PyArrayObject *arr = NULL;\n+ CHECK_DIMS_DEFINED(rank,dims,\"intent(hide) must have defined dimensions.\\n\");\n+ arr = (PyArrayObject *)\n+ PyArray_New(&PyArray_Type, rank, dims, type_num,\n+\t\t NULL,NULL,0,\n+\t\t !(intent&F2PY_INTENT_C),\n+\t\t NULL);\n+ ARR_IS_NULL(arr==NULL,\"PyArray_New failed: intent(hide)\\n\");\n+ PyArray_FILLWBYTE(arr, 0);\n+ return arr;\n+ }\n+\n+ if (PyArray_Check(obj)) { /* here we have always intent(in) or\n+\t\t\t intent(inout) or intent(inplace) */\n+ PyArrayObject *arr = (PyArrayObject *)obj;\n+\n+ if (check_and_fix_dimensions(arr,rank,dims))\n+ return NULL; /*XXX: set exception */\n+\n+ if ((! (intent & F2PY_INTENT_COPY))\n+\t&& HAS_PROPER_ELSIZE(arr,type_num)\n+\t&& PyArray_CanCastSafely(arr->descr->type_num,type_num)\n+\t) {\n+ if ((intent & F2PY_INTENT_C)?PyArray_ISCARRAY(arr):PyArray_ISFARRAY(arr)) {\n+\tif ((intent & F2PY_INTENT_OUT)) {\n+\t Py_INCREF(arr);\n+\t}\n+\treturn arr;\n+ }\n+ }\n+\n+ {\n+ PyArrayObject *retarr = (PyArrayObject *) \\\n+\tPyArray_New(&PyArray_Type, rank, dims, type_num,\n+\t\t NULL,NULL,0,\n+\t\t !(intent&F2PY_INTENT_C),\n+\t\t NULL);\n+\n+ ARR_IS_NULL(retarr==NULL,\"PyArray_New failed: intent(in,copy)\\n\");\n+ if (PyArray_CopyInto(retarr, arr)) {\n+\tPy_DECREF(retarr);\n+\treturn NULL;\n+ }\n+ if (intent & F2PY_INTENT_INPLACE) {\n+\tif (swap_arrays(arr,retarr))\n+\t return NULL;\n+\tPy_XDECREF(retarr);\n+\tif (intent & F2PY_INTENT_OUT)\n+\t Py_INCREF(arr);\t\n+ } else {\n+\tarr = retarr;\n+ }\n+ }\n+ return arr;\n+ }\n+\n+ if ((obj==Py_None) && (intent & F2PY_OPTIONAL)) {\n+ PyArrayObject *arr = NULL;\n+ CHECK_DIMS_DEFINED(rank,dims,\"optional must have defined dimensions.\\n\");\n+ arr = (PyArrayObject *)\n+ PyArray_New(&PyArray_Type, rank, dims, type_num,\n+\t\t NULL,NULL,0,\n+\t\t !(intent&F2PY_INTENT_C),\n+\t\t NULL);\n+ ARR_IS_NULL(arr==NULL,\"PyArray_New failed: optional\\n\");\n+ PyArray_FILLWBYTE(arr, 0);\n+ return arr;\n+ }\n+\n+ if ((intent & F2PY_INTENT_INOUT) || (intent & F2PY_INTENT_INPLACE)) {\n+ ARR_IS_NULL(1,\"intent(inout)|intent(inplace) argument must be an array.\\n\");\n+ }\n+\n+ {\n+ PyArray_Typecode typecode = {type_num, 0, 0};\n+ PyArrayObject *arr = (PyArrayObject *) \\\n+ PyArray_FromAny(obj,&typecode, 0,0,\n+\t\t ((intent & F2PY_INTENT_C)?CARRAY_FLAGS:FARRAY_FLAGS));\n+ ARR_IS_NULL(arr==NULL,\"PyArray_FromAny failed: not a sequence.\\n\");\n+ if (check_and_fix_dimensions(arr,rank,dims))\n+ return NULL; /*XXX: set exception */\n+ return arr;\n+ }\n+\n+}\n+\n+extern\n+PyArrayObject* old_array_from_pyobj(const int type_num,\n+\t\t\t\tintp *dims,\n+\t\t\t\tconst int rank,\n+\t\t\t\tconst int intent,\n+\t\t\t\tPyObject *obj) {\n+ /* Note about reference counting\n+ -----------------------------\n+ If the caller returns the array to Python, it must be done with\n+ Py_BuildValue(\"N\",arr).\n+ Otherwise, if obj!=arr then the caller must call Py_DECREF(arr).\n+ */\n if (intent & F2PY_INTENT_CACHE) {\n /* Don't expect correct storage order or anything reasonable when\n returning intent(cache) array. */ \n", "added_lines": 127, "deleted_lines": 0, "source_code": "#define FORTRANOBJECT_C\n#include \"fortranobject.h\"\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n/*\n This file implements: FortranObject, array_from_pyobj, copy_ND_array,\n lazy_transpose, transpose_strides,\n\t\t and array_has_column_major_storage.\n\n Author: Pearu Peterson \n $Revision: 1.52 $\n $Date: 2005/07/11 07:44:20 $\n*/\n\n/************************* FortranObject *******************************/\n\ntypedef PyObject *(*fortranfunc)(PyObject *,PyObject *,PyObject *,void *);\n\nPyObject *\nPyFortranObject_New(FortranDataDef* defs, f2py_void_func init) {\n int i;\n PyFortranObject *fp = NULL;\n PyObject *v = NULL;\n if (init!=NULL) /* Initialize F90 module objects */\n (*(init))();\n if ((fp = PyObject_New(PyFortranObject, &PyFortran_Type))==NULL) return NULL;\n if ((fp->dict = PyDict_New())==NULL) return NULL;\n fp->len = 0;\n while (defs[fp->len].name != NULL) fp->len++;\n if (fp->len == 0) goto fail;\n fp->defs = defs;\n for (i=0;ilen;i++)\n if (fp->defs[i].rank == -1) { /* Is Fortran routine */\n v = PyFortranObject_NewAsAttr(&(fp->defs[i]));\n if (v==NULL) return NULL;\n PyDict_SetItemString(fp->dict,fp->defs[i].name,v);\n } else\n if ((fp->defs[i].data)!=NULL) { /* Is Fortran variable or array (not allocatable) */\n\tv = PyArray_New(&PyArray_Type, fp->defs[i].rank, fp->defs[i].dims.d,\n\t\t\tfp->defs[i].type, NULL, fp->defs[i].data, 0, FARRAY_FLAGS,\n\t\t\tNULL);\n\tif (v==NULL) return NULL;\n\tPyDict_SetItemString(fp->dict,fp->defs[i].name,v);\n }\n Py_XDECREF(v);\n return (PyObject *)fp;\n fail:\n Py_XDECREF(v);\n return NULL;\n}\n\nPyObject *\nPyFortranObject_NewAsAttr(FortranDataDef* defs) { /* used for calling F90 module routines */\n PyFortranObject *fp = NULL;\n fp = PyObject_New(PyFortranObject, &PyFortran_Type);\n if (fp == NULL) return NULL;\n if ((fp->dict = PyDict_New())==NULL) return NULL;\n fp->len = 1;\n fp->defs = defs;\n return (PyObject *)fp;\n}\n\n/* Fortran methods */\n\nstatic void\nfortran_dealloc(PyFortranObject *fp) {\n Py_XDECREF(fp->dict);\n PyMem_Del(fp);\n}\n\n\nstatic PyMethodDef fortran_methods[] = {\n\t{NULL,\t\tNULL}\t\t/* sentinel */\n};\n\n\nstatic PyObject *\nfortran_doc (FortranDataDef def) {\n char *p;\n PyObject *s = NULL;\n int i;\n unsigned size=100;\n if (def.doc!=NULL)\n size += strlen(def.doc);\n p = (char*)malloc (size);\n if (sprintf(p,\"%s - \",def.name)==0) goto fail;\n if (def.rank==-1) {\n if (def.doc==NULL) {\n if (sprintf(p,\"%sno docs available\",p)==0)\n\tgoto fail;\n } else {\n if (sprintf(p,\"%s%s\",p,def.doc)==0)\n\tgoto fail;\n }\n } else {\n PyArray_Descr *d = PyArray_DescrFromType(def.type);\n if (sprintf(p,\"%s'%c'-\",p,d->type)==0) goto fail;\n if (def.data==NULL) {\n if (sprintf(p,\"%sarray(%\" INTP_FMT,p,def.dims.d[0])==0) goto fail;\n for(i=1;i0) {\n\tif (sprintf(p,\"%sarray(%\"INTP_FMT,p,def.dims.d[0])==0) goto fail;\n\tfor(i=1;isize) {\n fprintf(stderr,\"fortranobject.c:fortran_doc:len(p)=%zd>%d(size): too long doc string required, increase size\\n\",strlen(p),size);\n goto fail;\n }\n s = PyString_FromString(p);\n fail:\n free(p);\n return s;\n}\n\nstatic FortranDataDef *save_def; /* save pointer of an allocatable array */\nstatic void set_data(char *d,intp *f) { /* callback from Fortran */\n if (*f) /* In fortran f=allocated(d) */\n save_def->data = d;\n else\n save_def->data = NULL;\n /* printf(\"set_data: d=%p,f=%d\\n\",d,*f); */\n}\n\nstatic PyObject *\nfortran_getattr(PyFortranObject *fp, char *name) {\n int i,j,k,flag;\n if (fp->dict != NULL) {\n PyObject *v = PyDict_GetItemString(fp->dict, name);\n if (v != NULL) {\n Py_INCREF(v);\n return v;\n }\n }\n for (i=0,j=1;ilen && (j=strcmp(name,fp->defs[i].name));i++);\n if (j==0)\n if (fp->defs[i].rank!=-1) { /* F90 allocatable array */ \n if (fp->defs[i].func==NULL) return NULL;\n for(k=0;kdefs[i].rank;++k) \n\tfp->defs[i].dims.d[k]=-1;\n save_def = &fp->defs[i];\n (*(fp->defs[i].func))(&fp->defs[i].rank,fp->defs[i].dims.d,set_data,&flag);\n if (flag==2)\n\tk = fp->defs[i].rank + 1;\n else\n\tk = fp->defs[i].rank;\n if (fp->defs[i].data !=NULL) { /* array is allocated */\n\tPyObject *v = PyArray_New(&PyArray_Type, k, fp->defs[i].dims.d,\n\t\t\tfp->defs[i].type, NULL, fp->defs[i].data, 0, FARRAY_FLAGS,\n\t\t\tNULL);\n\tif (v==NULL) return NULL;\n\t/* Py_INCREF(v); */\n\treturn v;\n } else { /* array is not allocated */\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n }\n }\n if (strcmp(name,\"__dict__\")==0) {\n Py_INCREF(fp->dict);\n return fp->dict;\n }\n if (strcmp(name,\"__doc__\")==0) {\n PyObject *s = PyString_FromString(\"\");\n for (i=0;ilen;i++)\n PyString_ConcatAndDel(&s,fortran_doc(fp->defs[i]));\n if (PyDict_SetItemString(fp->dict, name, s))\n return NULL;\n return s;\n }\n if ((strcmp(name,\"_cpointer\")==0) && (fp->len==1)) {\n PyObject *cobj = PyCObject_FromVoidPtr((void *)(fp->defs[0].data),NULL);\n if (PyDict_SetItemString(fp->dict, name, cobj))\n return NULL;\n return cobj;\n }\n return Py_FindMethod(fortran_methods, (PyObject *)fp, name);\n}\n\nstatic int\nfortran_setattr(PyFortranObject *fp, char *name, PyObject *v) {\n int i,j,flag;\n PyArrayObject *arr = NULL;\n for (i=0,j=1;ilen && (j=strcmp(name,fp->defs[i].name));i++);\n if (j==0) {\n if (fp->defs[i].rank==-1) {\n PyErr_SetString(PyExc_AttributeError,\"over-writing fortran routine\");\n return -1;\n }\n if (fp->defs[i].func!=NULL) { /* is allocatable array */\n intp dims[F2PY_MAX_DIMS];\n int k;\n save_def = &fp->defs[i];\n if (v!=Py_None) { /* set new value (reallocate if needed --\n\t\t\t see f2py generated code for more\n\t\t\t details ) */\n\tfor(k=0;kdefs[i].rank;k++) dims[k]=-1;\n\tif ((arr = array_from_pyobj(fp->defs[i].type,dims,fp->defs[i].rank,F2PY_INTENT_IN,v))==NULL)\n\t return -1;\n\t(*(fp->defs[i].func))(&fp->defs[i].rank,arr->dimensions,set_data,&flag);\n } else { /* deallocate */\n\tfor(k=0;kdefs[i].rank;k++) dims[k]=0;\n\t(*(fp->defs[i].func))(&fp->defs[i].rank,dims,set_data,&flag);\n\tfor(k=0;kdefs[i].rank;k++) dims[k]=-1;\n }\n memcpy(fp->defs[i].dims.d,dims,fp->defs[i].rank*sizeof(intp));\n } else { /* not allocatable array */\n if ((arr = array_from_pyobj(fp->defs[i].type,fp->defs[i].dims.d,fp->defs[i].rank,F2PY_INTENT_IN,v))==NULL)\n\treturn -1; \n }\n if (fp->defs[i].data!=NULL) { /* copy Python object to Fortran array */\n intp s = PyArray_MultiplyList(fp->defs[i].dims.d,arr->nd);\n if (s==-1)\n\ts = PyArray_MultiplyList(arr->dimensions,arr->nd);\n if (s<0 ||\n\t (memcpy(fp->defs[i].data,arr->data,s*PyArray_ITEMSIZE(arr)))==NULL) {\n\tif ((PyObject*)arr!=v) {\n\t Py_DECREF(arr);\n\t}\n\treturn -1;\n }\n if ((PyObject*)arr!=v) {\n Py_DECREF(arr);\n }\n } else return (fp->defs[i].func==NULL?-1:0);\n return 0; /* succesful */\n }\n if (fp->dict == NULL) {\n fp->dict = PyDict_New();\n if (fp->dict == NULL)\n return -1;\n }\n if (v == NULL) {\n int rv = PyDict_DelItemString(fp->dict, name);\n if (rv < 0)\n PyErr_SetString(PyExc_AttributeError,\"delete non-existing fortran attribute\");\n return rv;\n }\n else\n return PyDict_SetItemString(fp->dict, name, v);\n}\n\nstatic PyObject*\nfortran_call(PyFortranObject *fp, PyObject *arg, PyObject *kw) {\n int i = 0;\n /* printf(\"fortran call\n name=%s,func=%p,data=%p,%p\\n\",fp->defs[i].name,\n fp->defs[i].func,fp->defs[i].data,&fp->defs[i].data); */\n if (fp->defs[i].rank==-1) {/* is Fortran routine */\n if ((fp->defs[i].func==NULL)) {\n PyErr_Format(PyExc_RuntimeError, \"no function to call\");\n return NULL;\n }\n else if (fp->defs[i].data==NULL)\n /* dummy routine */\n return (*((fortranfunc)(fp->defs[i].func)))((PyObject *)fp,arg,kw,NULL);\n else\n return (*((fortranfunc)(fp->defs[i].func)))((PyObject *)fp,arg,kw,\n\t\t\t\t\t\t (void *)fp->defs[i].data);\n }\n PyErr_Format(PyExc_TypeError, \"this fortran object is not callable\");\n return NULL;\n}\n\n\nPyTypeObject PyFortran_Type = {\n PyObject_HEAD_INIT(0)\n 0,\t\t\t/*ob_size*/\n \"fortran\",\t\t\t/*tp_name*/\n sizeof(PyFortranObject),\t/*tp_basicsize*/\n 0,\t\t\t/*tp_itemsize*/\n /* methods */\n (destructor)fortran_dealloc, /*tp_dealloc*/\n 0,\t\t\t/*tp_print*/\n (getattrfunc)fortran_getattr, /*tp_getattr*/\n (setattrfunc)fortran_setattr, /*tp_setattr*/\n 0,\t\t\t/*tp_compare*/\n 0,\t\t\t/*tp_repr*/\n 0,\t\t\t/*tp_as_number*/\n 0,\t\t\t/*tp_as_sequence*/\n 0,\t\t\t/*tp_as_mapping*/\n 0,\t\t\t/*tp_hash*/\n (ternaryfunc)fortran_call, /*tp_call*/\n};\n\n/************************* f2py_report_atexit *******************************/\n\n#ifdef F2PY_REPORT_ATEXIT\nstatic int passed_time = 0;\nstatic int passed_counter = 0;\nstatic int passed_call_time = 0;\nstatic struct timeb start_time;\nstatic struct timeb stop_time;\nstatic struct timeb start_call_time;\nstatic struct timeb stop_call_time;\nstatic int cb_passed_time = 0;\nstatic int cb_passed_counter = 0;\nstatic int cb_passed_call_time = 0;\nstatic struct timeb cb_start_time;\nstatic struct timeb cb_stop_time;\nstatic struct timeb cb_start_call_time;\nstatic struct timeb cb_stop_call_time;\n\nextern void f2py_start_clock(void) { ftime(&start_time); }\nextern\nvoid f2py_start_call_clock(void) {\n f2py_stop_clock();\n ftime(&start_call_time);\n}\nextern\nvoid f2py_stop_clock(void) {\n ftime(&stop_time);\n passed_time += 1000*(stop_time.time - start_time.time);\n passed_time += stop_time.millitm - start_time.millitm;\n}\nextern\nvoid f2py_stop_call_clock(void) {\n ftime(&stop_call_time);\n passed_call_time += 1000*(stop_call_time.time - start_call_time.time);\n passed_call_time += stop_call_time.millitm - start_call_time.millitm;\n passed_counter += 1;\n f2py_start_clock();\n}\n\nextern void f2py_cb_start_clock(void) { ftime(&cb_start_time); }\nextern\nvoid f2py_cb_start_call_clock(void) {\n f2py_cb_stop_clock();\n ftime(&cb_start_call_time);\n}\nextern\nvoid f2py_cb_stop_clock(void) {\n ftime(&cb_stop_time);\n cb_passed_time += 1000*(cb_stop_time.time - cb_start_time.time);\n cb_passed_time += cb_stop_time.millitm - cb_start_time.millitm;\n}\nextern\nvoid f2py_cb_stop_call_clock(void) {\n ftime(&cb_stop_call_time);\n cb_passed_call_time += 1000*(cb_stop_call_time.time - cb_start_call_time.time);\n cb_passed_call_time += cb_stop_call_time.millitm - cb_start_call_time.millitm;\n cb_passed_counter += 1;\n f2py_cb_start_clock();\n}\n\nstatic int f2py_report_on_exit_been_here = 0;\nextern\nvoid f2py_report_on_exit(int exit_flag,void *name) {\n if (f2py_report_on_exit_been_here) {\n fprintf(stderr,\" %s\\n\",(char*)name);\n return;\n }\n f2py_report_on_exit_been_here = 1;\n fprintf(stderr,\" /-----------------------\\\\\\n\");\n fprintf(stderr,\" < F2PY performance report >\\n\");\n fprintf(stderr,\" \\\\-----------------------/\\n\");\n fprintf(stderr,\"Overall time spent in ...\\n\");\n fprintf(stderr,\"(a) wrapped (Fortran/C) functions : %8d msec\\n\",\n\t passed_call_time);\n fprintf(stderr,\"(b) f2py interface, %6d calls : %8d msec\\n\",\n\t passed_counter,passed_time);\n fprintf(stderr,\"(c) call-back (Python) functions : %8d msec\\n\",\n\t cb_passed_call_time);\n fprintf(stderr,\"(d) f2py call-back interface, %6d calls : %8d msec\\n\",\n\t cb_passed_counter,cb_passed_time);\n \n fprintf(stderr,\"(e) wrapped (Fortran/C) functions (acctual) : %8d msec\\n\\n\",\n\t passed_call_time-cb_passed_call_time-cb_passed_time);\n fprintf(stderr,\"Use -DF2PY_REPORT_ATEXIT_DISABLE to disable this message.\\n\");\n fprintf(stderr,\"Exit status: %d\\n\",exit_flag);\n fprintf(stderr,\"Modules : %s\\n\",(char*)name);\n}\n#endif\n\n/********************** report on array copy ****************************/\n\n#ifdef F2PY_REPORT_ON_ARRAY_COPY\nstatic void f2py_report_on_array_copy(PyArrayObject* arr, char* func_name) {\n const long arr_size = PyArray_Size((PyObject *)arr);\n if (arr_size>F2PY_REPORT_ON_ARRAY_COPY) {\n fprintf(stderr,\"copied an array using %s: size=%ld, elsize=%d\\n\", \n\t func_name, arr_size, PyArray_ITEMSIZE(arr));\n }\n}\n#endif\n\n/************************* lazy_transpose *******************************/\n\nextern\nvoid lazy_transpose(PyArrayObject* arr) {\n /*\n Changes the order of array strides and dimensions. This\n corresponds to the lazy transpose of a Numeric array in-situ.\n Note that this function is assumed to be used even times for a\n given array. Otherwise, the caller should set flags &= ~CONTIGUOUS.\n */\n int rank, i;\n intp s,j; \n rank = arr->nd; \n if (rank < 2) return;\n\n for(i=0,j=rank-1;istrides[i];\n arr->strides[i] = arr->strides[j];\n arr->strides[j] = s;\n s = arr->dimensions[i];\n arr->dimensions[i] = arr->dimensions[j];\n arr->dimensions[j] = s;\n }\n}\n\nextern\nvoid transpose_strides(PyArrayObject* arr) {\n int rank, i;\n intp j;\n rank = arr->nd; \n if (rank < 2) return;\n j = arr->strides[rank-1];\n for(i=0;istrides[i] = j;\n j *= arr->dimensions[i];\n }\n}\n\n/************************* array_from_obj *******************************/\n\n/* \n * File: array_from_pyobj.c \n *\n * Description:\n * ------------ \n * Provides array_from_pyobj function that returns a contigious array\n * object with the given dimensions and required storage order, either\n * in row-major (C) or column-major (Fortran) order. The function\n * array_from_pyobj is very flexible about its Python object argument\n * that can be any number, list, tuple, or array.\n * \n * array_from_pyobj is used in f2py generated Python extension\n * modules.\n *\n * Author: Pearu Peterson \n * Created: 13-16 January 2002\n * $Id: fortranobject.c,v 1.52 2005/07/11 07:44:20 pearu Exp $\n */\n\n\n#define ARR_IS_NULL(arr_is_NULL,mess) \\\nif (arr_is_NULL) { \\\n fprintf(stderr,\"array_from_pyobj:\" mess); \\\n return NULL; \\\n}\n\n#define CHECK_DIMS_DEFINED(rank,dims,mess) \\\nif (count_nonpos(rank,dims)) { int i;\\\n fprintf(stderr,\"array_from_pyobj:\" mess); \\\n fprintf(stderr,\"rank=%d dimensions=[ \",rank); \\\n for(i=0;ielsize) == PyArray_ITEMSIZE(arr))\n\nstatic int \ncount_nonpos(const int rank,\n\t const intp *dims) {\n int i=0,r=0;\n while (ind;\n intp size = PyArray_Size((PyObject *)arr);\n int i;\n printf(\"\\trank = %d, flags = %d, size = %\" INTP_FMT \"\\n\",\n\t rank,arr->flags,size);\n printf(\"\\tstrides = [\");\n for(i=0;istrides[i]);\n }\n printf(\"]\\n\\t dimensions = [\");\n for(i=0;idimensions[i]);\n }\n printf(\"]\\n\");\n}\n#endif\n\n#define SWAPTYPE(a,b,t) {t c; c = (a); (a) = (b); (b) = c; }\n\nstatic int swap_arrays(PyArrayObject* arr1, PyArrayObject* arr2) {\n SWAPTYPE(arr1->data,arr2->data,char*);\n SWAPTYPE(arr1->nd,arr2->nd,int);\n SWAPTYPE(arr1->dimensions,arr2->dimensions,intp*);\n SWAPTYPE(arr1->strides,arr2->strides,intp*);\n SWAPTYPE(arr1->base,arr2->base,PyObject*);\n SWAPTYPE(arr1->descr,arr2->descr,PyArray_Descr*);\n SWAPTYPE(arr1->flags,arr2->flags,int);\n SWAPTYPE(arr1->itemsize, arr2->itemsize, int);\n /* SWAPTYPE(arr1->weakreflist,arr2->weakreflist,PyObject*); */\n return 0;\n}\n\n\t/* useful after a lazy-transpose to update the flags\n\t quickly \n\t*/\n\n#define _lazy_transpose_update_flags(obj) {\t\t \\\n\t\tif (PyArray_ISCONTIGUOUS(obj)) {\t \\\n\t\t\tPyArray_FLAGS(obj) &= ~CONTIGUOUS; \\\n\t\t\tPyArray_FLAGS(obj) |= FORTRAN; \\\n\t\t}\t\t\t\t\t \\\n\t\telse if PyArray_CHKFLAGS(obj, FORTRAN) { \\\n\t\t\tPyArray_FLAGS(obj) &= ~FORTRAN; \\\n\t\t\tPyArray_FLAGS(obj) |= CONTIGUOUS; \\\n\t\t}\t\t\t\t\t \\\n\t}\n\nextern\nPyArrayObject* array_from_pyobj(const int type_num,\n\t\t\t\tintp *dims,\n\t\t\t\tconst int rank,\n\t\t\t\tconst int intent,\n\t\t\t\tPyObject *obj) {\n /* Note about reference counting\n -----------------------------\n If the caller returns the array to Python, it must be done with\n Py_BuildValue(\"N\",arr).\n Otherwise, if obj!=arr then the caller must call Py_DECREF(arr).\n */\n\n if (intent & F2PY_INTENT_CACHE) {\n /* Don't expect correct storage order or anything reasonable when\n returning intent(cache) array. */ \n if ((intent & F2PY_INTENT_HIDE)\n\t|| (obj==Py_None)) {\n PyArrayObject *arr = NULL;\n CHECK_DIMS_DEFINED(rank,dims,\"optional,intent(cache) must\"\n\t\t\t \" have defined dimensions.\\n\");\n arr = (PyArrayObject *)PyArray_SimpleNew(rank,dims,type_num);\n ARR_IS_NULL(arr==NULL,\"PyArray_SimpleNew failed: optional,intent(cache)\\n\");\n return arr;\n }\n if (PyArray_Check(obj) \n\t&& PyArray_ISONESEGMENT(obj)\n\t&& HAS_PROPER_ELSIZE((PyArrayObject *)obj,type_num)\n\t) {\n if (check_and_fix_dimensions((PyArrayObject *)obj,rank,dims))\n\treturn NULL; /*XXX: set exception */\n {\n\tif (intent & F2PY_INTENT_OUT)\n\t Py_INCREF(obj);\n\treturn (PyArrayObject *)obj;\n }\n }\n ARR_IS_NULL(1,\"intent(cache) must be contiguous array with a proper elsize.\\n\");\n }\n\n if (intent & F2PY_INTENT_HIDE) {\n PyArrayObject *arr = NULL;\n CHECK_DIMS_DEFINED(rank,dims,\"intent(hide) must have defined dimensions.\\n\");\n arr = (PyArrayObject *)\n PyArray_New(&PyArray_Type, rank, dims, type_num,\n\t\t NULL,NULL,0,\n\t\t !(intent&F2PY_INTENT_C),\n\t\t NULL);\n ARR_IS_NULL(arr==NULL,\"PyArray_New failed: intent(hide)\\n\");\n PyArray_FILLWBYTE(arr, 0);\n return arr;\n }\n\n if (PyArray_Check(obj)) { /* here we have always intent(in) or\n\t\t\t intent(inout) or intent(inplace) */\n PyArrayObject *arr = (PyArrayObject *)obj;\n\n if (check_and_fix_dimensions(arr,rank,dims))\n return NULL; /*XXX: set exception */\n\n if ((! (intent & F2PY_INTENT_COPY))\n\t&& HAS_PROPER_ELSIZE(arr,type_num)\n\t&& PyArray_CanCastSafely(arr->descr->type_num,type_num)\n\t) {\n if ((intent & F2PY_INTENT_C)?PyArray_ISCARRAY(arr):PyArray_ISFARRAY(arr)) {\n\tif ((intent & F2PY_INTENT_OUT)) {\n\t Py_INCREF(arr);\n\t}\n\treturn arr;\n }\n }\n\n {\n PyArrayObject *retarr = (PyArrayObject *) \\\n\tPyArray_New(&PyArray_Type, rank, dims, type_num,\n\t\t NULL,NULL,0,\n\t\t !(intent&F2PY_INTENT_C),\n\t\t NULL);\n\n ARR_IS_NULL(retarr==NULL,\"PyArray_New failed: intent(in,copy)\\n\");\n if (PyArray_CopyInto(retarr, arr)) {\n\tPy_DECREF(retarr);\n\treturn NULL;\n }\n if (intent & F2PY_INTENT_INPLACE) {\n\tif (swap_arrays(arr,retarr))\n\t return NULL;\n\tPy_XDECREF(retarr);\n\tif (intent & F2PY_INTENT_OUT)\n\t Py_INCREF(arr);\t\n } else {\n\tarr = retarr;\n }\n }\n return arr;\n }\n\n if ((obj==Py_None) && (intent & F2PY_OPTIONAL)) {\n PyArrayObject *arr = NULL;\n CHECK_DIMS_DEFINED(rank,dims,\"optional must have defined dimensions.\\n\");\n arr = (PyArrayObject *)\n PyArray_New(&PyArray_Type, rank, dims, type_num,\n\t\t NULL,NULL,0,\n\t\t !(intent&F2PY_INTENT_C),\n\t\t NULL);\n ARR_IS_NULL(arr==NULL,\"PyArray_New failed: optional\\n\");\n PyArray_FILLWBYTE(arr, 0);\n return arr;\n }\n\n if ((intent & F2PY_INTENT_INOUT) || (intent & F2PY_INTENT_INPLACE)) {\n ARR_IS_NULL(1,\"intent(inout)|intent(inplace) argument must be an array.\\n\");\n }\n\n {\n PyArray_Typecode typecode = {type_num, 0, 0};\n PyArrayObject *arr = (PyArrayObject *) \\\n PyArray_FromAny(obj,&typecode, 0,0,\n\t\t ((intent & F2PY_INTENT_C)?CARRAY_FLAGS:FARRAY_FLAGS));\n ARR_IS_NULL(arr==NULL,\"PyArray_FromAny failed: not a sequence.\\n\");\n if (check_and_fix_dimensions(arr,rank,dims))\n return NULL; /*XXX: set exception */\n return arr;\n }\n\n}\n\nextern\nPyArrayObject* old_array_from_pyobj(const int type_num,\n\t\t\t\tintp *dims,\n\t\t\t\tconst int rank,\n\t\t\t\tconst int intent,\n\t\t\t\tPyObject *obj) {\n /* Note about reference counting\n -----------------------------\n If the caller returns the array to Python, it must be done with\n Py_BuildValue(\"N\",arr).\n Otherwise, if obj!=arr then the caller must call Py_DECREF(arr).\n */\n if (intent & F2PY_INTENT_CACHE) {\n /* Don't expect correct storage order or anything reasonable when\n returning intent(cache) array. */ \n if ((intent & F2PY_INTENT_HIDE)\n\t|| (obj==Py_None)) {\n PyArrayObject *arr = NULL;\n CHECK_DIMS_DEFINED(rank,dims,\"optional,intent(cache) must\"\n\t\t\t \" have defined dimensions.\\n\");\n arr = (PyArrayObject *)PyArray_SimpleNew(rank,dims,type_num);\n ARR_IS_NULL(arr==NULL,\"FromDims failed: optional,intent(cache)\\n\");\n memset(arr->data, 0, PyArray_NBYTES(arr));\n/* if (intent & F2PY_INTENT_OUT) */\n/* \tPy_INCREF(arr); */\n return arr;\n }\n\n if (PyArray_Check(obj) \n\t&& PyArray_ISONESEGMENT(obj)\n\t&& HAS_PROPER_ELSIZE((PyArrayObject *)obj,type_num)\n\t) {\n if (check_and_fix_dimensions((PyArrayObject *)obj,rank,dims))\n\treturn NULL; /*XXX: set exception */\n {\n\tPyArrayObject *obj2;\n\tif (intent & F2PY_INTENT_OUT)\n\t Py_INCREF(obj);\n\tobj2 = (PyArrayObject *) obj;\n\treturn obj2;\n }\n }\n ARR_IS_NULL(1,\"intent(cache) must be contiguous array with a proper elsize.\\n\");\n }\n\n if (intent & F2PY_INTENT_HIDE) {\n PyArrayObject *arr = NULL;\n CHECK_DIMS_DEFINED(rank,dims,\"intent(hide) must have defined dimensions.\\n\");\n arr = (PyArrayObject *)PyArray_SimpleNew(rank, dims, type_num);\n ARR_IS_NULL(arr==NULL,\"FromDims failed: intent(hide)\\n\");\n memset(arr->data, 0, PyArray_NBYTES(arr));\n if (intent & F2PY_INTENT_OUT) {\n if ((!(intent & F2PY_INTENT_C)) && (rank>1)) {\n\ttranspose_strides(arr);\n\tarr->flags &= ~CONTIGUOUS;\n\tarr->flags |= FORTRAN;\n }\n/* Py_INCREF(arr); */\n }\n return arr;\n }\n\n if (PyArray_Check(obj)) { /* here we have always intent(in) or\n\t\t\t intent(inout) or intent(inplace) */\n PyArrayObject *arr;\n int is_cont;\n\n arr = (PyArrayObject *)obj;\n is_cont = (intent & F2PY_INTENT_C) ? \n (ISCONTIGUOUS(arr)) : (2*array_has_column_major_storage(arr));\n if (check_and_fix_dimensions(arr,rank,dims))\n return NULL; /*XXX: set exception */\n if ((intent & F2PY_INTENT_COPY)\n\t|| (! (is_cont\n\t && HAS_PROPER_ELSIZE(arr,type_num)\n\t && PyArray_CanCastSafely(arr->descr->type_num,type_num)\n\t /* Make PyArray_CanCastSafely safer for 64-bit machines: */\n\t /* && (arr->descr->type_num==PyArray_LONG?type_num!=PyArray_DOUBLE:1)*/\n\t ))) {\n PyArrayObject *tmp_arr = NULL;\n if (intent & F2PY_INTENT_INOUT) {\n\tARR_IS_NULL(1,\"intent(inout) array must be contiguous and\"\n\t\t \" with a proper type and size.\\n\")\n\t }\n if ((rank>1) && (! (intent & F2PY_INTENT_C))) {\n\tlazy_transpose(arr);\n\t_lazy_transpose_update_flags(arr);\n }\n/* if (PyArray_CanCastSafely(arr->descr->type_num,type_num)) { */\n/* \ttmp_arr = (PyArrayObject *)PyArray_CopyFromObject(obj,type_num,0,0); */\n/* \tARR_IS_NULL(arr==NULL,\"CopyFromObject failed: array.\\n\"); */\n/* } else */\n {\n\ttmp_arr = (PyArrayObject *)PyArray_SimpleNew(arr->nd,\n\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t type_num);\n\tARR_IS_NULL(tmp_arr==NULL,\"FromDims failed: array with unsafe cast.\\n\");\n\tif (copy_ND_array(arr,tmp_arr))\n\t ARR_IS_NULL(1,\"copy_ND_array failed: array with unsafe cast.\\n\");\n }\n if ((rank>1) && (! (intent & F2PY_INTENT_C))) {\n\tlazy_transpose(arr);\n\t_lazy_transpose_update_flags(arr);\n\tlazy_transpose(tmp_arr);\n\ttmp_arr->flags &= ~CONTIGUOUS;\n\ttmp_arr->flags |= FORTRAN;\n }\n if (intent & F2PY_INTENT_INPLACE) {\n\tif (swap_arrays(arr,tmp_arr))\n\t return NULL;\n\tPy_XDECREF(tmp_arr);\n\tif (intent & F2PY_INTENT_OUT)\n\t Py_INCREF(arr);\n } else {\n\tarr = tmp_arr;\n }\n } else {\n if ((intent & F2PY_INTENT_OUT)) {\n\tPy_INCREF(arr);\n }\n }\n return arr;\n }\n\n if ((obj==Py_None) && (intent & F2PY_OPTIONAL)) {\n PyArrayObject *arr = NULL;\n CHECK_DIMS_DEFINED(rank,dims,\"optional must have defined dimensions.\\n\"); \n arr = (PyArrayObject *)PyArray_SimpleNew(rank,dims,type_num);\n ARR_IS_NULL(arr==NULL,\"FromDims failed: optional.\\n\");\n memset(arr->data, 0, PyArray_NBYTES(arr));\n if (intent & F2PY_INTENT_OUT) {\n if ((!(intent & F2PY_INTENT_C)) && (rank>1)) {\n\ttranspose_strides(arr);\n\tarr->flags &= ~CONTIGUOUS;\n\tarr->flags |= FORTRAN;\n }\n/* Py_INCREF(arr); */\n }\n return arr;\n }\n\n if ((intent & F2PY_INTENT_INOUT) || (intent & F2PY_INTENT_INPLACE)) {\n ARR_IS_NULL(1,\"intent(inout)|intent(inplace) argument must be an array.\\n\");\n }\n\n {\n PyArrayObject *arr = (PyArrayObject *) \\\n PyArray_ContiguousFromObject(obj,type_num,0,0);\n ARR_IS_NULL(arr==NULL,\"ContiguousFromObject failed: not a sequence.\\n\");\n if (check_and_fix_dimensions(arr,rank,dims))\n return NULL; /*XXX: set exception */\n\n if ((rank>1) && (! (intent & F2PY_INTENT_C))) {\n PyArrayObject *tmp_arr = NULL;\n if (rank == 2) {\n\t tmp_arr = (PyArrayObject *) PyArray_CopyAndTranspose((PyObject *)arr);\n\t PyArray_UpdateFlags(tmp_arr, CONTIGUOUS | FORTRAN);\n }\n else {\n\t lazy_transpose(arr);\n\t arr->flags &= ~CONTIGUOUS;\n\t arr->flags |= FORTRAN;\n\t tmp_arr = (PyArrayObject *) PyArray_Copy(arr);\n }\n#ifdef F2PY_REPORT_ON_ARRAY_COPY\n f2py_report_on_array_copy(tmp_arr,\"PyArray_Copy\");\n#endif\n Py_DECREF(arr);\n arr = tmp_arr;\n ARR_IS_NULL(arr==NULL,\"Copy(Array) failed: intent(fortran)\\n\");\n lazy_transpose(arr);\n _lazy_transpose_update_flags(arr);\n }\n/* if (intent & F2PY_INTENT_OUT) */\n/* Py_INCREF(arr); */\n return arr;\n }\n\n}\n\n /*****************************************/\n /* Helper functions for array_from_pyobj */\n /*****************************************/\n\nextern\nint array_has_column_major_storage(const PyArrayObject *ap) {\n /* array_has_column_major_storage(a) is equivalent to\n transpose(a).iscontiguous() but more efficient.\n\n This function can be used in order to decide whether to use a\n Fortran or C version of a wrapped function. This is relevant, for\n example, in choosing a clapack or flapack function depending on\n the storage order of array arguments.\n */\n int sd;\n int i;\n sd = PyArray_ITEMSIZE(ap);\n for (i=0;ind;++i) {\n if (ap->dimensions[i] == 0) return 1;\n if (ap->strides[i] != sd) return 0;\n sd *= ap->dimensions[i];\n }\n return 1;\n}\n\nstatic\nint check_and_fix_dimensions(const PyArrayObject* arr,const int rank,intp *dims) {\n /*\n This function fills in blanks (that are -1\\'s) in dims list using\n the dimensions from arr. It also checks that non-blank dims will\n match with the corresponding values in arr dimensions.\n */\n const intp arr_size = (arr->nd)?PyArray_Size((PyObject *)arr):1;\n\n if (rank > arr->nd) { /* [1,2] -> [[1],[2]]; 1 -> [[1]] */\n intp new_size = 1;\n int free_axe = -1;\n int i;\n /* Fill dims where -1 or 0; check dimensions; calc new_size; */\n for(i=0;ind;++i) { \n if (dims[i] >= 0) {\n\tif (dims[i]!=arr->dimensions[i]) {\n\t fprintf(stderr,\"%d-th dimension must be fixed to %\" INTP_FMT\n\t\t \" but got %\" INTP_FMT \"\\n\",\n\t\t i,dims[i], arr->dimensions[i]);\n\t return 1;\n\t}\n\tif (!dims[i]) dims[i] = 1;\n } else {\n\tdims[i] = arr->dimensions[i] ? arr->dimensions[i] : 1;\n }\n new_size *= dims[i];\n }\n for(i=arr->nd;i1) {\n\tfprintf(stderr,\"%d-th dimension must be %\" INTP_FMT\n\t\t\" but got 0 (not defined).\\n\",\n\t\ti,dims[i]);\n\treturn 1;\n } else if (free_axe<0)\n\tfree_axe = i;\n else\n\tdims[i] = 1;\n if (free_axe>=0) {\n dims[free_axe] = arr_size/new_size;\n new_size *= dims[free_axe];\n }\n if (new_size != arr_size) {\n fprintf(stderr,\"confused: new_size=%\" INTP_FMT\n\t \", arr_size=%\" INTP_FMT \" (maybe too many free\"\n\t \" indices)\\n\", new_size,arr_size);\n return 1;\n }\n } else { /* [[1,2]] -> [[1],[2]] */\n int i,j;\n intp d;\n int effrank;\n intp size;\n for (i=0,effrank=0;ind;++i)\n if (arr->dimensions[i]>1) ++effrank;\n if (dims[rank-1]>=0)\n if (effrank>rank) {\n\tfprintf(stderr,\"too many axes: %d (effrank=%d), expected rank=%d\\n\",\n\t\tarr->nd,effrank,rank);\n\treturn 1;\n }\n for (i=0,j=0;ind && arr->dimensions[j]<2) ++j;\n if (j>=arr->nd) d = 1;\n else d = arr->dimensions[j++];\n if (dims[i]>=0) {\n\tif (d>1 && d!=dims[i]) {\n\t fprintf(stderr,\"%d-th dimension must be fixed to %\" INTP_FMT \n\t\t \" but got %\" INTP_FMT \" (real index=%d)\\n\",\n\t\t i,dims[i],d,j-1);\n\t return 1;\t \n\t}\n\tif (!dims[i]) dims[i] = 1;\n } else\n\tdims[i] = d;\n }\n for (i=rank;ind;++i) { /* [[1,2],[3,4]] -> [1,2,3,4] */\n while (jnd && arr->dimensions[j]<2) ++j;\n if (j>=arr->nd) d = 1;\n else d = arr->dimensions[j++];\n dims[rank-1] *= d;\n }\n for (i=0,size=1;ind);\n for (i=0;ind;++i) fprintf(stderr,\" %\" INTP_FMT,arr->dimensions[i]);\n fprintf(stderr,\" ]\\n\");\n return 1;\n }\n }\n return 0;\n}\n\n/* End of file: array_from_pyobj.c */\n\n/************************* copy_ND_array *******************************/\n\nextern\nint copy_ND_array(const PyArrayObject *in, PyArrayObject *out)\n{\n#ifdef F2PY_REPORT_ON_ARRAY_COPY\n f2py_report_on_array_copy(out, \"CopyInto\");\n#endif\n return PyArray_CopyInto(out, (PyArrayObject *)in);\n}\n\n#ifdef __cplusplus\n}\n#endif\n/************************* EOF fortranobject.c *******************************/\n", "source_code_before": "#define FORTRANOBJECT_C\n#include \"fortranobject.h\"\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n/*\n This file implements: FortranObject, array_from_pyobj, copy_ND_array,\n lazy_transpose, transpose_strides,\n\t\t and array_has_column_major_storage.\n\n Author: Pearu Peterson \n $Revision: 1.52 $\n $Date: 2005/07/11 07:44:20 $\n*/\n\n/************************* FortranObject *******************************/\n\ntypedef PyObject *(*fortranfunc)(PyObject *,PyObject *,PyObject *,void *);\n\nPyObject *\nPyFortranObject_New(FortranDataDef* defs, f2py_void_func init) {\n int i;\n PyFortranObject *fp = NULL;\n PyObject *v = NULL;\n if (init!=NULL) /* Initialize F90 module objects */\n (*(init))();\n if ((fp = PyObject_New(PyFortranObject, &PyFortran_Type))==NULL) return NULL;\n if ((fp->dict = PyDict_New())==NULL) return NULL;\n fp->len = 0;\n while (defs[fp->len].name != NULL) fp->len++;\n if (fp->len == 0) goto fail;\n fp->defs = defs;\n for (i=0;ilen;i++)\n if (fp->defs[i].rank == -1) { /* Is Fortran routine */\n v = PyFortranObject_NewAsAttr(&(fp->defs[i]));\n if (v==NULL) return NULL;\n PyDict_SetItemString(fp->dict,fp->defs[i].name,v);\n } else\n if ((fp->defs[i].data)!=NULL) { /* Is Fortran variable or array (not allocatable) */\n\tv = PyArray_New(&PyArray_Type, fp->defs[i].rank, fp->defs[i].dims.d,\n\t\t\tfp->defs[i].type, NULL, fp->defs[i].data, 0, FARRAY_FLAGS,\n\t\t\tNULL);\n\tif (v==NULL) return NULL;\n\tPyDict_SetItemString(fp->dict,fp->defs[i].name,v);\n }\n Py_XDECREF(v);\n return (PyObject *)fp;\n fail:\n Py_XDECREF(v);\n return NULL;\n}\n\nPyObject *\nPyFortranObject_NewAsAttr(FortranDataDef* defs) { /* used for calling F90 module routines */\n PyFortranObject *fp = NULL;\n fp = PyObject_New(PyFortranObject, &PyFortran_Type);\n if (fp == NULL) return NULL;\n if ((fp->dict = PyDict_New())==NULL) return NULL;\n fp->len = 1;\n fp->defs = defs;\n return (PyObject *)fp;\n}\n\n/* Fortran methods */\n\nstatic void\nfortran_dealloc(PyFortranObject *fp) {\n Py_XDECREF(fp->dict);\n PyMem_Del(fp);\n}\n\n\nstatic PyMethodDef fortran_methods[] = {\n\t{NULL,\t\tNULL}\t\t/* sentinel */\n};\n\n\nstatic PyObject *\nfortran_doc (FortranDataDef def) {\n char *p;\n PyObject *s = NULL;\n int i;\n unsigned size=100;\n if (def.doc!=NULL)\n size += strlen(def.doc);\n p = (char*)malloc (size);\n if (sprintf(p,\"%s - \",def.name)==0) goto fail;\n if (def.rank==-1) {\n if (def.doc==NULL) {\n if (sprintf(p,\"%sno docs available\",p)==0)\n\tgoto fail;\n } else {\n if (sprintf(p,\"%s%s\",p,def.doc)==0)\n\tgoto fail;\n }\n } else {\n PyArray_Descr *d = PyArray_DescrFromType(def.type);\n if (sprintf(p,\"%s'%c'-\",p,d->type)==0) goto fail;\n if (def.data==NULL) {\n if (sprintf(p,\"%sarray(%\" INTP_FMT,p,def.dims.d[0])==0) goto fail;\n for(i=1;i0) {\n\tif (sprintf(p,\"%sarray(%\"INTP_FMT,p,def.dims.d[0])==0) goto fail;\n\tfor(i=1;isize) {\n fprintf(stderr,\"fortranobject.c:fortran_doc:len(p)=%zd>%d(size): too long doc string required, increase size\\n\",strlen(p),size);\n goto fail;\n }\n s = PyString_FromString(p);\n fail:\n free(p);\n return s;\n}\n\nstatic FortranDataDef *save_def; /* save pointer of an allocatable array */\nstatic void set_data(char *d,intp *f) { /* callback from Fortran */\n if (*f) /* In fortran f=allocated(d) */\n save_def->data = d;\n else\n save_def->data = NULL;\n /* printf(\"set_data: d=%p,f=%d\\n\",d,*f); */\n}\n\nstatic PyObject *\nfortran_getattr(PyFortranObject *fp, char *name) {\n int i,j,k,flag;\n if (fp->dict != NULL) {\n PyObject *v = PyDict_GetItemString(fp->dict, name);\n if (v != NULL) {\n Py_INCREF(v);\n return v;\n }\n }\n for (i=0,j=1;ilen && (j=strcmp(name,fp->defs[i].name));i++);\n if (j==0)\n if (fp->defs[i].rank!=-1) { /* F90 allocatable array */ \n if (fp->defs[i].func==NULL) return NULL;\n for(k=0;kdefs[i].rank;++k) \n\tfp->defs[i].dims.d[k]=-1;\n save_def = &fp->defs[i];\n (*(fp->defs[i].func))(&fp->defs[i].rank,fp->defs[i].dims.d,set_data,&flag);\n if (flag==2)\n\tk = fp->defs[i].rank + 1;\n else\n\tk = fp->defs[i].rank;\n if (fp->defs[i].data !=NULL) { /* array is allocated */\n\tPyObject *v = PyArray_New(&PyArray_Type, k, fp->defs[i].dims.d,\n\t\t\tfp->defs[i].type, NULL, fp->defs[i].data, 0, FARRAY_FLAGS,\n\t\t\tNULL);\n\tif (v==NULL) return NULL;\n\t/* Py_INCREF(v); */\n\treturn v;\n } else { /* array is not allocated */\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n }\n }\n if (strcmp(name,\"__dict__\")==0) {\n Py_INCREF(fp->dict);\n return fp->dict;\n }\n if (strcmp(name,\"__doc__\")==0) {\n PyObject *s = PyString_FromString(\"\");\n for (i=0;ilen;i++)\n PyString_ConcatAndDel(&s,fortran_doc(fp->defs[i]));\n if (PyDict_SetItemString(fp->dict, name, s))\n return NULL;\n return s;\n }\n if ((strcmp(name,\"_cpointer\")==0) && (fp->len==1)) {\n PyObject *cobj = PyCObject_FromVoidPtr((void *)(fp->defs[0].data),NULL);\n if (PyDict_SetItemString(fp->dict, name, cobj))\n return NULL;\n return cobj;\n }\n return Py_FindMethod(fortran_methods, (PyObject *)fp, name);\n}\n\nstatic int\nfortran_setattr(PyFortranObject *fp, char *name, PyObject *v) {\n int i,j,flag;\n PyArrayObject *arr = NULL;\n for (i=0,j=1;ilen && (j=strcmp(name,fp->defs[i].name));i++);\n if (j==0) {\n if (fp->defs[i].rank==-1) {\n PyErr_SetString(PyExc_AttributeError,\"over-writing fortran routine\");\n return -1;\n }\n if (fp->defs[i].func!=NULL) { /* is allocatable array */\n intp dims[F2PY_MAX_DIMS];\n int k;\n save_def = &fp->defs[i];\n if (v!=Py_None) { /* set new value (reallocate if needed --\n\t\t\t see f2py generated code for more\n\t\t\t details ) */\n\tfor(k=0;kdefs[i].rank;k++) dims[k]=-1;\n\tif ((arr = array_from_pyobj(fp->defs[i].type,dims,fp->defs[i].rank,F2PY_INTENT_IN,v))==NULL)\n\t return -1;\n\t(*(fp->defs[i].func))(&fp->defs[i].rank,arr->dimensions,set_data,&flag);\n } else { /* deallocate */\n\tfor(k=0;kdefs[i].rank;k++) dims[k]=0;\n\t(*(fp->defs[i].func))(&fp->defs[i].rank,dims,set_data,&flag);\n\tfor(k=0;kdefs[i].rank;k++) dims[k]=-1;\n }\n memcpy(fp->defs[i].dims.d,dims,fp->defs[i].rank*sizeof(intp));\n } else { /* not allocatable array */\n if ((arr = array_from_pyobj(fp->defs[i].type,fp->defs[i].dims.d,fp->defs[i].rank,F2PY_INTENT_IN,v))==NULL)\n\treturn -1; \n }\n if (fp->defs[i].data!=NULL) { /* copy Python object to Fortran array */\n intp s = PyArray_MultiplyList(fp->defs[i].dims.d,arr->nd);\n if (s==-1)\n\ts = PyArray_MultiplyList(arr->dimensions,arr->nd);\n if (s<0 ||\n\t (memcpy(fp->defs[i].data,arr->data,s*PyArray_ITEMSIZE(arr)))==NULL) {\n\tif ((PyObject*)arr!=v) {\n\t Py_DECREF(arr);\n\t}\n\treturn -1;\n }\n if ((PyObject*)arr!=v) {\n Py_DECREF(arr);\n }\n } else return (fp->defs[i].func==NULL?-1:0);\n return 0; /* succesful */\n }\n if (fp->dict == NULL) {\n fp->dict = PyDict_New();\n if (fp->dict == NULL)\n return -1;\n }\n if (v == NULL) {\n int rv = PyDict_DelItemString(fp->dict, name);\n if (rv < 0)\n PyErr_SetString(PyExc_AttributeError,\"delete non-existing fortran attribute\");\n return rv;\n }\n else\n return PyDict_SetItemString(fp->dict, name, v);\n}\n\nstatic PyObject*\nfortran_call(PyFortranObject *fp, PyObject *arg, PyObject *kw) {\n int i = 0;\n /* printf(\"fortran call\n name=%s,func=%p,data=%p,%p\\n\",fp->defs[i].name,\n fp->defs[i].func,fp->defs[i].data,&fp->defs[i].data); */\n if (fp->defs[i].rank==-1) {/* is Fortran routine */\n if ((fp->defs[i].func==NULL)) {\n PyErr_Format(PyExc_RuntimeError, \"no function to call\");\n return NULL;\n }\n else if (fp->defs[i].data==NULL)\n /* dummy routine */\n return (*((fortranfunc)(fp->defs[i].func)))((PyObject *)fp,arg,kw,NULL);\n else\n return (*((fortranfunc)(fp->defs[i].func)))((PyObject *)fp,arg,kw,\n\t\t\t\t\t\t (void *)fp->defs[i].data);\n }\n PyErr_Format(PyExc_TypeError, \"this fortran object is not callable\");\n return NULL;\n}\n\n\nPyTypeObject PyFortran_Type = {\n PyObject_HEAD_INIT(0)\n 0,\t\t\t/*ob_size*/\n \"fortran\",\t\t\t/*tp_name*/\n sizeof(PyFortranObject),\t/*tp_basicsize*/\n 0,\t\t\t/*tp_itemsize*/\n /* methods */\n (destructor)fortran_dealloc, /*tp_dealloc*/\n 0,\t\t\t/*tp_print*/\n (getattrfunc)fortran_getattr, /*tp_getattr*/\n (setattrfunc)fortran_setattr, /*tp_setattr*/\n 0,\t\t\t/*tp_compare*/\n 0,\t\t\t/*tp_repr*/\n 0,\t\t\t/*tp_as_number*/\n 0,\t\t\t/*tp_as_sequence*/\n 0,\t\t\t/*tp_as_mapping*/\n 0,\t\t\t/*tp_hash*/\n (ternaryfunc)fortran_call, /*tp_call*/\n};\n\n/************************* f2py_report_atexit *******************************/\n\n#ifdef F2PY_REPORT_ATEXIT\nstatic int passed_time = 0;\nstatic int passed_counter = 0;\nstatic int passed_call_time = 0;\nstatic struct timeb start_time;\nstatic struct timeb stop_time;\nstatic struct timeb start_call_time;\nstatic struct timeb stop_call_time;\nstatic int cb_passed_time = 0;\nstatic int cb_passed_counter = 0;\nstatic int cb_passed_call_time = 0;\nstatic struct timeb cb_start_time;\nstatic struct timeb cb_stop_time;\nstatic struct timeb cb_start_call_time;\nstatic struct timeb cb_stop_call_time;\n\nextern void f2py_start_clock(void) { ftime(&start_time); }\nextern\nvoid f2py_start_call_clock(void) {\n f2py_stop_clock();\n ftime(&start_call_time);\n}\nextern\nvoid f2py_stop_clock(void) {\n ftime(&stop_time);\n passed_time += 1000*(stop_time.time - start_time.time);\n passed_time += stop_time.millitm - start_time.millitm;\n}\nextern\nvoid f2py_stop_call_clock(void) {\n ftime(&stop_call_time);\n passed_call_time += 1000*(stop_call_time.time - start_call_time.time);\n passed_call_time += stop_call_time.millitm - start_call_time.millitm;\n passed_counter += 1;\n f2py_start_clock();\n}\n\nextern void f2py_cb_start_clock(void) { ftime(&cb_start_time); }\nextern\nvoid f2py_cb_start_call_clock(void) {\n f2py_cb_stop_clock();\n ftime(&cb_start_call_time);\n}\nextern\nvoid f2py_cb_stop_clock(void) {\n ftime(&cb_stop_time);\n cb_passed_time += 1000*(cb_stop_time.time - cb_start_time.time);\n cb_passed_time += cb_stop_time.millitm - cb_start_time.millitm;\n}\nextern\nvoid f2py_cb_stop_call_clock(void) {\n ftime(&cb_stop_call_time);\n cb_passed_call_time += 1000*(cb_stop_call_time.time - cb_start_call_time.time);\n cb_passed_call_time += cb_stop_call_time.millitm - cb_start_call_time.millitm;\n cb_passed_counter += 1;\n f2py_cb_start_clock();\n}\n\nstatic int f2py_report_on_exit_been_here = 0;\nextern\nvoid f2py_report_on_exit(int exit_flag,void *name) {\n if (f2py_report_on_exit_been_here) {\n fprintf(stderr,\" %s\\n\",(char*)name);\n return;\n }\n f2py_report_on_exit_been_here = 1;\n fprintf(stderr,\" /-----------------------\\\\\\n\");\n fprintf(stderr,\" < F2PY performance report >\\n\");\n fprintf(stderr,\" \\\\-----------------------/\\n\");\n fprintf(stderr,\"Overall time spent in ...\\n\");\n fprintf(stderr,\"(a) wrapped (Fortran/C) functions : %8d msec\\n\",\n\t passed_call_time);\n fprintf(stderr,\"(b) f2py interface, %6d calls : %8d msec\\n\",\n\t passed_counter,passed_time);\n fprintf(stderr,\"(c) call-back (Python) functions : %8d msec\\n\",\n\t cb_passed_call_time);\n fprintf(stderr,\"(d) f2py call-back interface, %6d calls : %8d msec\\n\",\n\t cb_passed_counter,cb_passed_time);\n \n fprintf(stderr,\"(e) wrapped (Fortran/C) functions (acctual) : %8d msec\\n\\n\",\n\t passed_call_time-cb_passed_call_time-cb_passed_time);\n fprintf(stderr,\"Use -DF2PY_REPORT_ATEXIT_DISABLE to disable this message.\\n\");\n fprintf(stderr,\"Exit status: %d\\n\",exit_flag);\n fprintf(stderr,\"Modules : %s\\n\",(char*)name);\n}\n#endif\n\n/********************** report on array copy ****************************/\n\n#ifdef F2PY_REPORT_ON_ARRAY_COPY\nstatic void f2py_report_on_array_copy(PyArrayObject* arr, char* func_name) {\n const long arr_size = PyArray_Size((PyObject *)arr);\n if (arr_size>F2PY_REPORT_ON_ARRAY_COPY) {\n fprintf(stderr,\"copied an array using %s: size=%ld, elsize=%d\\n\", \n\t func_name, arr_size, PyArray_ITEMSIZE(arr));\n }\n}\n#endif\n\n/************************* lazy_transpose *******************************/\n\nextern\nvoid lazy_transpose(PyArrayObject* arr) {\n /*\n Changes the order of array strides and dimensions. This\n corresponds to the lazy transpose of a Numeric array in-situ.\n Note that this function is assumed to be used even times for a\n given array. Otherwise, the caller should set flags &= ~CONTIGUOUS.\n */\n int rank, i;\n intp s,j; \n rank = arr->nd; \n if (rank < 2) return;\n\n for(i=0,j=rank-1;istrides[i];\n arr->strides[i] = arr->strides[j];\n arr->strides[j] = s;\n s = arr->dimensions[i];\n arr->dimensions[i] = arr->dimensions[j];\n arr->dimensions[j] = s;\n }\n}\n\nextern\nvoid transpose_strides(PyArrayObject* arr) {\n int rank, i;\n intp j;\n rank = arr->nd; \n if (rank < 2) return;\n j = arr->strides[rank-1];\n for(i=0;istrides[i] = j;\n j *= arr->dimensions[i];\n }\n}\n\n/************************* array_from_obj *******************************/\n\n/* \n * File: array_from_pyobj.c \n *\n * Description:\n * ------------ \n * Provides array_from_pyobj function that returns a contigious array\n * object with the given dimensions and required storage order, either\n * in row-major (C) or column-major (Fortran) order. The function\n * array_from_pyobj is very flexible about its Python object argument\n * that can be any number, list, tuple, or array.\n * \n * array_from_pyobj is used in f2py generated Python extension\n * modules.\n *\n * Author: Pearu Peterson \n * Created: 13-16 January 2002\n * $Id: fortranobject.c,v 1.52 2005/07/11 07:44:20 pearu Exp $\n */\n\n\n#define ARR_IS_NULL(arr_is_NULL,mess) \\\nif (arr_is_NULL) { \\\n fprintf(stderr,\"array_from_pyobj:\" mess); \\\n return NULL; \\\n}\n\n#define CHECK_DIMS_DEFINED(rank,dims,mess) \\\nif (count_nonpos(rank,dims)) { int i;\\\n fprintf(stderr,\"array_from_pyobj:\" mess); \\\n fprintf(stderr,\"rank=%d dimensions=[ \",rank); \\\n for(i=0;ielsize) == PyArray_ITEMSIZE(arr))\n\nstatic int \ncount_nonpos(const int rank,\n\t const intp *dims) {\n int i=0,r=0;\n while (ind;\n intp size = PyArray_Size((PyObject *)arr);\n int i;\n printf(\"\\trank = %d, flags = %d, size = %\" INTP_FMT \"\\n\",\n\t rank,arr->flags,size);\n printf(\"\\tstrides = [\");\n for(i=0;istrides[i]);\n }\n printf(\"]\\n\\t dimensions = [\");\n for(i=0;idimensions[i]);\n }\n printf(\"]\\n\");\n}\n#endif\n\n#define SWAPTYPE(a,b,t) {t c; c = (a); (a) = (b); (b) = c; }\n\nstatic int swap_arrays(PyArrayObject* arr1, PyArrayObject* arr2) {\n SWAPTYPE(arr1->data,arr2->data,char*);\n SWAPTYPE(arr1->nd,arr2->nd,int);\n SWAPTYPE(arr1->dimensions,arr2->dimensions,intp*);\n SWAPTYPE(arr1->strides,arr2->strides,intp*);\n SWAPTYPE(arr1->base,arr2->base,PyObject*);\n SWAPTYPE(arr1->descr,arr2->descr,PyArray_Descr*);\n SWAPTYPE(arr1->flags,arr2->flags,int);\n SWAPTYPE(arr1->itemsize, arr2->itemsize, int);\n /* SWAPTYPE(arr1->weakreflist,arr2->weakreflist,PyObject*); */\n return 0;\n}\n\n\t/* useful after a lazy-transpose to update the flags\n\t quickly \n\t*/\n\n#define _lazy_transpose_update_flags(obj) {\t\t \\\n\t\tif (PyArray_ISCONTIGUOUS(obj)) {\t \\\n\t\t\tPyArray_FLAGS(obj) &= ~CONTIGUOUS; \\\n\t\t\tPyArray_FLAGS(obj) |= FORTRAN; \\\n\t\t}\t\t\t\t\t \\\n\t\telse if PyArray_CHKFLAGS(obj, FORTRAN) { \\\n\t\t\tPyArray_FLAGS(obj) &= ~FORTRAN; \\\n\t\t\tPyArray_FLAGS(obj) |= CONTIGUOUS; \\\n\t\t}\t\t\t\t\t \\\n\t}\n\nextern\nPyArrayObject* array_from_pyobj(const int type_num,\n\t\t\t\tintp *dims,\n\t\t\t\tconst int rank,\n\t\t\t\tconst int intent,\n\t\t\t\tPyObject *obj) {\n /* Note about reference counting\n -----------------------------\n If the caller returns the array to Python, it must be done with\n Py_BuildValue(\"N\",arr).\n Otherwise, if obj!=arr then the caller must call Py_DECREF(arr).\n */\n if (intent & F2PY_INTENT_CACHE) {\n /* Don't expect correct storage order or anything reasonable when\n returning intent(cache) array. */ \n if ((intent & F2PY_INTENT_HIDE)\n\t|| (obj==Py_None)) {\n PyArrayObject *arr = NULL;\n CHECK_DIMS_DEFINED(rank,dims,\"optional,intent(cache) must\"\n\t\t\t \" have defined dimensions.\\n\");\n arr = (PyArrayObject *)PyArray_SimpleNew(rank,dims,type_num);\n ARR_IS_NULL(arr==NULL,\"FromDims failed: optional,intent(cache)\\n\");\n memset(arr->data, 0, PyArray_NBYTES(arr));\n/* if (intent & F2PY_INTENT_OUT) */\n/* \tPy_INCREF(arr); */\n return arr;\n }\n\n if (PyArray_Check(obj) \n\t&& PyArray_ISONESEGMENT(obj)\n\t&& HAS_PROPER_ELSIZE((PyArrayObject *)obj,type_num)\n\t) {\n if (check_and_fix_dimensions((PyArrayObject *)obj,rank,dims))\n\treturn NULL; /*XXX: set exception */\n {\n\tPyArrayObject *obj2;\n\tif (intent & F2PY_INTENT_OUT)\n\t Py_INCREF(obj);\n\tobj2 = (PyArrayObject *) obj;\n\treturn obj2;\n }\n }\n ARR_IS_NULL(1,\"intent(cache) must be contiguous array with a proper elsize.\\n\");\n }\n\n if (intent & F2PY_INTENT_HIDE) {\n PyArrayObject *arr = NULL;\n CHECK_DIMS_DEFINED(rank,dims,\"intent(hide) must have defined dimensions.\\n\");\n arr = (PyArrayObject *)PyArray_SimpleNew(rank, dims, type_num);\n ARR_IS_NULL(arr==NULL,\"FromDims failed: intent(hide)\\n\");\n memset(arr->data, 0, PyArray_NBYTES(arr));\n if (intent & F2PY_INTENT_OUT) {\n if ((!(intent & F2PY_INTENT_C)) && (rank>1)) {\n\ttranspose_strides(arr);\n\tarr->flags &= ~CONTIGUOUS;\n\tarr->flags |= FORTRAN;\n }\n/* Py_INCREF(arr); */\n }\n return arr;\n }\n\n if (PyArray_Check(obj)) { /* here we have always intent(in) or\n\t\t\t intent(inout) or intent(inplace) */\n PyArrayObject *arr;\n int is_cont;\n\n arr = (PyArrayObject *)obj;\n is_cont = (intent & F2PY_INTENT_C) ? \n (ISCONTIGUOUS(arr)) : (2*array_has_column_major_storage(arr));\n if (check_and_fix_dimensions(arr,rank,dims))\n return NULL; /*XXX: set exception */\n if ((intent & F2PY_INTENT_COPY)\n\t|| (! (is_cont\n\t && HAS_PROPER_ELSIZE(arr,type_num)\n\t && PyArray_CanCastSafely(arr->descr->type_num,type_num)\n\t /* Make PyArray_CanCastSafely safer for 64-bit machines: */\n\t /* && (arr->descr->type_num==PyArray_LONG?type_num!=PyArray_DOUBLE:1)*/\n\t ))) {\n PyArrayObject *tmp_arr = NULL;\n if (intent & F2PY_INTENT_INOUT) {\n\tARR_IS_NULL(1,\"intent(inout) array must be contiguous and\"\n\t\t \" with a proper type and size.\\n\")\n\t }\n if ((rank>1) && (! (intent & F2PY_INTENT_C))) {\n\tlazy_transpose(arr);\n\t_lazy_transpose_update_flags(arr);\n }\n/* if (PyArray_CanCastSafely(arr->descr->type_num,type_num)) { */\n/* \ttmp_arr = (PyArrayObject *)PyArray_CopyFromObject(obj,type_num,0,0); */\n/* \tARR_IS_NULL(arr==NULL,\"CopyFromObject failed: array.\\n\"); */\n/* } else */\n {\n\ttmp_arr = (PyArrayObject *)PyArray_SimpleNew(arr->nd,\n\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t type_num);\n\tARR_IS_NULL(tmp_arr==NULL,\"FromDims failed: array with unsafe cast.\\n\");\n\tif (copy_ND_array(arr,tmp_arr))\n\t ARR_IS_NULL(1,\"copy_ND_array failed: array with unsafe cast.\\n\");\n }\n if ((rank>1) && (! (intent & F2PY_INTENT_C))) {\n\tlazy_transpose(arr);\n\t_lazy_transpose_update_flags(arr);\n\tlazy_transpose(tmp_arr);\n\ttmp_arr->flags &= ~CONTIGUOUS;\n\ttmp_arr->flags |= FORTRAN;\n }\n if (intent & F2PY_INTENT_INPLACE) {\n\tif (swap_arrays(arr,tmp_arr))\n\t return NULL;\n\tPy_XDECREF(tmp_arr);\n\tif (intent & F2PY_INTENT_OUT)\n\t Py_INCREF(arr);\n } else {\n\tarr = tmp_arr;\n }\n } else {\n if ((intent & F2PY_INTENT_OUT)) {\n\tPy_INCREF(arr);\n }\n }\n return arr;\n }\n\n if ((obj==Py_None) && (intent & F2PY_OPTIONAL)) {\n PyArrayObject *arr = NULL;\n CHECK_DIMS_DEFINED(rank,dims,\"optional must have defined dimensions.\\n\"); \n arr = (PyArrayObject *)PyArray_SimpleNew(rank,dims,type_num);\n ARR_IS_NULL(arr==NULL,\"FromDims failed: optional.\\n\");\n memset(arr->data, 0, PyArray_NBYTES(arr));\n if (intent & F2PY_INTENT_OUT) {\n if ((!(intent & F2PY_INTENT_C)) && (rank>1)) {\n\ttranspose_strides(arr);\n\tarr->flags &= ~CONTIGUOUS;\n\tarr->flags |= FORTRAN;\n }\n/* Py_INCREF(arr); */\n }\n return arr;\n }\n\n if ((intent & F2PY_INTENT_INOUT) || (intent & F2PY_INTENT_INPLACE)) {\n ARR_IS_NULL(1,\"intent(inout)|intent(inplace) argument must be an array.\\n\");\n }\n\n {\n PyArrayObject *arr = (PyArrayObject *) \\\n PyArray_ContiguousFromObject(obj,type_num,0,0);\n ARR_IS_NULL(arr==NULL,\"ContiguousFromObject failed: not a sequence.\\n\");\n if (check_and_fix_dimensions(arr,rank,dims))\n return NULL; /*XXX: set exception */\n\n if ((rank>1) && (! (intent & F2PY_INTENT_C))) {\n PyArrayObject *tmp_arr = NULL;\n if (rank == 2) {\n\t tmp_arr = (PyArrayObject *) PyArray_CopyAndTranspose((PyObject *)arr);\n\t PyArray_UpdateFlags(tmp_arr, CONTIGUOUS | FORTRAN);\n }\n else {\n\t lazy_transpose(arr);\n\t arr->flags &= ~CONTIGUOUS;\n\t arr->flags |= FORTRAN;\n\t tmp_arr = (PyArrayObject *) PyArray_Copy(arr);\n }\n#ifdef F2PY_REPORT_ON_ARRAY_COPY\n f2py_report_on_array_copy(tmp_arr,\"PyArray_Copy\");\n#endif\n Py_DECREF(arr);\n arr = tmp_arr;\n ARR_IS_NULL(arr==NULL,\"Copy(Array) failed: intent(fortran)\\n\");\n lazy_transpose(arr);\n _lazy_transpose_update_flags(arr);\n }\n/* if (intent & F2PY_INTENT_OUT) */\n/* Py_INCREF(arr); */\n return arr;\n }\n\n}\n\n /*****************************************/\n /* Helper functions for array_from_pyobj */\n /*****************************************/\n\nextern\nint array_has_column_major_storage(const PyArrayObject *ap) {\n /* array_has_column_major_storage(a) is equivalent to\n transpose(a).iscontiguous() but more efficient.\n\n This function can be used in order to decide whether to use a\n Fortran or C version of a wrapped function. This is relevant, for\n example, in choosing a clapack or flapack function depending on\n the storage order of array arguments.\n */\n int sd;\n int i;\n sd = PyArray_ITEMSIZE(ap);\n for (i=0;ind;++i) {\n if (ap->dimensions[i] == 0) return 1;\n if (ap->strides[i] != sd) return 0;\n sd *= ap->dimensions[i];\n }\n return 1;\n}\n\nstatic\nint check_and_fix_dimensions(const PyArrayObject* arr,const int rank,intp *dims) {\n /*\n This function fills in blanks (that are -1\\'s) in dims list using\n the dimensions from arr. It also checks that non-blank dims will\n match with the corresponding values in arr dimensions.\n */\n const intp arr_size = (arr->nd)?PyArray_Size((PyObject *)arr):1;\n\n if (rank > arr->nd) { /* [1,2] -> [[1],[2]]; 1 -> [[1]] */\n intp new_size = 1;\n int free_axe = -1;\n int i;\n /* Fill dims where -1 or 0; check dimensions; calc new_size; */\n for(i=0;ind;++i) { \n if (dims[i] >= 0) {\n\tif (dims[i]!=arr->dimensions[i]) {\n\t fprintf(stderr,\"%d-th dimension must be fixed to %\" INTP_FMT\n\t\t \" but got %\" INTP_FMT \"\\n\",\n\t\t i,dims[i], arr->dimensions[i]);\n\t return 1;\n\t}\n\tif (!dims[i]) dims[i] = 1;\n } else {\n\tdims[i] = arr->dimensions[i] ? arr->dimensions[i] : 1;\n }\n new_size *= dims[i];\n }\n for(i=arr->nd;i1) {\n\tfprintf(stderr,\"%d-th dimension must be %\" INTP_FMT\n\t\t\" but got 0 (not defined).\\n\",\n\t\ti,dims[i]);\n\treturn 1;\n } else if (free_axe<0)\n\tfree_axe = i;\n else\n\tdims[i] = 1;\n if (free_axe>=0) {\n dims[free_axe] = arr_size/new_size;\n new_size *= dims[free_axe];\n }\n if (new_size != arr_size) {\n fprintf(stderr,\"confused: new_size=%\" INTP_FMT\n\t \", arr_size=%\" INTP_FMT \" (maybe too many free\"\n\t \" indices)\\n\", new_size,arr_size);\n return 1;\n }\n } else { /* [[1,2]] -> [[1],[2]] */\n int i,j;\n intp d;\n int effrank;\n intp size;\n for (i=0,effrank=0;ind;++i)\n if (arr->dimensions[i]>1) ++effrank;\n if (dims[rank-1]>=0)\n if (effrank>rank) {\n\tfprintf(stderr,\"too many axes: %d (effrank=%d), expected rank=%d\\n\",\n\t\tarr->nd,effrank,rank);\n\treturn 1;\n }\n for (i=0,j=0;ind && arr->dimensions[j]<2) ++j;\n if (j>=arr->nd) d = 1;\n else d = arr->dimensions[j++];\n if (dims[i]>=0) {\n\tif (d>1 && d!=dims[i]) {\n\t fprintf(stderr,\"%d-th dimension must be fixed to %\" INTP_FMT \n\t\t \" but got %\" INTP_FMT \" (real index=%d)\\n\",\n\t\t i,dims[i],d,j-1);\n\t return 1;\t \n\t}\n\tif (!dims[i]) dims[i] = 1;\n } else\n\tdims[i] = d;\n }\n for (i=rank;ind;++i) { /* [[1,2],[3,4]] -> [1,2,3,4] */\n while (jnd && arr->dimensions[j]<2) ++j;\n if (j>=arr->nd) d = 1;\n else d = arr->dimensions[j++];\n dims[rank-1] *= d;\n }\n for (i=0,size=1;ind);\n for (i=0;ind;++i) fprintf(stderr,\" %\" INTP_FMT,arr->dimensions[i]);\n fprintf(stderr,\" ]\\n\");\n return 1;\n }\n }\n return 0;\n}\n\n/* End of file: array_from_pyobj.c */\n\n/************************* copy_ND_array *******************************/\n\nextern\nint copy_ND_array(const PyArrayObject *in, PyArrayObject *out)\n{\n#ifdef F2PY_REPORT_ON_ARRAY_COPY\n f2py_report_on_array_copy(out, \"CopyInto\");\n#endif\n return PyArray_CopyInto(out, (PyArrayObject *)in);\n}\n\n#ifdef __cplusplus\n}\n#endif\n/************************* EOF fortranobject.c *******************************/\n", "methods": [ { "name": "PyFortranObject_New", "long_name": "PyFortranObject_New( FortranDataDef * defs , f2py_void_func init)", "filename": "fortranobject.c", "nloc": 31, "complexity": 11, "token_count": 312, "parameters": [ "defs", "init" ], "start_line": 22, "end_line": 52, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 1 }, { "name": "PyFortranObject_NewAsAttr", "long_name": "PyFortranObject_NewAsAttr( FortranDataDef * defs)", "filename": "fortranobject.c", "nloc": 9, "complexity": 3, "token_count": 69, "parameters": [ "defs" ], "start_line": 55, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "fortran_dealloc", "long_name": "fortran_dealloc( PyFortranObject * fp)", "filename": "fortranobject.c", "nloc": 4, "complexity": 1, "token_count": 20, "parameters": [ "fp" ], "start_line": 68, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "fortran_doc", "long_name": "fortran_doc( FortranDataDef def)", "filename": "fortranobject.c", "nloc": 46, "complexity": 21, "token_count": 434, "parameters": [ "def" ], "start_line": 80, "end_line": 125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 46, "top_nesting_level": 1 }, { "name": "set_data", "long_name": "set_data( char * d , intp * f)", "filename": "fortranobject.c", "nloc": 6, "complexity": 2, "token_count": 30, "parameters": [ "d", "f" ], "start_line": 128, "end_line": 134, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "fortran_getattr", "long_name": "fortran_getattr( PyFortranObject * fp , char * name)", "filename": "fortranobject.c", "nloc": 52, "complexity": 18, "token_count": 519, "parameters": [ "fp", "name" ], "start_line": 137, "end_line": 189, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "top_nesting_level": 1 }, { "name": "fortran_setattr", "long_name": "fortran_setattr( PyFortranObject * fp , char * name , PyObject * v)", "filename": "fortranobject.c", "nloc": 59, "complexity": 22, "token_count": 647, "parameters": [ "fp", "name", "v" ], "start_line": 192, "end_line": 252, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 61, "top_nesting_level": 1 }, { "name": "fortran_call", "long_name": "fortran_call( PyFortranObject * fp , PyObject * arg , PyObject * kw)", "filename": "fortranobject.c", "nloc": 16, "complexity": 4, "token_count": 166, "parameters": [ "fp", "arg", "kw" ], "start_line": 255, "end_line": 274, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "f2py_start_clock", "long_name": "f2py_start_clock()", "filename": "fortranobject.c", "nloc": 1, "complexity": 1, "token_count": 12, "parameters": [], "start_line": 315, "end_line": 315, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "f2py_start_call_clock", "long_name": "f2py_start_call_clock()", "filename": "fortranobject.c", "nloc": 4, "complexity": 1, "token_count": 16, "parameters": [], "start_line": 317, "end_line": 320, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "f2py_stop_clock", "long_name": "f2py_stop_clock()", "filename": "fortranobject.c", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [], "start_line": 322, "end_line": 326, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "f2py_stop_call_clock", "long_name": "f2py_stop_call_clock()", "filename": "fortranobject.c", "nloc": 7, "complexity": 1, "token_count": 44, "parameters": [], "start_line": 328, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "f2py_cb_start_clock", "long_name": "f2py_cb_start_clock()", "filename": "fortranobject.c", "nloc": 1, "complexity": 1, "token_count": 12, "parameters": [], "start_line": 336, "end_line": 336, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "f2py_cb_start_call_clock", "long_name": "f2py_cb_start_call_clock()", "filename": "fortranobject.c", "nloc": 4, "complexity": 1, "token_count": 16, "parameters": [], "start_line": 338, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "f2py_cb_stop_clock", "long_name": "f2py_cb_stop_clock()", "filename": "fortranobject.c", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [], "start_line": 343, "end_line": 347, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "f2py_cb_stop_call_clock", "long_name": "f2py_cb_stop_call_clock()", "filename": "fortranobject.c", "nloc": 7, "complexity": 1, "token_count": 44, "parameters": [], "start_line": 349, "end_line": 355, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "f2py_report_on_exit", "long_name": "f2py_report_on_exit( int exit_flag , * name)", "filename": "fortranobject.c", "nloc": 24, "complexity": 2, "token_count": 146, "parameters": [ "exit_flag", "name" ], "start_line": 359, "end_line": 383, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "f2py_report_on_array_copy", "long_name": "f2py_report_on_array_copy( PyArrayObject * arr , char * func_name)", "filename": "fortranobject.c", "nloc": 7, "complexity": 2, "token_count": 49, "parameters": [ "arr", "func_name" ], "start_line": 389, "end_line": 395, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "lazy_transpose", "long_name": "lazy_transpose( PyArrayObject * arr)", "filename": "fortranobject.c", "nloc": 14, "complexity": 3, "token_count": 122, "parameters": [ "arr" ], "start_line": 401, "end_line": 421, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "transpose_strides", "long_name": "transpose_strides( PyArrayObject * arr)", "filename": "fortranobject.c", "nloc": 11, "complexity": 3, "token_count": 75, "parameters": [ "arr" ], "start_line": 424, "end_line": 434, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "count_nonpos", "long_name": "count_nonpos( const int rank , const intp * dims)", "filename": "fortranobject.c", "nloc": 9, "complexity": 3, "token_count": 48, "parameters": [ "rank", "dims" ], "start_line": 477, "end_line": 485, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "dump_attrs", "long_name": "dump_attrs( const PyArrayObject * arr)", "filename": "fortranobject.c", "nloc": 16, "complexity": 3, "token_count": 117, "parameters": [ "arr" ], "start_line": 492, "end_line": 507, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "swap_arrays", "long_name": "swap_arrays( PyArrayObject * arr1 , PyArrayObject * arr2)", "filename": "fortranobject.c", "nloc": 11, "complexity": 1, "token_count": 124, "parameters": [ "arr1", "arr2" ], "start_line": 512, "end_line": 523, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "array_from_pyobj", "long_name": "array_from_pyobj( const int type_num , intp * dims , const int rank , const int intent , PyObject * obj)", "filename": "fortranobject.c", "nloc": 105, "complexity": 28, "token_count": 628, "parameters": [ "type_num", "dims", "rank", "intent", "obj" ], "start_line": 541, "end_line": 665, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 125, "top_nesting_level": 1 }, { "name": "old_array_from_pyobj", "long_name": "old_array_from_pyobj( const int type_num , intp * dims , const int rank , const int intent , PyObject * obj)", "filename": "fortranobject.c", "nloc": 146, "complexity": 42, "token_count": 904, "parameters": [ "type_num", "dims", "rank", "intent", "obj" ], "start_line": 668, "end_line": 845, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 178, "top_nesting_level": 1 }, { "name": "array_has_column_major_storage", "long_name": "array_has_column_major_storage( const PyArrayObject * ap)", "filename": "fortranobject.c", "nloc": 11, "complexity": 4, "token_count": 80, "parameters": [ "ap" ], "start_line": 852, "end_line": 870, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 1 }, { "name": "check_and_fix_dimensions", "long_name": "check_and_fix_dimensions( const PyArrayObject * arr , const int rank , intp * dims)", "filename": "fortranobject.c", "nloc": 88, "complexity": 33, "token_count": 724, "parameters": [ "arr", "rank", "dims" ], "start_line": 873, "end_line": 967, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 95, "top_nesting_level": 1 }, { "name": "copy_ND_array", "long_name": "copy_ND_array( const PyArrayObject * in , PyArrayObject * out)", "filename": "fortranobject.c", "nloc": 5, "complexity": 2, "token_count": 32, "parameters": [ "in", "out" ], "start_line": 974, "end_line": 980, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 } ], "methods_before": [ { "name": "PyFortranObject_New", "long_name": "PyFortranObject_New( FortranDataDef * defs , f2py_void_func init)", "filename": "fortranobject.c", "nloc": 31, "complexity": 11, "token_count": 312, "parameters": [ "defs", "init" ], "start_line": 22, "end_line": 52, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 1 }, { "name": "PyFortranObject_NewAsAttr", "long_name": "PyFortranObject_NewAsAttr( FortranDataDef * defs)", "filename": "fortranobject.c", "nloc": 9, "complexity": 3, "token_count": 69, "parameters": [ "defs" ], "start_line": 55, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "fortran_dealloc", "long_name": "fortran_dealloc( PyFortranObject * fp)", "filename": "fortranobject.c", "nloc": 4, "complexity": 1, "token_count": 20, "parameters": [ "fp" ], "start_line": 68, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "fortran_doc", "long_name": "fortran_doc( FortranDataDef def)", "filename": "fortranobject.c", "nloc": 46, "complexity": 21, "token_count": 434, "parameters": [ "def" ], "start_line": 80, "end_line": 125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 46, "top_nesting_level": 1 }, { "name": "set_data", "long_name": "set_data( char * d , intp * f)", "filename": "fortranobject.c", "nloc": 6, "complexity": 2, "token_count": 30, "parameters": [ "d", "f" ], "start_line": 128, "end_line": 134, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "fortran_getattr", "long_name": "fortran_getattr( PyFortranObject * fp , char * name)", "filename": "fortranobject.c", "nloc": 52, "complexity": 18, "token_count": 519, "parameters": [ "fp", "name" ], "start_line": 137, "end_line": 189, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "top_nesting_level": 1 }, { "name": "fortran_setattr", "long_name": "fortran_setattr( PyFortranObject * fp , char * name , PyObject * v)", "filename": "fortranobject.c", "nloc": 59, "complexity": 22, "token_count": 647, "parameters": [ "fp", "name", "v" ], "start_line": 192, "end_line": 252, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 61, "top_nesting_level": 1 }, { "name": "fortran_call", "long_name": "fortran_call( PyFortranObject * fp , PyObject * arg , PyObject * kw)", "filename": "fortranobject.c", "nloc": 16, "complexity": 4, "token_count": 166, "parameters": [ "fp", "arg", "kw" ], "start_line": 255, "end_line": 274, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "f2py_start_clock", "long_name": "f2py_start_clock()", "filename": "fortranobject.c", "nloc": 1, "complexity": 1, "token_count": 12, "parameters": [], "start_line": 315, "end_line": 315, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "f2py_start_call_clock", "long_name": "f2py_start_call_clock()", "filename": "fortranobject.c", "nloc": 4, "complexity": 1, "token_count": 16, "parameters": [], "start_line": 317, "end_line": 320, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "f2py_stop_clock", "long_name": "f2py_stop_clock()", "filename": "fortranobject.c", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [], "start_line": 322, "end_line": 326, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "f2py_stop_call_clock", "long_name": "f2py_stop_call_clock()", "filename": "fortranobject.c", "nloc": 7, "complexity": 1, "token_count": 44, "parameters": [], "start_line": 328, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "f2py_cb_start_clock", "long_name": "f2py_cb_start_clock()", "filename": "fortranobject.c", "nloc": 1, "complexity": 1, "token_count": 12, "parameters": [], "start_line": 336, "end_line": 336, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "f2py_cb_start_call_clock", "long_name": "f2py_cb_start_call_clock()", "filename": "fortranobject.c", "nloc": 4, "complexity": 1, "token_count": 16, "parameters": [], "start_line": 338, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "f2py_cb_stop_clock", "long_name": "f2py_cb_stop_clock()", "filename": "fortranobject.c", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [], "start_line": 343, "end_line": 347, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "f2py_cb_stop_call_clock", "long_name": "f2py_cb_stop_call_clock()", "filename": "fortranobject.c", "nloc": 7, "complexity": 1, "token_count": 44, "parameters": [], "start_line": 349, "end_line": 355, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "f2py_report_on_exit", "long_name": "f2py_report_on_exit( int exit_flag , * name)", "filename": "fortranobject.c", "nloc": 24, "complexity": 2, "token_count": 146, "parameters": [ "exit_flag", "name" ], "start_line": 359, "end_line": 383, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "f2py_report_on_array_copy", "long_name": "f2py_report_on_array_copy( PyArrayObject * arr , char * func_name)", "filename": "fortranobject.c", "nloc": 7, "complexity": 2, "token_count": 49, "parameters": [ "arr", "func_name" ], "start_line": 389, "end_line": 395, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "lazy_transpose", "long_name": "lazy_transpose( PyArrayObject * arr)", "filename": "fortranobject.c", "nloc": 14, "complexity": 3, "token_count": 122, "parameters": [ "arr" ], "start_line": 401, "end_line": 421, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "transpose_strides", "long_name": "transpose_strides( PyArrayObject * arr)", "filename": "fortranobject.c", "nloc": 11, "complexity": 3, "token_count": 75, "parameters": [ "arr" ], "start_line": 424, "end_line": 434, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "count_nonpos", "long_name": "count_nonpos( const int rank , const intp * dims)", "filename": "fortranobject.c", "nloc": 9, "complexity": 3, "token_count": 48, "parameters": [ "rank", "dims" ], "start_line": 477, "end_line": 485, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "dump_attrs", "long_name": "dump_attrs( const PyArrayObject * arr)", "filename": "fortranobject.c", "nloc": 16, "complexity": 3, "token_count": 117, "parameters": [ "arr" ], "start_line": 492, "end_line": 507, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "swap_arrays", "long_name": "swap_arrays( PyArrayObject * arr1 , PyArrayObject * arr2)", "filename": "fortranobject.c", "nloc": 11, "complexity": 1, "token_count": 124, "parameters": [ "arr1", "arr2" ], "start_line": 512, "end_line": 523, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "array_from_pyobj", "long_name": "array_from_pyobj( const int type_num , intp * dims , const int rank , const int intent , PyObject * obj)", "filename": "fortranobject.c", "nloc": 146, "complexity": 42, "token_count": 904, "parameters": [ "type_num", "dims", "rank", "intent", "obj" ], "start_line": 541, "end_line": 718, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 178, "top_nesting_level": 1 }, { "name": "array_has_column_major_storage", "long_name": "array_has_column_major_storage( const PyArrayObject * ap)", "filename": "fortranobject.c", "nloc": 11, "complexity": 4, "token_count": 80, "parameters": [ "ap" ], "start_line": 725, "end_line": 743, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 1 }, { "name": "check_and_fix_dimensions", "long_name": "check_and_fix_dimensions( const PyArrayObject * arr , const int rank , intp * dims)", "filename": "fortranobject.c", "nloc": 88, "complexity": 33, "token_count": 724, "parameters": [ "arr", "rank", "dims" ], "start_line": 746, "end_line": 840, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 95, "top_nesting_level": 1 }, { "name": "copy_ND_array", "long_name": "copy_ND_array( const PyArrayObject * in , PyArrayObject * out)", "filename": "fortranobject.c", "nloc": 5, "complexity": 2, "token_count": 32, "parameters": [ "in", "out" ], "start_line": 847, "end_line": 853, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "old_array_from_pyobj", "long_name": "old_array_from_pyobj( const int type_num , intp * dims , const int rank , const int intent , PyObject * obj)", "filename": "fortranobject.c", "nloc": 146, "complexity": 42, "token_count": 904, "parameters": [ "type_num", "dims", "rank", "intent", "obj" ], "start_line": 668, "end_line": 845, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 178, "top_nesting_level": 1 }, { "name": "array_from_pyobj", "long_name": "array_from_pyobj( const int type_num , intp * dims , const int rank , const int intent , PyObject * obj)", "filename": "fortranobject.c", "nloc": 105, "complexity": 28, "token_count": 628, "parameters": [ "type_num", "dims", "rank", "intent", "obj" ], "start_line": 541, "end_line": 665, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 125, "top_nesting_level": 1 } ], "nloc": 770, "complexity": 216, "token_count": 5723, "diff_parsed": { "added": [ "", " if (intent & F2PY_INTENT_CACHE) {", " /* Don't expect correct storage order or anything reasonable when", " returning intent(cache) array. */", " if ((intent & F2PY_INTENT_HIDE)", "\t|| (obj==Py_None)) {", " PyArrayObject *arr = NULL;", " CHECK_DIMS_DEFINED(rank,dims,\"optional,intent(cache) must\"", "\t\t\t \" have defined dimensions.\\n\");", " arr = (PyArrayObject *)PyArray_SimpleNew(rank,dims,type_num);", " ARR_IS_NULL(arr==NULL,\"PyArray_SimpleNew failed: optional,intent(cache)\\n\");", " return arr;", " }", " if (PyArray_Check(obj)", "\t&& PyArray_ISONESEGMENT(obj)", "\t&& HAS_PROPER_ELSIZE((PyArrayObject *)obj,type_num)", "\t) {", " if (check_and_fix_dimensions((PyArrayObject *)obj,rank,dims))", "\treturn NULL; /*XXX: set exception */", " {", "\tif (intent & F2PY_INTENT_OUT)", "\t Py_INCREF(obj);", "\treturn (PyArrayObject *)obj;", " }", " }", " ARR_IS_NULL(1,\"intent(cache) must be contiguous array with a proper elsize.\\n\");", " }", "", " if (intent & F2PY_INTENT_HIDE) {", " PyArrayObject *arr = NULL;", " CHECK_DIMS_DEFINED(rank,dims,\"intent(hide) must have defined dimensions.\\n\");", " arr = (PyArrayObject *)", " PyArray_New(&PyArray_Type, rank, dims, type_num,", "\t\t NULL,NULL,0,", "\t\t !(intent&F2PY_INTENT_C),", "\t\t NULL);", " ARR_IS_NULL(arr==NULL,\"PyArray_New failed: intent(hide)\\n\");", " PyArray_FILLWBYTE(arr, 0);", " return arr;", " }", "", " if (PyArray_Check(obj)) { /* here we have always intent(in) or", "\t\t\t intent(inout) or intent(inplace) */", " PyArrayObject *arr = (PyArrayObject *)obj;", "", " if (check_and_fix_dimensions(arr,rank,dims))", " return NULL; /*XXX: set exception */", "", " if ((! (intent & F2PY_INTENT_COPY))", "\t&& HAS_PROPER_ELSIZE(arr,type_num)", "\t&& PyArray_CanCastSafely(arr->descr->type_num,type_num)", "\t) {", " if ((intent & F2PY_INTENT_C)?PyArray_ISCARRAY(arr):PyArray_ISFARRAY(arr)) {", "\tif ((intent & F2PY_INTENT_OUT)) {", "\t Py_INCREF(arr);", "\t}", "\treturn arr;", " }", " }", "", " {", " PyArrayObject *retarr = (PyArrayObject *) \\", "\tPyArray_New(&PyArray_Type, rank, dims, type_num,", "\t\t NULL,NULL,0,", "\t\t !(intent&F2PY_INTENT_C),", "\t\t NULL);", "", " ARR_IS_NULL(retarr==NULL,\"PyArray_New failed: intent(in,copy)\\n\");", " if (PyArray_CopyInto(retarr, arr)) {", "\tPy_DECREF(retarr);", "\treturn NULL;", " }", " if (intent & F2PY_INTENT_INPLACE) {", "\tif (swap_arrays(arr,retarr))", "\t return NULL;", "\tPy_XDECREF(retarr);", "\tif (intent & F2PY_INTENT_OUT)", "\t Py_INCREF(arr);", " } else {", "\tarr = retarr;", " }", " }", " return arr;", " }", "", " if ((obj==Py_None) && (intent & F2PY_OPTIONAL)) {", " PyArrayObject *arr = NULL;", " CHECK_DIMS_DEFINED(rank,dims,\"optional must have defined dimensions.\\n\");", " arr = (PyArrayObject *)", " PyArray_New(&PyArray_Type, rank, dims, type_num,", "\t\t NULL,NULL,0,", "\t\t !(intent&F2PY_INTENT_C),", "\t\t NULL);", " ARR_IS_NULL(arr==NULL,\"PyArray_New failed: optional\\n\");", " PyArray_FILLWBYTE(arr, 0);", " return arr;", " }", "", " if ((intent & F2PY_INTENT_INOUT) || (intent & F2PY_INTENT_INPLACE)) {", " ARR_IS_NULL(1,\"intent(inout)|intent(inplace) argument must be an array.\\n\");", " }", "", " {", " PyArray_Typecode typecode = {type_num, 0, 0};", " PyArrayObject *arr = (PyArrayObject *) \\", " PyArray_FromAny(obj,&typecode, 0,0,", "\t\t ((intent & F2PY_INTENT_C)?CARRAY_FLAGS:FARRAY_FLAGS));", " ARR_IS_NULL(arr==NULL,\"PyArray_FromAny failed: not a sequence.\\n\");", " if (check_and_fix_dimensions(arr,rank,dims))", " return NULL; /*XXX: set exception */", " return arr;", " }", "", "}", "", "extern", "PyArrayObject* old_array_from_pyobj(const int type_num,", "\t\t\t\tintp *dims,", "\t\t\t\tconst int rank,", "\t\t\t\tconst int intent,", "\t\t\t\tPyObject *obj) {", " /* Note about reference counting", " -----------------------------", " If the caller returns the array to Python, it must be done with", " Py_BuildValue(\"N\",arr).", " Otherwise, if obj!=arr then the caller must call Py_DECREF(arr).", " */" ], "deleted": [] } } ] }, { "hash": "33616f8e0e2574ce73442bf257dba723f812b572", "msg": "Fix toscalar so it only works when a.size == 1", "author": { "name": "Travis Oliphant", "email": "oliphant@enthought.com" }, "committer": { "name": "Travis Oliphant", "email": "oliphant@enthought.com" }, "author_date": "2005-10-26T02:41:30+00:00", "author_timezone": 0, "committer_date": "2005-10-26T02:41:30+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "878d5355b9e5ef92db78a51daff325f34d295690" ], "project_name": "repo_copy", "project_path": "/tmp/tmpn4cqam_6/repo_copy", "deletions": 1, "insertions": 7, "lines": 8, "files": 1, "dmm_unit_size": 1.0, "dmm_unit_complexity": 1.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy/base/src/arraymethods.c", "new_path": "scipy/base/src/arraymethods.c", "filename": "arraymethods.c", "extension": "c", "change_type": "MODIFY", "diff": "@@ -426,7 +426,13 @@ static char doc_toscalar[] = \"m.toscalar(). Copy the first data point of \"\\\n static PyObject *\n array_toscalar(PyArrayObject *self, PyObject *args) {\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n- return self->descr->getitem(self->data, self);\n+\tif (self->nd == 0 || PyArray_SIZE(self) == 1) \n+\t\treturn self->descr->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 \n static char doc_cast[] = \"m.astype(t).\tCast array m to type t.\t \\n\\n\"\\\n", "added_lines": 7, "deleted_lines": 1, "source_code": "\n#define _ARET(x) PyArray_Return((PyArrayObject *)(x))\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(indices, values) 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[] = {\"indices\", \"values\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &indices, &values))\n\t\treturn NULL;\n\treturn PyArray_Put(self, indices, values);\n}\n\nstatic char doc_putmask[] = \"a.putmask(mask, values) 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[] = {\"mask\", \"values\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &mask, &values))\n\t\treturn NULL;\n\treturn PyArray_PutMask(self, mask, values);\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.\";\n\nstatic PyObject *\narray_view(PyArrayObject *self, PyObject *args)\n{\n PyArray_Typecode type = {PyArray_NOTYPE, 0, 0};\n\tif (!PyArg_ParseTuple(args, \"|O&\",\n PyArray_TypecodeConverter, &type)) \n return NULL;\n\n\treturn _ARET(PyArray_View(self, &type));\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.field(type, 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 items given.\";\n\nstatic PyObject *\nPyArray_GetField(PyArrayObject *self, PyArray_Typecode *type, \n\t\t\t\t int offset)\n{\n\tPyObject *ret=NULL;\n\tret = PyArray_New(self->ob_type, self->nd, self->dimensions,\n\t\t\t type->type_num, self->strides, \n\t\t\t self->data + offset,\n\t\t\t type->itemsize, self->flags, (PyObject *)self);\n\tif (ret == NULL) return NULL;\n\tPy_INCREF(self);\n\t((PyArrayObject *)ret)->base = (PyObject *)self;\n\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\n\treturn ret;\t\n}\n\nstatic PyObject *\narray_getfield(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n\tPyArray_Typecode typecode = {PyArray_NOTYPE, 0, 0};\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_TypecodeConverter, \n\t\t\t\t\t &typecode, &offset)) return NULL;\n\n\t\n\tif (typecode.itemsize > self->itemsize) {\n\t\tPyErr_SetString(PyExc_TypeError, \"field itemsize must be <=\"\\\n\t\t\t\t\"array itemsize\");\n\t\treturn NULL;\n\t}\n\treturn _ARET(PyArray_GetField(self, &typecode, offset));\n}\n\nstatic PyObject *\nPyArray_Byteswap(PyArrayObject *self, Bool inplace)\n{\n PyArrayObject *ret;\n\tintp size;\n\tPyArray_CopySwapNFunc *copyswapn;\n\tPyArrayIterObject *it;\n\n\tif (inplace) {\n\t\tcopyswapn = self->descr->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, self->itemsize);\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\t\n\t\t\twhile (it->index < it->size) {\n\t\t\t\tcopyswapn(it->dataptr, NULL, 1, 1, \n\t\t\t\t\t self->itemsize);\n\t\t\t\tPyArray_ITER_NEXT(it);\n\t\t\t}\n\t\t\tPy_DECREF(it);\n\t\t}\n\n\t\tif (self->flags & NOTSWAPPED) self->flags &= ~NOTSWAPPED;\n\t\telse self->flags |= NOTSWAPPED;\n\t\t\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n\telse {\n\t\tif ((ret = (PyArrayObject *)PyArray_Copy(self)) == NULL) \n\t\t\treturn NULL;\n\t\t\n\t\tsize = PyArray_SIZE(self);\n\t\t\n\t\t/* set the NOTSWAPPED flag to opposite self */\n\t\t/* ret is always notswapped, \n\t\t PyArray_Copy has already swapped if self was swapped */\n\n\t\tif (self->flags & NOTSWAPPED) {\n\t\t\tret->descr->copyswapn(ret->data, NULL, size, 1, ret->itemsize);\n\t\t\tret->flags &= ~NOTSWAPPED;\n\t\t}\n\t\telse { /* self was swapped, so now ret isn't */\n\t\t\tret->flags |= NOTSWAPPED;\n\t\t}\n\t\t\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.toscalar(). 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->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_Typecode typecode = {PyArray_NOTYPE, 0, 0};\n\t\n if (!PyArg_ParseTuple(args, \"O&\", PyArray_TypecodeConverter,\n\t\t\t &typecode)) return NULL;\n\n\tif (typecode.type_num == PyArray_NOTYPE ||\t\\\n\t typecode.type_num == PyArray_TYPE(self)) {\n\t\treturn _ARET(PyArray_Copy(self));\n\t}\n\treturn _ARET(PyArray_CastToType(self, &typecode));\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\tret = PyArray_New(self->ob_type, PyArray_NDIM(arr),\n\t\t\t PyArray_DIMS(arr), PyArray_TYPE(arr),\n\t\t\t PyArray_STRIDES(arr), PyArray_DATA(arr),\n\t\t\t PyArray_ITEMSIZE(arr), \n\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__(|type) just returns either a new reference to self if type is not given or a new array of type if type is different from the current type of the array.\";\n\nstatic PyObject *\narray_getarray(PyArrayObject *self, PyObject *args) \n{\n\tPyArray_Typecode newtype = {PyArray_NOTYPE, 0, 0};\n\tPyArray_Typecode oldtype = {PyArray_TYPE(self),\n\t\t\t\t PyArray_ITEMSIZE(self),\n\t\t\t\t 0};\n\tPyObject *ret;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\", &PyArray_TypecodeConverter,\n\t\t\t &newtype)) return NULL;\n\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\tnew = PyArray_New(subtype, PyArray_NDIM(self),\n\t\t\t\t PyArray_DIMS(self), PyArray_TYPE(self),\n\t\t\t\t PyArray_STRIDES(self), PyArray_DATA(self),\n\t\t\t\t PyArray_ITEMSIZE(self), \n\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.type_num == PyArray_NOTYPE ||\n\t PyArray_EquivalentTypes(&oldtype, &newtype)) {\n\t\treturn (PyObject *)self;\n\t}\n\telse {\n\t\tret = PyArray_CastToType(self, &newtype);\n\t\tPy_DECREF(self);\n\t\treturn ret;\n\t}\n}\n\nstatic char doc_copy[] = \"m.copy(). Return a copy of the array.\";\n\nstatic PyObject *\narray_copy(PyArrayObject *self, PyObject *args) \n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\t\n return _ARET(PyArray_Copy(self));\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\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 PyArray_Repeat(self, repeats, axis);\n}\n\nstatic char doc_choose[] = \"self.choose(b0,b1,...,bn)\\n\"\\\n\t\"\\n\"\\\n\t\" Self sould be an integer array with entries from 0 to n+1, \\n\"\\\n\t\" The bi arrays should be of the same shape as self. The result\\n\"\\\n\t\" will be an array with elements chosen from the bi arrays\\n\"\\\n\t\" according to the value at each position of self.\";\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()\";\n\nstatic PyObject *\narray_sort(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_Sort(self, axis));\n}\n\nstatic char doc_argsort[] = \"a.argsort()\\n\"\\\n\t\" Return the indexes into a that would sort it along the\"\\\n\t\" given axis (or if the sorting should be done\"\\\n\t\" in terms of a.flat\";\n\nstatic PyObject *\narray_argsort(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_ArgSort(self, axis));\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;\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 if (deepcopy == NULL) return NULL;\n Py_DECREF(copy);\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->itemsize;\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\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 *Bool, *thestr=NULL;\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(\"scipy.base.multiarray\");\n\tif (mod == NULL) return NULL;\n\tobj = PyObject_GetAttrString(mod, \"empty\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) return NULL;\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tPyTuple_SET_ITEM(ret, 1, \n\t\t\t Py_BuildValue(\"NNN\",\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,\n\t\t\t\t\t\t\t \"dtypechar\"),\n\t\t\t\t PyInt_FromLong((long) 0)));\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 string giving the typestr (> or < indicates byte order\n\t if swap is possibly needed)\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\"));\t\n\tPyTuple_SET_ITEM(state, 1, PyObject_GetAttrString((PyObject *)self, \n\t\t\t\t\t\t\t \"dtypestr\"));\n\tBool = (PyArray_ISFORTRAN(self) ? Py_True : Py_False);\n\tPy_INCREF(Bool);\n\tPyTuple_SET_ITEM(state, 2, Bool);\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 string giving the typestr (> or < indicates byte order\n\t if swap is possibly needed)\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 PyObject *\narray_setstate(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *shape;\n\tPyArray_Typecode typecode;\n\tlong fortran;\n\tPyObject *rawdata;\n\tchar *datastr;\n\tconst char *typestr;\n\tint len, typestrlen;\n\tint swap;\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!z#iO)\", &PyTuple_Type,\n\t\t\t &shape, &typestr, &typestrlen,\n\t\t\t &fortran, &rawdata))\n\t\treturn NULL;\n\n\tif (_array_typecode_fromstr((char *)typestr, &swap, &typecode) < 0)\n\t\treturn NULL;\n\n\tself->descr = PyArray_DescrFromType(typecode.type_num);\n\tself->itemsize = typecode.itemsize;\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->itemsize *\t\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->itemsize, 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\tself->base = rawdata;\n\t\tPy_INCREF(self->base);\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->itemsize);\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\n\tif (swap) self->flags &= ~NOTSWAPPED;\n\t\n\tPy_INCREF(Py_None);\n\treturn Py_None;\t\n}\n\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), \"rb\");\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\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\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\treturn _ARET(PyArray_Transpose(self, shape));\n}\n\nstatic char doc_mean[] = \"a.mean(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_mean(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\n\treturn _ARET(PyArray_Mean(self, axis, rtype.type_num));\n}\n\nstatic char doc_sum[] = \"a.sum(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_sum(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\t\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_Sum(self, axis, rtype.type_num);\n}\n\n\nstatic char doc_cumsum[] = \"a.cumsum(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_cumsum(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_CumSum(self, axis, rtype.type_num);\n}\n\nstatic char doc_prod[] = \"a.prod(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_prod(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_Prod(self, axis, rtype.type_num);\n}\n\n\nstatic char doc_cumprod[] = \"a.cumprod(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_cumprod(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_CumProd(self, axis, rtype.type_num);\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\n\nstatic char doc_stddev[] = \"a.std(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_stddev(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_Std(self, axis, rtype.type_num);\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, rtype=None)\";\n\nstatic PyObject *\narray_trace(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis1=0, axis2=1, offset=0;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"offset\", \"axis1\", \"axis2\", \"rtype\", 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_TypecodeConverter, &rtype))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Trace(self, offset, axis1, axis2, rtype.type_num));\n}\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\tBool fortran=FALSE;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\",\n\t\t\t PyArray_BoolConverter, &fortran)) \n\t\treturn 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\tBool fortran=FALSE;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_BoolConverter,\n\t\t\t &fortran)) return NULL;\n\n\treturn PyArray_Ravel(self, (int) fortran);\n}\n\n\n\nstatic char doc_setflags[] = \"a.setflags(write=None, swap=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\", \"swap\", \"align\", \"uic\", NULL};\n\tPyObject *write=Py_None;\n\tPyObject *swap=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, \"|OOOO\", kwlist,\n\t\t\t\t\t &write, &swap, &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 if (swap != Py_None) {\n if (PyObject_IsTrue(swap))\n self->flags &= ~NOTSWAPPED;\n else \n self->flags |= NOTSWAPPED;\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic PyMethodDef array_methods[] = {\n {\"tolist\",\t (PyCFunction)array_tolist,\t1, doc_tolist},\n {\"toscalar\", (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 {\"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, doc_sort},\n\t{\"argsort\",\t(PyCFunction)array_argsort, \n\t METH_VARARGS, 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{\"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 {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\n#undef _ARET\n\n\n", "source_code_before": "\n#define _ARET(x) PyArray_Return((PyArrayObject *)(x))\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(indices, values) 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[] = {\"indices\", \"values\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &indices, &values))\n\t\treturn NULL;\n\treturn PyArray_Put(self, indices, values);\n}\n\nstatic char doc_putmask[] = \"a.putmask(mask, values) 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[] = {\"mask\", \"values\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &mask, &values))\n\t\treturn NULL;\n\treturn PyArray_PutMask(self, mask, values);\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.\";\n\nstatic PyObject *\narray_view(PyArrayObject *self, PyObject *args)\n{\n PyArray_Typecode type = {PyArray_NOTYPE, 0, 0};\n\tif (!PyArg_ParseTuple(args, \"|O&\",\n PyArray_TypecodeConverter, &type)) \n return NULL;\n\n\treturn _ARET(PyArray_View(self, &type));\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.field(type, 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 items given.\";\n\nstatic PyObject *\nPyArray_GetField(PyArrayObject *self, PyArray_Typecode *type, \n\t\t\t\t int offset)\n{\n\tPyObject *ret=NULL;\n\tret = PyArray_New(self->ob_type, self->nd, self->dimensions,\n\t\t\t type->type_num, self->strides, \n\t\t\t self->data + offset,\n\t\t\t type->itemsize, self->flags, (PyObject *)self);\n\tif (ret == NULL) return NULL;\n\tPy_INCREF(self);\n\t((PyArrayObject *)ret)->base = (PyObject *)self;\n\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\n\treturn ret;\t\n}\n\nstatic PyObject *\narray_getfield(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n\tPyArray_Typecode typecode = {PyArray_NOTYPE, 0, 0};\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_TypecodeConverter, \n\t\t\t\t\t &typecode, &offset)) return NULL;\n\n\t\n\tif (typecode.itemsize > self->itemsize) {\n\t\tPyErr_SetString(PyExc_TypeError, \"field itemsize must be <=\"\\\n\t\t\t\t\"array itemsize\");\n\t\treturn NULL;\n\t}\n\treturn _ARET(PyArray_GetField(self, &typecode, offset));\n}\n\nstatic PyObject *\nPyArray_Byteswap(PyArrayObject *self, Bool inplace)\n{\n PyArrayObject *ret;\n\tintp size;\n\tPyArray_CopySwapNFunc *copyswapn;\n\tPyArrayIterObject *it;\n\n\tif (inplace) {\n\t\tcopyswapn = self->descr->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, self->itemsize);\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\t\n\t\t\twhile (it->index < it->size) {\n\t\t\t\tcopyswapn(it->dataptr, NULL, 1, 1, \n\t\t\t\t\t self->itemsize);\n\t\t\t\tPyArray_ITER_NEXT(it);\n\t\t\t}\n\t\t\tPy_DECREF(it);\n\t\t}\n\n\t\tif (self->flags & NOTSWAPPED) self->flags &= ~NOTSWAPPED;\n\t\telse self->flags |= NOTSWAPPED;\n\t\t\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n\telse {\n\t\tif ((ret = (PyArrayObject *)PyArray_Copy(self)) == NULL) \n\t\t\treturn NULL;\n\t\t\n\t\tsize = PyArray_SIZE(self);\n\t\t\n\t\t/* set the NOTSWAPPED flag to opposite self */\n\t\t/* ret is always notswapped, \n\t\t PyArray_Copy has already swapped if self was swapped */\n\n\t\tif (self->flags & NOTSWAPPED) {\n\t\t\tret->descr->copyswapn(ret->data, NULL, size, 1, ret->itemsize);\n\t\t\tret->flags &= ~NOTSWAPPED;\n\t\t}\n\t\telse { /* self was swapped, so now ret isn't */\n\t\t\tret->flags |= NOTSWAPPED;\n\t\t}\n\t\t\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.toscalar(). 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 return self->descr->getitem(self->data, self);\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_Typecode typecode = {PyArray_NOTYPE, 0, 0};\n\t\n if (!PyArg_ParseTuple(args, \"O&\", PyArray_TypecodeConverter,\n\t\t\t &typecode)) return NULL;\n\n\tif (typecode.type_num == PyArray_NOTYPE ||\t\\\n\t typecode.type_num == PyArray_TYPE(self)) {\n\t\treturn _ARET(PyArray_Copy(self));\n\t}\n\treturn _ARET(PyArray_CastToType(self, &typecode));\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\tret = PyArray_New(self->ob_type, PyArray_NDIM(arr),\n\t\t\t PyArray_DIMS(arr), PyArray_TYPE(arr),\n\t\t\t PyArray_STRIDES(arr), PyArray_DATA(arr),\n\t\t\t PyArray_ITEMSIZE(arr), \n\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__(|type) just returns either a new reference to self if type is not given or a new array of type if type is different from the current type of the array.\";\n\nstatic PyObject *\narray_getarray(PyArrayObject *self, PyObject *args) \n{\n\tPyArray_Typecode newtype = {PyArray_NOTYPE, 0, 0};\n\tPyArray_Typecode oldtype = {PyArray_TYPE(self),\n\t\t\t\t PyArray_ITEMSIZE(self),\n\t\t\t\t 0};\n\tPyObject *ret;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\", &PyArray_TypecodeConverter,\n\t\t\t &newtype)) return NULL;\n\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\tnew = PyArray_New(subtype, PyArray_NDIM(self),\n\t\t\t\t PyArray_DIMS(self), PyArray_TYPE(self),\n\t\t\t\t PyArray_STRIDES(self), PyArray_DATA(self),\n\t\t\t\t PyArray_ITEMSIZE(self), \n\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.type_num == PyArray_NOTYPE ||\n\t PyArray_EquivalentTypes(&oldtype, &newtype)) {\n\t\treturn (PyObject *)self;\n\t}\n\telse {\n\t\tret = PyArray_CastToType(self, &newtype);\n\t\tPy_DECREF(self);\n\t\treturn ret;\n\t}\n}\n\nstatic char doc_copy[] = \"m.copy(). Return a copy of the array.\";\n\nstatic PyObject *\narray_copy(PyArrayObject *self, PyObject *args) \n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\t\n return _ARET(PyArray_Copy(self));\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\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 PyArray_Repeat(self, repeats, axis);\n}\n\nstatic char doc_choose[] = \"self.choose(b0,b1,...,bn)\\n\"\\\n\t\"\\n\"\\\n\t\" Self sould be an integer array with entries from 0 to n+1, \\n\"\\\n\t\" The bi arrays should be of the same shape as self. The result\\n\"\\\n\t\" will be an array with elements chosen from the bi arrays\\n\"\\\n\t\" according to the value at each position of self.\";\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()\";\n\nstatic PyObject *\narray_sort(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_Sort(self, axis));\n}\n\nstatic char doc_argsort[] = \"a.argsort()\\n\"\\\n\t\" Return the indexes into a that would sort it along the\"\\\n\t\" given axis (or if the sorting should be done\"\\\n\t\" in terms of a.flat\";\n\nstatic PyObject *\narray_argsort(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_ArgSort(self, axis));\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;\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 if (deepcopy == NULL) return NULL;\n Py_DECREF(copy);\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->itemsize;\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\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 *Bool, *thestr=NULL;\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(\"scipy.base.multiarray\");\n\tif (mod == NULL) return NULL;\n\tobj = PyObject_GetAttrString(mod, \"empty\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) return NULL;\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tPyTuple_SET_ITEM(ret, 1, \n\t\t\t Py_BuildValue(\"NNN\",\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,\n\t\t\t\t\t\t\t \"dtypechar\"),\n\t\t\t\t PyInt_FromLong((long) 0)));\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 string giving the typestr (> or < indicates byte order\n\t if swap is possibly needed)\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\"));\t\n\tPyTuple_SET_ITEM(state, 1, PyObject_GetAttrString((PyObject *)self, \n\t\t\t\t\t\t\t \"dtypestr\"));\n\tBool = (PyArray_ISFORTRAN(self) ? Py_True : Py_False);\n\tPy_INCREF(Bool);\n\tPyTuple_SET_ITEM(state, 2, Bool);\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 string giving the typestr (> or < indicates byte order\n\t if swap is possibly needed)\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 PyObject *\narray_setstate(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *shape;\n\tPyArray_Typecode typecode;\n\tlong fortran;\n\tPyObject *rawdata;\n\tchar *datastr;\n\tconst char *typestr;\n\tint len, typestrlen;\n\tint swap;\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!z#iO)\", &PyTuple_Type,\n\t\t\t &shape, &typestr, &typestrlen,\n\t\t\t &fortran, &rawdata))\n\t\treturn NULL;\n\n\tif (_array_typecode_fromstr((char *)typestr, &swap, &typecode) < 0)\n\t\treturn NULL;\n\n\tself->descr = PyArray_DescrFromType(typecode.type_num);\n\tself->itemsize = typecode.itemsize;\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->itemsize *\t\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->itemsize, 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\tself->base = rawdata;\n\t\tPy_INCREF(self->base);\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->itemsize);\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\n\tif (swap) self->flags &= ~NOTSWAPPED;\n\t\n\tPy_INCREF(Py_None);\n\treturn Py_None;\t\n}\n\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), \"rb\");\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\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\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\treturn _ARET(PyArray_Transpose(self, shape));\n}\n\nstatic char doc_mean[] = \"a.mean(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_mean(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\n\treturn _ARET(PyArray_Mean(self, axis, rtype.type_num));\n}\n\nstatic char doc_sum[] = \"a.sum(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_sum(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\t\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_Sum(self, axis, rtype.type_num);\n}\n\n\nstatic char doc_cumsum[] = \"a.cumsum(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_cumsum(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_CumSum(self, axis, rtype.type_num);\n}\n\nstatic char doc_prod[] = \"a.prod(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_prod(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_Prod(self, axis, rtype.type_num);\n}\n\n\nstatic char doc_cumprod[] = \"a.cumprod(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_cumprod(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_CumProd(self, axis, rtype.type_num);\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\n\nstatic char doc_stddev[] = \"a.std(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_stddev(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_Std(self, axis, rtype.type_num);\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, rtype=None)\";\n\nstatic PyObject *\narray_trace(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis1=0, axis2=1, offset=0;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"offset\", \"axis1\", \"axis2\", \"rtype\", 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_TypecodeConverter, &rtype))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Trace(self, offset, axis1, axis2, rtype.type_num));\n}\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\tBool fortran=FALSE;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\",\n\t\t\t PyArray_BoolConverter, &fortran)) \n\t\treturn 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\tBool fortran=FALSE;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_BoolConverter,\n\t\t\t &fortran)) return NULL;\n\n\treturn PyArray_Ravel(self, (int) fortran);\n}\n\n\n\nstatic char doc_setflags[] = \"a.setflags(write=None, swap=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\", \"swap\", \"align\", \"uic\", NULL};\n\tPyObject *write=Py_None;\n\tPyObject *swap=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, \"|OOOO\", kwlist,\n\t\t\t\t\t &write, &swap, &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 if (swap != Py_None) {\n if (PyObject_IsTrue(swap))\n self->flags &= ~NOTSWAPPED;\n else \n self->flags |= NOTSWAPPED;\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic PyMethodDef array_methods[] = {\n {\"tolist\",\t (PyCFunction)array_tolist,\t1, doc_tolist},\n {\"toscalar\", (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 {\"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, doc_sort},\n\t{\"argsort\",\t(PyCFunction)array_argsort, \n\t METH_VARARGS, 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{\"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 {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": 7, "end_line": 20, "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": 26, "end_line": 34, "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": 41, "end_line": 50, "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": 56, "end_line": 66, "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": 70, "end_line": 84, "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": 47, "complexity": 13, "token_count": 290, "parameters": [ "self", "args" ], "start_line": 92, "end_line": 141, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "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": 146, "end_line": 150, "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": 8, "complexity": 2, "token_count": 53, "parameters": [ "self", "args" ], "start_line": 157, "end_line": 165, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "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": 170, "end_line": 178, "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": 183, "end_line": 191, "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": 196, "end_line": 204, "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": 209, "end_line": 217, "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": 223, "end_line": 231, "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": 237, "end_line": 244, "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_Typecode * type , int offset)", "filename": "arraymethods.c", "nloc": 14, "complexity": 2, "token_count": 110, "parameters": [ "self", "type", "offset" ], "start_line": 252, "end_line": 265, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "array_getfield", "long_name": "array_getfield( PyArrayObject * self , PyObject * args , PyObject * kwds)", "filename": "arraymethods.c", "nloc": 15, "complexity": 3, "token_count": 110, "parameters": [ "self", "args", "kwds" ], "start_line": 268, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "PyArray_Byteswap", "long_name": "PyArray_Byteswap( PyArrayObject * self , Bool inplace)", "filename": "arraymethods.c", "nloc": 41, "complexity": 7, "token_count": 247, "parameters": [ "self", "inplace" ], "start_line": 288, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "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": 348, "end_line": 356, "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": 362, "end_line": 372, "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": 378, "end_line": 382, "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": 206, "parameters": [ "self", "args", "kwds" ], "start_line": 387, "end_line": 421, "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": 69, "parameters": [ "self", "args" ], "start_line": 427, "end_line": 436, "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": 11, "complexity": 4, "token_count": 82, "parameters": [ "self", "args" ], "start_line": 443, "end_line": 455, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "array_wraparray", "long_name": "array_wraparray( PyArrayObject * self , PyObject * args)", "filename": "arraymethods.c", "nloc": 25, "complexity": 4, "token_count": 144, "parameters": [ "self", "args" ], "start_line": 463, "end_line": 489, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "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": 493, "end_line": 497, "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": 242, "parameters": [ "self", "args" ], "start_line": 503, "end_line": 546, "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": 5, "complexity": 2, "token_count": 34, "parameters": [ "self", "args" ], "start_line": 551, "end_line": 556, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "array_resize", "long_name": "array_resize( PyArrayObject * self , PyObject * args)", "filename": "arraymethods.c", "nloc": 25, "complexity": 5, "token_count": 120, "parameters": [ "self", "args" ], "start_line": 564, "end_line": 589, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "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": 75, "parameters": [ "self", "args", "kwds" ], "start_line": 597, "end_line": 607, "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": 617, "end_line": 632, "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)", "filename": "arraymethods.c", "nloc": 7, "complexity": 2, "token_count": 46, "parameters": [ "self", "args" ], "start_line": 637, "end_line": 645, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "array_argsort", "long_name": "array_argsort( PyArrayObject * self , PyObject * args)", "filename": "arraymethods.c", "nloc": 7, "complexity": 2, "token_count": 46, "parameters": [ "self", "args" ], "start_line": 653, "end_line": 661, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "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": 673, "end_line": 680, "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": 685, "end_line": 718, "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": 722, "end_line": 741, "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": 113, "parameters": [ "self", "list" ], "start_line": 744, "end_line": 762, "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": 45, "complexity": 8, "token_count": 301, "parameters": [ "self", "args" ], "start_line": 768, "end_line": 831, "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": 88, "complexity": 17, "token_count": 534, "parameters": [ "self", "args" ], "start_line": 846, "end_line": 951, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 106, "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": 954, "end_line": 975, "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": 978, "end_line": 989, "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": 995, "end_line": 1006, "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": 1011, "end_line": 1016, "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": 9, "complexity": 3, "token_count": 65, "parameters": [ "self", "args" ], "start_line": 1022, "end_line": 1032, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "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": 89, "parameters": [ "self", "args", "kwds" ], "start_line": 1037, "end_line": 1049, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1054, "end_line": 1066, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1072, "end_line": 1084, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1089, "end_line": 1101, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1107, "end_line": 1119, "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": 1125, "end_line": 1133, "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": 1138, "end_line": 1146, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1152, "end_line": 1164, "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": 1169, "end_line": 1180, "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": 1186, "end_line": 1191, "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": 11, "complexity": 2, "token_count": 109, "parameters": [ "self", "args", "kwds" ], "start_line": 1197, "end_line": 1209, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 1215, "end_line": 1225, "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": 1232, "end_line": 1238, "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": 1244, "end_line": 1254, "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": 8, "complexity": 2, "token_count": 46, "parameters": [ "self", "args" ], "start_line": 1259, "end_line": 1268, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "array_ravel", "long_name": "array_ravel( PyArrayObject * self , PyObject * args)", "filename": "arraymethods.c", "nloc": 7, "complexity": 2, "token_count": 46, "parameters": [ "self", "args" ], "start_line": 1273, "end_line": 1281, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "array_setflags", "long_name": "array_setflags( PyArrayObject * self , PyObject * args , PyObject * kwds)", "filename": "arraymethods.c", "nloc": 60, "complexity": 12, "token_count": 299, "parameters": [ "self", "args", "kwds" ], "start_line": 1291, "end_line": 1355, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 65, "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": 7, "end_line": 20, "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": 26, "end_line": 34, "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": 41, "end_line": 50, "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": 56, "end_line": 66, "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": 70, "end_line": 84, "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": 47, "complexity": 13, "token_count": 290, "parameters": [ "self", "args" ], "start_line": 92, "end_line": 141, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "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": 146, "end_line": 150, "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": 8, "complexity": 2, "token_count": 53, "parameters": [ "self", "args" ], "start_line": 157, "end_line": 165, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "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": 170, "end_line": 178, "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": 183, "end_line": 191, "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": 196, "end_line": 204, "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": 209, "end_line": 217, "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": 223, "end_line": 231, "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": 237, "end_line": 244, "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_Typecode * type , int offset)", "filename": "arraymethods.c", "nloc": 14, "complexity": 2, "token_count": 110, "parameters": [ "self", "type", "offset" ], "start_line": 252, "end_line": 265, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "array_getfield", "long_name": "array_getfield( PyArrayObject * self , PyObject * args , PyObject * kwds)", "filename": "arraymethods.c", "nloc": 15, "complexity": 3, "token_count": 110, "parameters": [ "self", "args", "kwds" ], "start_line": 268, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "PyArray_Byteswap", "long_name": "PyArray_Byteswap( PyArrayObject * self , Bool inplace)", "filename": "arraymethods.c", "nloc": 41, "complexity": 7, "token_count": 247, "parameters": [ "self", "inplace" ], "start_line": 288, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "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": 348, "end_line": 356, "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": 362, "end_line": 372, "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": 378, "end_line": 382, "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": 206, "parameters": [ "self", "args", "kwds" ], "start_line": 387, "end_line": 421, "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": 4, "complexity": 2, "token_count": 39, "parameters": [ "self", "args" ], "start_line": 427, "end_line": 430, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "array_cast", "long_name": "array_cast( PyArrayObject * self , PyObject * args)", "filename": "arraymethods.c", "nloc": 11, "complexity": 4, "token_count": 82, "parameters": [ "self", "args" ], "start_line": 437, "end_line": 449, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "array_wraparray", "long_name": "array_wraparray( PyArrayObject * self , PyObject * args)", "filename": "arraymethods.c", "nloc": 25, "complexity": 4, "token_count": 144, "parameters": [ "self", "args" ], "start_line": 457, "end_line": 483, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "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": 487, "end_line": 491, "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": 242, "parameters": [ "self", "args" ], "start_line": 497, "end_line": 540, "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": 5, "complexity": 2, "token_count": 34, "parameters": [ "self", "args" ], "start_line": 545, "end_line": 550, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "array_resize", "long_name": "array_resize( PyArrayObject * self , PyObject * args)", "filename": "arraymethods.c", "nloc": 25, "complexity": 5, "token_count": 120, "parameters": [ "self", "args" ], "start_line": 558, "end_line": 583, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "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": 75, "parameters": [ "self", "args", "kwds" ], "start_line": 591, "end_line": 601, "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": 611, "end_line": 626, "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)", "filename": "arraymethods.c", "nloc": 7, "complexity": 2, "token_count": 46, "parameters": [ "self", "args" ], "start_line": 631, "end_line": 639, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "array_argsort", "long_name": "array_argsort( PyArrayObject * self , PyObject * args)", "filename": "arraymethods.c", "nloc": 7, "complexity": 2, "token_count": 46, "parameters": [ "self", "args" ], "start_line": 647, "end_line": 655, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "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": 667, "end_line": 674, "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": 679, "end_line": 712, "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": 716, "end_line": 735, "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": 113, "parameters": [ "self", "list" ], "start_line": 738, "end_line": 756, "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": 45, "complexity": 8, "token_count": 301, "parameters": [ "self", "args" ], "start_line": 762, "end_line": 825, "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": 88, "complexity": 17, "token_count": 534, "parameters": [ "self", "args" ], "start_line": 840, "end_line": 945, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 106, "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": 948, "end_line": 969, "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": 972, "end_line": 983, "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": 989, "end_line": 1000, "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": 1005, "end_line": 1010, "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": 9, "complexity": 3, "token_count": 65, "parameters": [ "self", "args" ], "start_line": 1016, "end_line": 1026, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "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": 89, "parameters": [ "self", "args", "kwds" ], "start_line": 1031, "end_line": 1043, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1048, "end_line": 1060, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1066, "end_line": 1078, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1083, "end_line": 1095, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1101, "end_line": 1113, "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": 1119, "end_line": 1127, "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": 1132, "end_line": 1140, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1146, "end_line": 1158, "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": 1163, "end_line": 1174, "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": 1180, "end_line": 1185, "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": 11, "complexity": 2, "token_count": 109, "parameters": [ "self", "args", "kwds" ], "start_line": 1191, "end_line": 1203, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 1209, "end_line": 1219, "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": 1226, "end_line": 1232, "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": 1238, "end_line": 1248, "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": 8, "complexity": 2, "token_count": 46, "parameters": [ "self", "args" ], "start_line": 1253, "end_line": 1262, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "array_ravel", "long_name": "array_ravel( PyArrayObject * self , PyObject * args)", "filename": "arraymethods.c", "nloc": 7, "complexity": 2, "token_count": 46, "parameters": [ "self", "args" ], "start_line": 1267, "end_line": 1275, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "array_setflags", "long_name": "array_setflags( PyArrayObject * self , PyObject * args , PyObject * kwds)", "filename": "arraymethods.c", "nloc": 60, "complexity": 12, "token_count": 299, "parameters": [ "self", "args", "kwds" ], "start_line": 1285, "end_line": 1349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 65, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "array_toscalar", "long_name": "array_toscalar( PyArrayObject * self , PyObject * args)", "filename": "arraymethods.c", "nloc": 10, "complexity": 4, "token_count": 69, "parameters": [ "self", "args" ], "start_line": 427, "end_line": 436, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 } ], "nloc": 1156, "complexity": 205, "token_count": 7363, "diff_parsed": { "added": [ "\tif (self->nd == 0 || PyArray_SIZE(self) == 1)", "\t\treturn self->descr->getitem(self->data, self);", "\telse {", "\t\tPyErr_SetString(PyExc_ValueError, \"can only convert an\"\t\\", "\t\t\t\t\" array of size 1 to Python scalar.\");", "\t\treturn NULL;", "\t}" ], "deleted": [ " return self->descr->getitem(self->data, self);" ] } } ] }, { "hash": "9e2b9a429169902426dc07156f0414d2ec63a8c6", "msg": "Fix segfault with Character arrays.", "author": { "name": "Travis Oliphant", "email": "oliphant@enthought.com" }, "committer": { "name": "Travis Oliphant", "email": "oliphant@enthought.com" }, "author_date": "2005-10-26T03:31:22+00:00", "author_timezone": 0, "committer_date": "2005-10-26T03:31:22+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "33616f8e0e2574ce73442bf257dba723f812b572" ], "project_name": "repo_copy", "project_path": "/tmp/tmpn4cqam_6/repo_copy", "deletions": 3, "insertions": 8, "lines": 11, "files": 2, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.5, "dmm_unit_interfacing": 0.5, "modified_files": [ { "old_path": "scipy/base/numeric.py", "new_path": "scipy/base/numeric.py", "filename": "numeric.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -196,6 +196,8 @@ def array_repr(arr, max_line_width=None, precision=None, suppress_small=None):\n return cName + \"(%s)\" % lst\n else:\n typename=arr.dtype.__name__[:-8]\n+ if issubclass(arr.dtype, flexible):\n+ typename = \"%s%d\" % (typename, arr.itemsize) \n return cName + \"(%s, dtype=%s)\" % (lst, typename)\n \n def array_str(a, max_line_width = None, precision = None, suppress_small = None):\n", "added_lines": 2, "deleted_lines": 0, "source_code": "\nimport sys\nimport types, math\n\nimport multiarray\nimport umath\nfrom umath import *\nfrom numerictypes import *\nfrom _compiled_base import _insert\n\nnewaxis = None\n\nndarray = multiarray.ndarray\nbigndarray = multiarray.bigndarray\nflatiter = multiarray.flatiter\nufunc = type(sin)\n\narange = multiarray.arange\narray = multiarray.array\nzeros = multiarray.zeros\nempty = multiarray.empty\nfromstring = multiarray.fromstring\nfromfile = multiarray.fromfile\nfrombuffer = multiarray.frombuffer\nwhere = multiarray.where\nconcatenate = multiarray.concatenate\nfastCopyAndTranspose = multiarray._fastCopyAndTranspose\nregister_dtype = multiarray.register_dtype\ncan_cast = multiarray.can_cast\n\ndef asarray(a, dtype=None, fortran=False):\n \"\"\"returns a as an array. Unlike array(),\n no copy is performed if a is already an array. Subclasses are converted\n to base class ndarray.\n \"\"\"\n return array(a, dtype, copy=False, fortran=fortran)\n\ndef asanyarray(a, dtype=None,copy=False,fortran=False):\n \"\"\"will pass subclasses through...\n \"\"\"\n return array(a, dtype, copy=False, fortran=fortran, subok=1)\n\ndef isfortran(a):\n return a.flags['FNC']\n\n# from Fernando Perez's IPython\ndef zeros_like(a):\n \"\"\"Return an array of zeros of the shape and typecode of a.\n\n If you don't explicitly need the array to be zeroed, you should instead\n use empty_like(), which is faster as it only allocates memory.\"\"\"\n \n a = asanyarray(a)\n return a.__array_wrap__(zeros(a.shape,a.dtype, a.flags['FNC']))\n\ndef empty_like(a):\n \"\"\"Return an empty (uninitialized) array of the shape and typecode of a.\n\n Note that this does NOT initialize the returned array. If you require\n your array to be initialized, you should use zeros_like().\n\n \"\"\"\n a = asanyarray(a)\n return a.__array_wrap__(empty(a.shape,a.dtype, a.flags['FNC']))\n\n# end Fernando's utilities\n\n_mode_from_name_dict = {'v': 0,\n 's' : 1,\n 'f' : 2}\n\ndef _mode_from_name(mode):\n if isinstance(mode, type(\"\")):\n return _mode_from_name_dict[mode.lower()[0]]\n return mode\n \ndef correlate(a,v,mode='valid'):\n mode = _mode_from_name(mode)\n return multiarray.correlate(a,v,mode)\n\n\ndef convolve(a,v,mode='full'):\n \"\"\"Returns the discrete, linear convolution of 1-D\n sequences a and v; mode can be 0 (valid), 1 (same), or 2 (full)\n to specify size of the resulting sequence.\n \"\"\"\n if (len(v) > len(a)):\n a, v = v, a\n mode = _mode_from_name(mode)\n return correlate(a,asarray(v)[::-1],mode)\n\n\ninner = multiarray.inner\ndot = multiarray.dot\n\ndef outer(a,b):\n \"\"\"outer(a,b) returns the outer product of two vectors.\n result(i,j) = a(i)*b(j) when a and b are vectors\n Will accept any arguments that can be made into vectors.\n \"\"\"\n a = asarray(a)\n b = asarray(b)\n return a.ravel()[:,newaxis]*b.ravel()[newaxis,:]\n\ndef vdot(a, b):\n \"\"\"Returns the dot product of 2 vectors (or anything that can be made into\n a vector). NB: this is not the same as `dot`, as it takes the conjugate\n of its first argument if complex and always returns a scalar.\"\"\"\n return dot(asarray(a).ravel().conj(), asarray(b).ravel())\n\n# try to import blas optimized dot if available\ntry:\n # importing this changes the dot function for basic 4 types\n # to blas-optimized versions.\n from scipy.lib._dotblas import dot, vdot, inner, alterdot, restoredot\nexcept ImportError:\n def alterdot():\n pass\n def restoredot():\n pass\n\n\ndef _move_axis_to_0(a, axis):\n if axis == 0:\n return a\n n = a.ndim\n if axis < 0:\n axis += n\n axes = range(1, axis+1) + [0,] + range(axis+1, n)\n return a.transpose(axes)\n\ndef cross(a, b, axisa=-1, axisb=-1, axisc=-1):\n \"\"\"Return the cross product of two (arrays of) vectors.\n\n The cross product is performed over the last axis of a and b by default,\n and can handle axes with dimensions 2 and 3. For a dimension of 2,\n the z-component of the equivalent three-dimensional cross product is\n returned.\n \"\"\"\n a = _move_axis_to_0(asarray(a), axisa)\n b = _move_axis_to_0(asarray(b), axisb)\n msg = \"incompatible dimensions for cross product\\n\"\\\n \"(dimension must be 2 or 3)\"\n if (a.shape[0] not in [2,3]) or (b.shape[0] not in [2,3]):\n raise ValueError(msg)\n if a.shape[0] == 2:\n if (b.shape[0] == 2):\n cp = a[0]*b[1] - a[1]*b[0]\n if cp.ndim == 0:\n return cp\n else:\n return cp.swapaxes(0,axisc)\n else:\n x = a[1]*b[2]\n y = -a[0]*b[2]\n z = a[0]*b[1] - a[1]*b[0]\n elif a.shape[0] == 3:\n if (b.shape[0] == 3):\n x = a[1]*b[2] - a[2]*b[1]\n y = a[2]*b[0] - a[0]*b[2]\n z = a[0]*b[1] - a[1]*b[0]\n else:\n x = -a[2]*b[1]\n y = a[2]*b[0]\n z = a[0]*b[1] - a[1]*b[0]\n cp = array([x,y,z])\n if cp.ndim == 1:\n return cp\n else:\n return cp.swapaxes(0,axisc)\n \n\n#Use numarray's printing function\nfrom arrayprint import array2string, get_printoptions, set_printoptions\n\n_typelessdata = [int_, float_, complex_]\nif issubclass(intc, int):\n _typelessdata.append(intc)\n\nif issubclass(longlong, int):\n _typelessdata.append(longlong)\n\ndef array_repr(arr, max_line_width=None, precision=None, suppress_small=None):\n if arr.size > 0 or arr.shape==(0,):\n lst = array2string(arr, max_line_width, precision, suppress_small,\n ', ', \"array(\")\n else: # show zero-length shape unless it is (0,)\n lst = \"[], shape=%s\" % (repr(arr.shape),)\n typeless = arr.dtype in _typelessdata\n\n if arr.__class__ is not ndarray:\n cName= arr.__class__.__name__\n else:\n cName = \"array\"\n if typeless and arr.size:\n return cName + \"(%s)\" % lst\n else:\n typename=arr.dtype.__name__[:-8]\n if issubclass(arr.dtype, flexible):\n typename = \"%s%d\" % (typename, arr.itemsize) \n return cName + \"(%s, dtype=%s)\" % (lst, typename)\n\ndef array_str(a, max_line_width = None, precision = None, suppress_small = None):\n return array2string(a, max_line_width, precision, suppress_small, ' ', \"\")\n\nset_string_function = multiarray.set_string_function\nset_string_function(array_str, 0)\nset_string_function(array_repr, 1)\n\n\nlittle_endian = (sys.byteorder == 'little')\n\ndef indices(dimensions, dtype=int_):\n \"\"\"indices(dimensions,dtype=int_) returns an array representing a grid\n of indices with row-only, and column-only variation.\n \"\"\"\n tmp = ones(dimensions, dtype)\n lst = []\n for i in range(len(dimensions)):\n lst.append( add.accumulate(tmp, i, )-1 )\n return array(lst)\n\ndef fromfunction(function, dimensions, **kwargs):\n \"\"\"fromfunction(function, dimensions) returns an array constructed by\n calling function on a tuple of number grids. The function should\n accept as many arguments as there are dimensions which is a list of\n numbers indicating the length of the desired output for each axis.\n\n The function can also accept keyword arguments which will be\n passed in as well. \n \"\"\"\n args = indices(dimensions)\n return function(*args,**kwargs)\n \n\nfrom cPickle import load, loads\n_cload = load\n_file = file\n\ndef load(file):\n if isinstance(file, type(\"\")):\n file = _file(file,\"rb\")\n return _cload(file)\n\n\n# These are all essentially abbreviations\n# These might wind up in a special abbreviations module\n\ndef ones(shape, dtype=int_, fortran=False):\n \"\"\"ones(shape, dtype=int_) returns an array of the given\n dimensions which is initialized to all ones. \n \"\"\"\n # This appears to be slower...\n #a = empty(shape, dtype, fortran)\n #a.fill(1)\n a = zeros(shape, dtype, fortran)\n a+=1\n return a\n \ndef identity(n,dtype=int_):\n \"\"\"identity(n) returns the identity matrix of shape n x n.\n \"\"\"\n a = array([1]+n*[0],dtype=dtype)\n b = empty((n,n),dtype=dtype)\n b.flat = a\n return b\n\ndef allclose (a, b, rtol=1.e-5, atol=1.e-8):\n \"\"\" allclose(a,b,rtol=1.e-5,atol=1.e-8)\n Returns true if all components of a and b are equal\n subject to given tolerances.\n The relative error rtol must be positive and << 1.0\n The absolute error atol comes into play for those elements\n of y that are very small or zero; it says how small x must be also.\n \"\"\"\n x = array(a, copy=False)\n y = array(b, copy=False)\n d = less(absolute(x-y), atol + rtol * absolute(y))\n return alltrue(ravel(d))\n \n\ndef _setpyvals(lst, frame, where=0):\n if not isinstance(lst, list) or len(lst) != 3:\n raise ValueError, \"Invalid pyvalues (length 3 list needed).\"\n\n try:\n wh = where.lower()[0]\n except (AttributeError, TypeError, IndexError):\n wh = None\n\n if where==0 or wh == 'l':\n frame.f_locals[UFUNC_PYVALS_NAME] = lst\n elif where == 1 or wh == 'g':\n frame.f_globals[UFUNC_PYVALS_NAME] = lst\n elif where == 2 or wh == 'b':\n frame.f_builtins[UFUNC_PYVALS_NAME] = lst \n\n return\n\ndef _getpyvals(frame):\n try:\n return frame.f_locals[UFUNC_PYVALS_NAME]\n except KeyError:\n try:\n return frame.f_globals[UFUNC_PYVALS_NAME]\n except KeyError:\n try:\n return frame.f_builtins[UFUNC_PYVALS_NAME]\n except KeyError:\n return [UFUNC_BUFSIZE_DEFAULT, ERR_DEFAULT, None]\n \n\n\n_errdict = {\"ignore\":ERR_IGNORE,\n \"warn\":ERR_WARN,\n \"raise\":ERR_RAISE,\n \"call\":ERR_CALL}\n\n_errdict_rev = {}\nfor key in _errdict.keys():\n _errdict_rev[_errdict[key]] = key\ndel key\n\ndef seterr(divide=\"ignore\", over=\"ignore\", under=\"ignore\", invalid=\"ignore\", where=0):\n maskvalue = (_errdict[divide] << SHIFT_DIVIDEBYZERO) + \\\n (_errdict[over] << SHIFT_OVERFLOW ) + \\\n (_errdict[under] << SHIFT_UNDERFLOW) + \\\n (_errdict[invalid] << SHIFT_INVALID)\n\n frame = sys._getframe().f_back\n pyvals = _getpyvals(frame)\n pyvals[1] = maskvalue\n _setpyvals(pyvals, frame, where) \n \ndef geterr():\n frame = sys._getframe().f_back \n maskvalue = _getpyvals(frame)[1]\n \n mask = 3\n res = {}\n val = (maskvalue >> SHIFT_DIVIDEBYZERO) & mask\n res['divide'] = _errdict_rev[val]\n val = (maskvalue >> SHIFT_OVERFLOW) & mask\n res['over'] = _errdict_rev[val]\n val = (maskvalue >> SHIFT_UNDERFLOW) & mask\n res['under'] = _errdict_rev[val]\n val = (maskvalue >> SHIFT_INVALID) & mask\n res['invalid'] = _errdict_rev[val]\n return res\n\ndef setbufsize(size, where=0):\n if size > 10e6:\n raise ValueError, \"Very big buffers.. %s\" % size\n\n frame = sys._getframe().f_back\n pyvals = _getpyvals(frame)\n pyvals[0] = size\n _setpyvals(pyvals, frame, where)\n\ndef getbufsize():\n frame = sys._getframe().f_back\n return _getpyvals(frame)[0]\n\ndef seterrcall(func, where=0):\n if not callable(func):\n raise ValueError, \"Only callable can be used as callback\"\n frame = sys._getframe().f_back\n pyvals = _getpyvals(frame)\n pyvals[2] = func\n _setpyvals(pyvals, frame, where)\n\ndef geterrcall():\n frame = sys._getframe().f_back\n return _getpyvals(frame)[2] \n\ndef _setdef():\n frame = sys._getframe()\n defval = [UFUNC_BUFSIZE_DEFAULT, ERR_DEFAULT, None]\n frame.f_globals[UFUNC_PYVALS_NAME] = defval\n frame.f_builtins[UFUNC_PYVALS_NAME] = defval \n \n# set the default values\n_setdef()\n\nInf = inf = infty = Infinity = PINF\nnan = NaN = NAN\nfrom oldnumeric import *\n\n\n", "source_code_before": "\nimport sys\nimport types, math\n\nimport multiarray\nimport umath\nfrom umath import *\nfrom numerictypes import *\nfrom _compiled_base import _insert\n\nnewaxis = None\n\nndarray = multiarray.ndarray\nbigndarray = multiarray.bigndarray\nflatiter = multiarray.flatiter\nufunc = type(sin)\n\narange = multiarray.arange\narray = multiarray.array\nzeros = multiarray.zeros\nempty = multiarray.empty\nfromstring = multiarray.fromstring\nfromfile = multiarray.fromfile\nfrombuffer = multiarray.frombuffer\nwhere = multiarray.where\nconcatenate = multiarray.concatenate\nfastCopyAndTranspose = multiarray._fastCopyAndTranspose\nregister_dtype = multiarray.register_dtype\ncan_cast = multiarray.can_cast\n\ndef asarray(a, dtype=None, fortran=False):\n \"\"\"returns a as an array. Unlike array(),\n no copy is performed if a is already an array. Subclasses are converted\n to base class ndarray.\n \"\"\"\n return array(a, dtype, copy=False, fortran=fortran)\n\ndef asanyarray(a, dtype=None,copy=False,fortran=False):\n \"\"\"will pass subclasses through...\n \"\"\"\n return array(a, dtype, copy=False, fortran=fortran, subok=1)\n\ndef isfortran(a):\n return a.flags['FNC']\n\n# from Fernando Perez's IPython\ndef zeros_like(a):\n \"\"\"Return an array of zeros of the shape and typecode of a.\n\n If you don't explicitly need the array to be zeroed, you should instead\n use empty_like(), which is faster as it only allocates memory.\"\"\"\n \n a = asanyarray(a)\n return a.__array_wrap__(zeros(a.shape,a.dtype, a.flags['FNC']))\n\ndef empty_like(a):\n \"\"\"Return an empty (uninitialized) array of the shape and typecode of a.\n\n Note that this does NOT initialize the returned array. If you require\n your array to be initialized, you should use zeros_like().\n\n \"\"\"\n a = asanyarray(a)\n return a.__array_wrap__(empty(a.shape,a.dtype, a.flags['FNC']))\n\n# end Fernando's utilities\n\n_mode_from_name_dict = {'v': 0,\n 's' : 1,\n 'f' : 2}\n\ndef _mode_from_name(mode):\n if isinstance(mode, type(\"\")):\n return _mode_from_name_dict[mode.lower()[0]]\n return mode\n \ndef correlate(a,v,mode='valid'):\n mode = _mode_from_name(mode)\n return multiarray.correlate(a,v,mode)\n\n\ndef convolve(a,v,mode='full'):\n \"\"\"Returns the discrete, linear convolution of 1-D\n sequences a and v; mode can be 0 (valid), 1 (same), or 2 (full)\n to specify size of the resulting sequence.\n \"\"\"\n if (len(v) > len(a)):\n a, v = v, a\n mode = _mode_from_name(mode)\n return correlate(a,asarray(v)[::-1],mode)\n\n\ninner = multiarray.inner\ndot = multiarray.dot\n\ndef outer(a,b):\n \"\"\"outer(a,b) returns the outer product of two vectors.\n result(i,j) = a(i)*b(j) when a and b are vectors\n Will accept any arguments that can be made into vectors.\n \"\"\"\n a = asarray(a)\n b = asarray(b)\n return a.ravel()[:,newaxis]*b.ravel()[newaxis,:]\n\ndef vdot(a, b):\n \"\"\"Returns the dot product of 2 vectors (or anything that can be made into\n a vector). NB: this is not the same as `dot`, as it takes the conjugate\n of its first argument if complex and always returns a scalar.\"\"\"\n return dot(asarray(a).ravel().conj(), asarray(b).ravel())\n\n# try to import blas optimized dot if available\ntry:\n # importing this changes the dot function for basic 4 types\n # to blas-optimized versions.\n from scipy.lib._dotblas import dot, vdot, inner, alterdot, restoredot\nexcept ImportError:\n def alterdot():\n pass\n def restoredot():\n pass\n\n\ndef _move_axis_to_0(a, axis):\n if axis == 0:\n return a\n n = a.ndim\n if axis < 0:\n axis += n\n axes = range(1, axis+1) + [0,] + range(axis+1, n)\n return a.transpose(axes)\n\ndef cross(a, b, axisa=-1, axisb=-1, axisc=-1):\n \"\"\"Return the cross product of two (arrays of) vectors.\n\n The cross product is performed over the last axis of a and b by default,\n and can handle axes with dimensions 2 and 3. For a dimension of 2,\n the z-component of the equivalent three-dimensional cross product is\n returned.\n \"\"\"\n a = _move_axis_to_0(asarray(a), axisa)\n b = _move_axis_to_0(asarray(b), axisb)\n msg = \"incompatible dimensions for cross product\\n\"\\\n \"(dimension must be 2 or 3)\"\n if (a.shape[0] not in [2,3]) or (b.shape[0] not in [2,3]):\n raise ValueError(msg)\n if a.shape[0] == 2:\n if (b.shape[0] == 2):\n cp = a[0]*b[1] - a[1]*b[0]\n if cp.ndim == 0:\n return cp\n else:\n return cp.swapaxes(0,axisc)\n else:\n x = a[1]*b[2]\n y = -a[0]*b[2]\n z = a[0]*b[1] - a[1]*b[0]\n elif a.shape[0] == 3:\n if (b.shape[0] == 3):\n x = a[1]*b[2] - a[2]*b[1]\n y = a[2]*b[0] - a[0]*b[2]\n z = a[0]*b[1] - a[1]*b[0]\n else:\n x = -a[2]*b[1]\n y = a[2]*b[0]\n z = a[0]*b[1] - a[1]*b[0]\n cp = array([x,y,z])\n if cp.ndim == 1:\n return cp\n else:\n return cp.swapaxes(0,axisc)\n \n\n#Use numarray's printing function\nfrom arrayprint import array2string, get_printoptions, set_printoptions\n\n_typelessdata = [int_, float_, complex_]\nif issubclass(intc, int):\n _typelessdata.append(intc)\n\nif issubclass(longlong, int):\n _typelessdata.append(longlong)\n\ndef array_repr(arr, max_line_width=None, precision=None, suppress_small=None):\n if arr.size > 0 or arr.shape==(0,):\n lst = array2string(arr, max_line_width, precision, suppress_small,\n ', ', \"array(\")\n else: # show zero-length shape unless it is (0,)\n lst = \"[], shape=%s\" % (repr(arr.shape),)\n typeless = arr.dtype in _typelessdata\n\n if arr.__class__ is not ndarray:\n cName= arr.__class__.__name__\n else:\n cName = \"array\"\n if typeless and arr.size:\n return cName + \"(%s)\" % lst\n else:\n typename=arr.dtype.__name__[:-8]\n return cName + \"(%s, dtype=%s)\" % (lst, typename)\n\ndef array_str(a, max_line_width = None, precision = None, suppress_small = None):\n return array2string(a, max_line_width, precision, suppress_small, ' ', \"\")\n\nset_string_function = multiarray.set_string_function\nset_string_function(array_str, 0)\nset_string_function(array_repr, 1)\n\n\nlittle_endian = (sys.byteorder == 'little')\n\ndef indices(dimensions, dtype=int_):\n \"\"\"indices(dimensions,dtype=int_) returns an array representing a grid\n of indices with row-only, and column-only variation.\n \"\"\"\n tmp = ones(dimensions, dtype)\n lst = []\n for i in range(len(dimensions)):\n lst.append( add.accumulate(tmp, i, )-1 )\n return array(lst)\n\ndef fromfunction(function, dimensions, **kwargs):\n \"\"\"fromfunction(function, dimensions) returns an array constructed by\n calling function on a tuple of number grids. The function should\n accept as many arguments as there are dimensions which is a list of\n numbers indicating the length of the desired output for each axis.\n\n The function can also accept keyword arguments which will be\n passed in as well. \n \"\"\"\n args = indices(dimensions)\n return function(*args,**kwargs)\n \n\nfrom cPickle import load, loads\n_cload = load\n_file = file\n\ndef load(file):\n if isinstance(file, type(\"\")):\n file = _file(file,\"rb\")\n return _cload(file)\n\n\n# These are all essentially abbreviations\n# These might wind up in a special abbreviations module\n\ndef ones(shape, dtype=int_, fortran=False):\n \"\"\"ones(shape, dtype=int_) returns an array of the given\n dimensions which is initialized to all ones. \n \"\"\"\n # This appears to be slower...\n #a = empty(shape, dtype, fortran)\n #a.fill(1)\n a = zeros(shape, dtype, fortran)\n a+=1\n return a\n \ndef identity(n,dtype=int_):\n \"\"\"identity(n) returns the identity matrix of shape n x n.\n \"\"\"\n a = array([1]+n*[0],dtype=dtype)\n b = empty((n,n),dtype=dtype)\n b.flat = a\n return b\n\ndef allclose (a, b, rtol=1.e-5, atol=1.e-8):\n \"\"\" allclose(a,b,rtol=1.e-5,atol=1.e-8)\n Returns true if all components of a and b are equal\n subject to given tolerances.\n The relative error rtol must be positive and << 1.0\n The absolute error atol comes into play for those elements\n of y that are very small or zero; it says how small x must be also.\n \"\"\"\n x = array(a, copy=False)\n y = array(b, copy=False)\n d = less(absolute(x-y), atol + rtol * absolute(y))\n return alltrue(ravel(d))\n \n\ndef _setpyvals(lst, frame, where=0):\n if not isinstance(lst, list) or len(lst) != 3:\n raise ValueError, \"Invalid pyvalues (length 3 list needed).\"\n\n try:\n wh = where.lower()[0]\n except (AttributeError, TypeError, IndexError):\n wh = None\n\n if where==0 or wh == 'l':\n frame.f_locals[UFUNC_PYVALS_NAME] = lst\n elif where == 1 or wh == 'g':\n frame.f_globals[UFUNC_PYVALS_NAME] = lst\n elif where == 2 or wh == 'b':\n frame.f_builtins[UFUNC_PYVALS_NAME] = lst \n\n return\n\ndef _getpyvals(frame):\n try:\n return frame.f_locals[UFUNC_PYVALS_NAME]\n except KeyError:\n try:\n return frame.f_globals[UFUNC_PYVALS_NAME]\n except KeyError:\n try:\n return frame.f_builtins[UFUNC_PYVALS_NAME]\n except KeyError:\n return [UFUNC_BUFSIZE_DEFAULT, ERR_DEFAULT, None]\n \n\n\n_errdict = {\"ignore\":ERR_IGNORE,\n \"warn\":ERR_WARN,\n \"raise\":ERR_RAISE,\n \"call\":ERR_CALL}\n\n_errdict_rev = {}\nfor key in _errdict.keys():\n _errdict_rev[_errdict[key]] = key\ndel key\n\ndef seterr(divide=\"ignore\", over=\"ignore\", under=\"ignore\", invalid=\"ignore\", where=0):\n maskvalue = (_errdict[divide] << SHIFT_DIVIDEBYZERO) + \\\n (_errdict[over] << SHIFT_OVERFLOW ) + \\\n (_errdict[under] << SHIFT_UNDERFLOW) + \\\n (_errdict[invalid] << SHIFT_INVALID)\n\n frame = sys._getframe().f_back\n pyvals = _getpyvals(frame)\n pyvals[1] = maskvalue\n _setpyvals(pyvals, frame, where) \n \ndef geterr():\n frame = sys._getframe().f_back \n maskvalue = _getpyvals(frame)[1]\n \n mask = 3\n res = {}\n val = (maskvalue >> SHIFT_DIVIDEBYZERO) & mask\n res['divide'] = _errdict_rev[val]\n val = (maskvalue >> SHIFT_OVERFLOW) & mask\n res['over'] = _errdict_rev[val]\n val = (maskvalue >> SHIFT_UNDERFLOW) & mask\n res['under'] = _errdict_rev[val]\n val = (maskvalue >> SHIFT_INVALID) & mask\n res['invalid'] = _errdict_rev[val]\n return res\n\ndef setbufsize(size, where=0):\n if size > 10e6:\n raise ValueError, \"Very big buffers.. %s\" % size\n\n frame = sys._getframe().f_back\n pyvals = _getpyvals(frame)\n pyvals[0] = size\n _setpyvals(pyvals, frame, where)\n\ndef getbufsize():\n frame = sys._getframe().f_back\n return _getpyvals(frame)[0]\n\ndef seterrcall(func, where=0):\n if not callable(func):\n raise ValueError, \"Only callable can be used as callback\"\n frame = sys._getframe().f_back\n pyvals = _getpyvals(frame)\n pyvals[2] = func\n _setpyvals(pyvals, frame, where)\n\ndef geterrcall():\n frame = sys._getframe().f_back\n return _getpyvals(frame)[2] \n\ndef _setdef():\n frame = sys._getframe()\n defval = [UFUNC_BUFSIZE_DEFAULT, ERR_DEFAULT, None]\n frame.f_globals[UFUNC_PYVALS_NAME] = defval\n frame.f_builtins[UFUNC_PYVALS_NAME] = defval \n \n# set the default values\n_setdef()\n\nInf = inf = infty = Infinity = PINF\nnan = NaN = NAN\nfrom oldnumeric import *\n\n\n", "methods": [ { "name": "asarray", "long_name": "asarray( a , dtype = None , fortran = False )", "filename": "numeric.py", "nloc": 2, "complexity": 1, "token_count": 29, "parameters": [ "a", "dtype", "fortran" ], "start_line": 31, "end_line": 36, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "asanyarray", "long_name": "asanyarray( a , dtype = None , copy = False , fortran = False )", "filename": "numeric.py", "nloc": 2, "complexity": 1, "token_count": 37, "parameters": [ "a", "dtype", "copy", "fortran" ], "start_line": 38, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "isfortran", "long_name": "isfortran( a )", "filename": "numeric.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "a" ], "start_line": 43, "end_line": 44, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "zeros_like", "long_name": "zeros_like( a )", "filename": "numeric.py", "nloc": 3, "complexity": 1, "token_count": 35, "parameters": [ "a" ], "start_line": 47, "end_line": 54, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "empty_like", "long_name": "empty_like( a )", "filename": "numeric.py", "nloc": 3, "complexity": 1, "token_count": 35, "parameters": [ "a" ], "start_line": 56, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "_mode_from_name", "long_name": "_mode_from_name( mode )", "filename": "numeric.py", "nloc": 4, "complexity": 2, "token_count": 30, "parameters": [ "mode" ], "start_line": 72, "end_line": 75, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "correlate", "long_name": "correlate( a , v , mode = 'valid' )", "filename": "numeric.py", "nloc": 3, "complexity": 1, "token_count": 28, "parameters": [ "a", "v", "mode" ], "start_line": 77, "end_line": 79, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "convolve", "long_name": "convolve( a , v , mode = 'full' )", "filename": "numeric.py", "nloc": 5, "complexity": 2, "token_count": 55, "parameters": [ "a", "v", "mode" ], "start_line": 82, "end_line": 90, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "outer", "long_name": "outer( a , b )", "filename": "numeric.py", "nloc": 4, "complexity": 1, "token_count": 42, "parameters": [ "a", "b" ], "start_line": 96, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "vdot", "long_name": "vdot( a , b )", "filename": "numeric.py", "nloc": 2, "complexity": 1, "token_count": 33, "parameters": [ "a", "b" ], "start_line": 105, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "alterdot", "long_name": "alterdot( )", "filename": "numeric.py", "nloc": 2, "complexity": 1, "token_count": 5, "parameters": [], "start_line": 117, "end_line": 118, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "restoredot", "long_name": "restoredot( )", "filename": "numeric.py", "nloc": 2, "complexity": 1, "token_count": 5, "parameters": [], "start_line": 119, "end_line": 120, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_move_axis_to_0", "long_name": "_move_axis_to_0( a , axis )", "filename": "numeric.py", "nloc": 8, "complexity": 3, "token_count": 58, "parameters": [ "a", "axis" ], "start_line": 123, "end_line": 130, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "cross", "long_name": "cross( a , b , axisa = - 1 , axisb = - 1 , axisc = - 1 )", "filename": "numeric.py", "nloc": 32, "complexity": 9, "token_count": 360, "parameters": [ "a", "b", "axisa", "axisb", "axisc" ], "start_line": 132, "end_line": 170, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "top_nesting_level": 0 }, { "name": "array_repr", "long_name": "array_repr( arr , max_line_width = None , precision = None , suppress_small = None )", "filename": "numeric.py", "nloc": 18, "complexity": 7, "token_count": 149, "parameters": [ "arr", "max_line_width", "precision", "suppress_small" ], "start_line": 183, "end_line": 201, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "array_str", "long_name": "array_str( a , max_line_width = None , precision = None , suppress_small = None )", "filename": "numeric.py", "nloc": 2, "complexity": 1, "token_count": 32, "parameters": [ "a", "max_line_width", "precision", "suppress_small" ], "start_line": 203, "end_line": 204, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "indices", "long_name": "indices( dimensions , dtype = int_ )", "filename": "numeric.py", "nloc": 6, "complexity": 2, "token_count": 54, "parameters": [ "dimensions", "dtype" ], "start_line": 213, "end_line": 221, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "fromfunction", "long_name": "fromfunction( function , dimensions , ** kwargs )", "filename": "numeric.py", "nloc": 3, "complexity": 1, "token_count": 26, "parameters": [ "function", "dimensions", "kwargs" ], "start_line": 223, "end_line": 233, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "load", "long_name": "load( file )", "filename": "numeric.py", "nloc": 4, "complexity": 2, "token_count": 29, "parameters": [ "file" ], "start_line": 240, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "ones", "long_name": "ones( shape , dtype = int_ , fortran = False )", "filename": "numeric.py", "nloc": 4, "complexity": 1, "token_count": 29, "parameters": [ "shape", "dtype", "fortran" ], "start_line": 249, "end_line": 258, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "identity", "long_name": "identity( n , dtype = int_ )", "filename": "numeric.py", "nloc": 5, "complexity": 1, "token_count": 49, "parameters": [ "n", "dtype" ], "start_line": 260, "end_line": 266, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "allclose", "long_name": "allclose( a , b , rtol = 1 . e - 5 , atol = 1 . e - 8 )", "filename": "numeric.py", "nloc": 5, "complexity": 1, "token_count": 72, "parameters": [ "a", "b", "rtol", "atol" ], "start_line": 268, "end_line": 279, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "_setpyvals", "long_name": "_setpyvals( lst , frame , where = 0 )", "filename": "numeric.py", "nloc": 14, "complexity": 10, "token_count": 107, "parameters": [ "lst", "frame", "where" ], "start_line": 282, "end_line": 298, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_getpyvals", "long_name": "_getpyvals( frame )", "filename": "numeric.py", "nloc": 11, "complexity": 4, "token_count": 49, "parameters": [ "frame" ], "start_line": 300, "end_line": 310, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "seterr", "long_name": "seterr( divide = \"ignore\" , over = \"ignore\" , under = \"ignore\" , invalid = \"ignore\" , where = 0 )", "filename": "numeric.py", "nloc": 9, "complexity": 1, "token_count": 96, "parameters": [ "divide", "over", "under", "invalid", "where" ], "start_line": 324, "end_line": 333, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "geterr", "long_name": "geterr( )", "filename": "numeric.py", "nloc": 14, "complexity": 1, "token_count": 107, "parameters": [], "start_line": 335, "end_line": 349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "setbufsize", "long_name": "setbufsize( size , where = 0 )", "filename": "numeric.py", "nloc": 7, "complexity": 2, "token_count": 49, "parameters": [ "size", "where" ], "start_line": 351, "end_line": 358, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "getbufsize", "long_name": "getbufsize( )", "filename": "numeric.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [], "start_line": 360, "end_line": 362, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "seterrcall", "long_name": "seterrcall( func , where = 0 )", "filename": "numeric.py", "nloc": 7, "complexity": 2, "token_count": 49, "parameters": [ "func", "where" ], "start_line": 364, "end_line": 370, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "geterrcall", "long_name": "geterrcall( )", "filename": "numeric.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [], "start_line": 372, "end_line": 374, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "_setdef", "long_name": "_setdef( )", "filename": "numeric.py", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [], "start_line": 376, "end_line": 380, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "methods_before": [ { "name": "asarray", "long_name": "asarray( a , dtype = None , fortran = False )", "filename": "numeric.py", "nloc": 2, "complexity": 1, "token_count": 29, "parameters": [ "a", "dtype", "fortran" ], "start_line": 31, "end_line": 36, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "asanyarray", "long_name": "asanyarray( a , dtype = None , copy = False , fortran = False )", "filename": "numeric.py", "nloc": 2, "complexity": 1, "token_count": 37, "parameters": [ "a", "dtype", "copy", "fortran" ], "start_line": 38, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "isfortran", "long_name": "isfortran( a )", "filename": "numeric.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "a" ], "start_line": 43, "end_line": 44, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "zeros_like", "long_name": "zeros_like( a )", "filename": "numeric.py", "nloc": 3, "complexity": 1, "token_count": 35, "parameters": [ "a" ], "start_line": 47, "end_line": 54, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "empty_like", "long_name": "empty_like( a )", "filename": "numeric.py", "nloc": 3, "complexity": 1, "token_count": 35, "parameters": [ "a" ], "start_line": 56, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "_mode_from_name", "long_name": "_mode_from_name( mode )", "filename": "numeric.py", "nloc": 4, "complexity": 2, "token_count": 30, "parameters": [ "mode" ], "start_line": 72, "end_line": 75, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "correlate", "long_name": "correlate( a , v , mode = 'valid' )", "filename": "numeric.py", "nloc": 3, "complexity": 1, "token_count": 28, "parameters": [ "a", "v", "mode" ], "start_line": 77, "end_line": 79, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "convolve", "long_name": "convolve( a , v , mode = 'full' )", "filename": "numeric.py", "nloc": 5, "complexity": 2, "token_count": 55, "parameters": [ "a", "v", "mode" ], "start_line": 82, "end_line": 90, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "outer", "long_name": "outer( a , b )", "filename": "numeric.py", "nloc": 4, "complexity": 1, "token_count": 42, "parameters": [ "a", "b" ], "start_line": 96, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "vdot", "long_name": "vdot( a , b )", "filename": "numeric.py", "nloc": 2, "complexity": 1, "token_count": 33, "parameters": [ "a", "b" ], "start_line": 105, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "alterdot", "long_name": "alterdot( )", "filename": "numeric.py", "nloc": 2, "complexity": 1, "token_count": 5, "parameters": [], "start_line": 117, "end_line": 118, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "restoredot", "long_name": "restoredot( )", "filename": "numeric.py", "nloc": 2, "complexity": 1, "token_count": 5, "parameters": [], "start_line": 119, "end_line": 120, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_move_axis_to_0", "long_name": "_move_axis_to_0( a , axis )", "filename": "numeric.py", "nloc": 8, "complexity": 3, "token_count": 58, "parameters": [ "a", "axis" ], "start_line": 123, "end_line": 130, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "cross", "long_name": "cross( a , b , axisa = - 1 , axisb = - 1 , axisc = - 1 )", "filename": "numeric.py", "nloc": 32, "complexity": 9, "token_count": 360, "parameters": [ "a", "b", "axisa", "axisb", "axisc" ], "start_line": 132, "end_line": 170, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "top_nesting_level": 0 }, { "name": "array_repr", "long_name": "array_repr( arr , max_line_width = None , precision = None , suppress_small = None )", "filename": "numeric.py", "nloc": 16, "complexity": 6, "token_count": 128, "parameters": [ "arr", "max_line_width", "precision", "suppress_small" ], "start_line": 183, "end_line": 199, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "array_str", "long_name": "array_str( a , max_line_width = None , precision = None , suppress_small = None )", "filename": "numeric.py", "nloc": 2, "complexity": 1, "token_count": 32, "parameters": [ "a", "max_line_width", "precision", "suppress_small" ], "start_line": 201, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "indices", "long_name": "indices( dimensions , dtype = int_ )", "filename": "numeric.py", "nloc": 6, "complexity": 2, "token_count": 54, "parameters": [ "dimensions", "dtype" ], "start_line": 211, "end_line": 219, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "fromfunction", "long_name": "fromfunction( function , dimensions , ** kwargs )", "filename": "numeric.py", "nloc": 3, "complexity": 1, "token_count": 26, "parameters": [ "function", "dimensions", "kwargs" ], "start_line": 221, "end_line": 231, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "load", "long_name": "load( file )", "filename": "numeric.py", "nloc": 4, "complexity": 2, "token_count": 29, "parameters": [ "file" ], "start_line": 238, "end_line": 241, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "ones", "long_name": "ones( shape , dtype = int_ , fortran = False )", "filename": "numeric.py", "nloc": 4, "complexity": 1, "token_count": 29, "parameters": [ "shape", "dtype", "fortran" ], "start_line": 247, "end_line": 256, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "identity", "long_name": "identity( n , dtype = int_ )", "filename": "numeric.py", "nloc": 5, "complexity": 1, "token_count": 49, "parameters": [ "n", "dtype" ], "start_line": 258, "end_line": 264, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "allclose", "long_name": "allclose( a , b , rtol = 1 . e - 5 , atol = 1 . e - 8 )", "filename": "numeric.py", "nloc": 5, "complexity": 1, "token_count": 72, "parameters": [ "a", "b", "rtol", "atol" ], "start_line": 266, "end_line": 277, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "_setpyvals", "long_name": "_setpyvals( lst , frame , where = 0 )", "filename": "numeric.py", "nloc": 14, "complexity": 10, "token_count": 107, "parameters": [ "lst", "frame", "where" ], "start_line": 280, "end_line": 296, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_getpyvals", "long_name": "_getpyvals( frame )", "filename": "numeric.py", "nloc": 11, "complexity": 4, "token_count": 49, "parameters": [ "frame" ], "start_line": 298, "end_line": 308, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "seterr", "long_name": "seterr( divide = \"ignore\" , over = \"ignore\" , under = \"ignore\" , invalid = \"ignore\" , where = 0 )", "filename": "numeric.py", "nloc": 9, "complexity": 1, "token_count": 96, "parameters": [ "divide", "over", "under", "invalid", "where" ], "start_line": 322, "end_line": 331, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "geterr", "long_name": "geterr( )", "filename": "numeric.py", "nloc": 14, "complexity": 1, "token_count": 107, "parameters": [], "start_line": 333, "end_line": 347, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "setbufsize", "long_name": "setbufsize( size , where = 0 )", "filename": "numeric.py", "nloc": 7, "complexity": 2, "token_count": 49, "parameters": [ "size", "where" ], "start_line": 349, "end_line": 356, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "getbufsize", "long_name": "getbufsize( )", "filename": "numeric.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [], "start_line": 358, "end_line": 360, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "seterrcall", "long_name": "seterrcall( func , where = 0 )", "filename": "numeric.py", "nloc": 7, "complexity": 2, "token_count": 49, "parameters": [ "func", "where" ], "start_line": 362, "end_line": 368, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "geterrcall", "long_name": "geterrcall( )", "filename": "numeric.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [], "start_line": 370, "end_line": 372, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "_setdef", "long_name": "_setdef( )", "filename": "numeric.py", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [], "start_line": 374, "end_line": 378, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "array_repr", "long_name": "array_repr( arr , max_line_width = None , precision = None , suppress_small = None )", "filename": "numeric.py", "nloc": 18, "complexity": 7, "token_count": 149, "parameters": [ "arr", "max_line_width", "precision", "suppress_small" ], "start_line": 183, "end_line": 201, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 } ], "nloc": 251, "complexity": 65, "token_count": 2069, "diff_parsed": { "added": [ " if issubclass(arr.dtype, flexible):", " typename = \"%s%d\" % (typename, arr.itemsize)" ], "deleted": [] } }, { "old_path": "scipy/base/src/arrayobject.c", "new_path": "scipy/base/src/arrayobject.c", "filename": "arrayobject.c", "extension": "c", "change_type": "MODIFY", "diff": "@@ -4703,10 +4703,13 @@ static PyObject *\n Array_FromScalar(PyObject *op, PyArray_Typecode *typecode) \n {\n PyArrayObject *ret;\n-\tint itemsize = 0;\n-\tint type = typecode->type_num;\n+\tint itemsize; \n+\tint type;\n+\t\n+\titemsize = typecode->itemsize;\n+\ttype = typecode->type_num;\n \n-\tif PyTypeNum_ISFLEXIBLE(type) {\n+\tif (itemsize == 0 && PyTypeNum_ISFLEXIBLE(type)) {\n \t\titemsize = PyObject_Length(op);\n \t}\n \n", "added_lines": 6, "deleted_lines": 3, "source_code": " /*\n Provide multidimensional arrays as a basic object type in python. \n\nBased on Original Numeric implementation\nCopyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\nwith contributions from many Numeric Python developers 1995-2004 *\n\nHeavily modified in 2005 with inspiration from Numarray \n\nby\n\nTravis Oliphant\nAssistant Professor at\nBrigham Young University \n\nmaintainer email: oliphant.travis@ieee.org\n\nNumarray design (which provided guidance) by \nSpace Science Telescope Institute \n (J. Todd Miller, Perry Greenfield, Rick White)\n\n*/\n\n/* $Id: arrayobject.c,v 1.59 2005/09/14 00:14:00 teoliphant Exp $ */\n\n/*\n#include \"Python.h\"\n#include \"structmember.h\"\n\n#define _MULTIARRAYMODULE\n#include \"Numeric3/arrayobject.h\"\n*/\n\n/* Helper functions */\n\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\n\nstatic intp\nPyArray_PyIntAsIntp(PyObject *o)\n{\n\tlonglong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr=NULL;\n\tPyArray_Typecode typecode = {PyArray_INTP, 0, 0};\n\tintp ret;\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\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\tarr = PyArray_CastToType((PyArrayObject *)o, &typecode);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tarr = PyArray_FromScalar(o, &typecode);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((intp *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\t\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONGLONG != SIZEOF_PY_INTPTR_T)\n\tif ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C intp\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (intp) long_value;\n}\n\n\nstatic PyObject *array_int(PyArrayObject *v);\n\nstatic int\nPyArray_PyIntAsInt(PyObject *o)\n{\n\tlong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr=NULL;\n\tPyArray_Typecode typecode = {PyArray_INT, 0, 0};\n\tint ret;\n\t\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\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\tarr = PyArray_CastToType((PyArrayObject *)o, &typecode);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tarr = PyArray_FromScalar(o, &typecode);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((int *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONG != SIZEOF_INT)\n\tif ((long_value < INT_MIN) || (long_value > INT_MAX)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C int\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (int) long_value;\n}\n\n\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\nstatic char *\nPyArray_Zero(PyArrayObject *arr)\n{\n char *zeroval;\n char *buf;\n int buf_len;\n PyObject *obj, *ret;\n\n zeroval = PyDataMem_NEW(arr->itemsize);\n if (zeroval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n if (PyArray_ISOBJECT(arr)) {\n obj=PyInt_FromLong((long) 0);\n memcpy(zeroval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return zeroval;\n }\n ret = PyObject_GetAttrString((PyObject *)arr, \"_zero\");\n if (ret != NULL) {\n if (PyObject_AsReadBuffer(ret, (const void **)&buf, \n &buf_len) < 0) {\n PyErr_SetString(PyExc_ValueError, \n \"_zero not returning \" \\\n \"writeable buffer\");\n Py_DECREF(ret);\n return NULL;\n }\n memcpy(zeroval, buf, buf_len);\n Py_DECREF(ret);\n }\n if (PyErr_Occurred()) PyErr_Clear();\n memset(zeroval, 0, arr->itemsize);\n return zeroval;\n}\n\nstatic char *\nPyArray_One(PyArrayObject *arr)\n{\n char *oneval;\n char *buf;\n int buf_len, ret2;\n PyObject *obj, *ret;\n\n oneval = PyDataMem_NEW(arr->itemsize);\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 ret = PyObject_GetAttrString((PyObject *)arr, \"_one\");\n if (ret != NULL) {\n if (PyObject_AsReadBuffer(ret, (const void **)&buf, \n &buf_len) < 0) {\n PyErr_SetString(PyExc_ValueError, \n \"_one not returning \" \\\n \"writeable buffer\");\n Py_DECREF(ret);\n PyDataMem_FREE(oneval);\n return NULL;\n }\n memcpy(oneval, buf, buf_len);\n Py_DECREF(ret);\n }\n if (PyErr_Occurred()) PyErr_Clear();\n\n ret2 = arr->descr->setitem(obj, oneval, arr);\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->itemsize;\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 *)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 { free(new_data); return NULL; }\n}\n\n/* end Helper functions */\n\n\nstatic PyObject *PyArray_New(PyTypeObject *, int nd, intp *, \n int, intp *, char *, 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. */\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/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\n\nstatic char *\nindex2ptr(PyArrayObject *mp, int i) \n{\n\tif (i==0 && (mp->nd == 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\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\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->copyswap;\n\tcopyswapn = dest->descr->copyswapn;\n\n elsize = dest->itemsize;\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->itemsize;\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\tPyArray_Typecode typecode;\n\n\n\ttypecode.type_num = dest->descr->type_num;\n\ttypecode.itemsize = dest->itemsize;\n\ttypecode.fortran = PyArray_ISFORTRAN(dest);\n\t\t\t\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n\t\t\t\t\t &typecode, 0,\n\t\t\t\t\t dest->nd, 0);\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\nstatic PyObject *\nPyArray_FromDimsAndDataAndDescr(int nd, int *d, \n PyArray_Descr *descr,\n char *data) {\n\tPyObject *ret;\n\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\n\tintp newd[MAX_DIMS];\n\t\n\tfor (i=0; itype_num, NULL, data, descr->elsize, \n\t\t\t CARRAY_FLAGS, NULL);\n#else\n\tret = PyArray_New(&PyArray_Type, nd, (intp *)d, \n descr->type_num, NULL, data, descr->elsize, \n\t\t\t CARRAY_FLAGS, NULL);\n#endif\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_FromDimsAndData(int nd, int *d, int type, char *data) \n{\n\tPyObject *ret;\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\t\n\tintp newd[MAX_DIMS];\n\n\tfor (i=0; iob_type, m1->nd, \n\t\t\t\t\t m1->dimensions,\n\t\t\t\t\t m1->descr->type_num,\n\t\t\t\t\t NULL, NULL, m1->itemsize,\n\t\t\t\t\t 0, (PyObject *)m1);\n\t\n if (PyArray_CopyInto(ret, m1) == -1) return NULL;\n\t\n return (PyObject *)ret;\n}\n\n\nstatic PyObject *array_item(PyArrayObject *, int);\n\nstatic PyObject *\nPyArray_Scalar(char *data, int type_num, int itemsize, int swap)\n{\n PyArray_Descr *descr;\n\tPyTypeObject *type;\n\tPyObject *obj;\t\n\tchar *destptr;\n PyArray_CopySwapFunc *copyswap;\n\n descr = PyArray_DescrFromType(type_num);\n if (descr == NULL) return NULL;\n type = descr->typeobj;\n copyswap = descr->copyswap;\n\tif (type_num == PyArray_STRING) \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_ISFLEXIBLE(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 {\n\t\t\tdestptr = PyDataMem_NEW(itemsize);\n\t\t\tif (destptr == NULL) {\n\t\t\t\tPyObject_Del(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tif (type_num == PyArray_UNICODE) {\n\t\t\t\tPyUnicode_AS_UNICODE(obj) = \\\n\t\t\t\t\t(Py_UNICODE *)destptr;\n\t\t\t\t((PyUnicodeObject*)obj)->length = itemsize / \\\n\t\t\t\t\tsizeof(Py_UNICODE);\n\t\t\t\t((PyUnicodeObject*)obj)->hash = -1;\n\t\t\t}\n\t\t\telse {\n\t\t\t\t((PyVoidScalarObject *)obj)->obval = destptr;\n\t\t\t\t((PyVoidScalarObject *)obj)->ob_size = itemsize;\n\t\t\t}\n\t\t}\n\t}\n\telse {\n\t\tdestptr = &(((PyScalarObject*)obj)->obval);\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*/\nstatic PyObject *\nPyArray_ToScalar(char *data, PyArrayObject *arr)\n{\n\tint type_num = arr->descr->type_num;\n\tint itemsize = arr->itemsize;\n int swap = !(PyArray_ISNOTSWAPPED(arr));\n\n\treturn PyArray_Scalar(data, type_num, itemsize, swap);\n}\n\n\n/* Return Python scalar if 0-d array object is encountered */\n\nstatic PyObject *\nPyArray_Return(PyArrayObject *mp) \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((PyObject *)mp) && 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*/\nstatic int \nPyArray_RegisterDataType(PyTypeObject *type)\n{\n\tPyArray_Descr *descr;\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 = malloc(sizeof(PyArray_Descr));\n\tmemcpy(descr, PyArray_DescrFromType(PyArray_VOID), \n\t sizeof(PyArray_Descr));\n\ttypenum = PyArray_USERDEF + PyArray_NUMUSERTYPES;\n\tdescr->type_num = typenum;\n\tdescr->typeobj = 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 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 frees the copy of the Descr_table already there.\n places a pointer to the new one into the slot.\n*/\nstatic int\nPyArray_RegisterDescrForType(int typenum, PyArray_Descr *descr)\n{\n\tPyArray_Descr *old;\n\tint i;\n\n\tif (!PyTypeNum_ISUSERDEF(typenum)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"data type not registered\");\n\t\treturn -1;\n\t}\n\told = userdescrs[typenum-PyArray_USERDEF];\n\tdescr->typeobj = old->typeobj;\n\tdescr->type_num = typenum;\n\n#define _NULL_CHECK(member) \\\n\tif (descr->member == NULL) descr->member = old->member\n\n\tfor (i=0; imember == 0) descr->member = old->member\n\n\t_ZERO_CHECK(kind);\n\t_ZERO_CHECK(type);\n\t_ZERO_CHECK(elsize);\n\t_ZERO_CHECK(alignment);\n#undef _ZERO_CHECK\n\n\tfree(old);\n\tuserdescrs[typenum-PyArray_USERDEF] = descr;\n\treturn 0;\n}\n\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 n3 = strlen((const char *)sep);\n if (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 \"\\\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->itemsize,\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->itemsize,\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 = strlen((const char *)format);\n while(it->index < it->size) {\n obj = self->descr->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\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->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\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 if (PyArray_TYPE(self) == PyArray_OBJECT) {\n PyErr_SetString(PyExc_ValueError, \"a string for the data\"\\\n\t\t\t\t\"in an object array is not appropriate\");\n return NULL;\n }\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->itemsize;\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 != NULL)) {\n\t\t/* Free internal references if an Object array */\n\t\tPyArray_XDECREF(self);\n\n PyDataMem_FREE(self->data);\n }\n\t\n if (self->dimensions != NULL) {\n PyDimMem_FREE(self->dimensions); \n\t}\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\n\nstatic PyObject *\narray_item(PyArrayObject *self, int i) \n{\n char *item;\n PyArrayObject *r;\n\n\n\tif(self->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n if ((item = index2ptr(self, i)) == NULL) return NULL;\n\n\tr = (PyArrayObject *)PyArray_New(self->ob_type, \n\t\t\t\t\t self->nd-1, self->dimensions+1, \n\t\t\t\t\t self->descr->type_num, \n\t\t\t\t\t self->strides+1, item, \n\t\t\t\t\t self->itemsize, self->flags,\n\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_item(self, i));\n}\n\n\nstatic int \narray_ass_item(PyArrayObject *self, int 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\n if (i < 0) i = i+self->dimensions[0];\n\n if (self->nd > 1) {\n if((tmp = (PyArrayObject *)array_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->setitem(v, item, self) == -1) return -1;\n return 0;\n}\n\n/* -------------------------------------------------------------- */\nstatic int\nslice_coerce_index(PyObject *o, int *v)\n{\n\t*v = PyArray_PyIntAsInt(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, int length,\n int *start, int *stop, int *step,\n intp *slicelength)\n{\n\tint 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 int\nparse_subindex(PyObject *op, int *step_size, intp *n_steps, int max)\n{\n\tint 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\tint 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_PyIntAsInt(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, start, offset, n_add, n_pseudo;\n int step_size;\n\tintp n_steps;\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, *tup;\n\tint n1, n2, n3, val;\n\tint i;\n\n\ttup = PyTuple_New(mit->nd);\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\tPyTuple_SET_ITEM(tup, i++, PyInt_FromLong((long)val++));\n\tval = 0;\n\twhile(val < n1)\n\t\tPyTuple_SET_ITEM(tup, i++, PyInt_FromLong((long)val++));\n\tval = n1+n2;\n\twhile(val < n3)\n\t\tPyTuple_SET_ITEM(tup, i++, PyInt_FromLong((long)val++));\n\n\tnew = PyArray_Transpose(*ret, tup);\n\tPy_DECREF(tup);\n\tPy_DECREF(*ret);\n\t*ret = (PyArrayObject *)new;\n}\n\n\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\tret = (PyArrayObject *)\\\n\t\tPyArray_New(temp->ob_type, mit->nd, mit->dimensions, \n\t\t\t temp->descr->type_num, NULL, NULL, \n\t\t\t temp->itemsize, \n\t\t\t PyArray_ISFORTRAN(temp),\n\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\treturn NULL;\n\tindex = it->size;\n\tswap = ((temp->flags & NOTSWAPPED) != (ret->flags & NOTSWAPPED));\n copyswap = ret->descr->copyswap;\n\tPyArray_MapIterReset(mit);\n\twhile (index--) {\n copyswap(it->dataptr, mit->dataptr, swap, ret->itemsize);\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\tPyArray_Typecode typecode = {0, 0, 0};\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Unbound Map Iterator */\n\tif (mit->ait == NULL) return -1;\n\n\ttypecode.type_num = mit->ait->ao->descr->type_num;\n\ttypecode.itemsize = mit->ait->ao->itemsize;\n\n\tarr = PyArray_FromAny(op, &typecode, \n\t\t\t 0, 0, FORCECAST);\n\tif (arr == NULL) return -1;\n\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, (PyArrayObject **)&arr);\n\t\t}\n\t}\n\t\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) \n\t\treturn -1;\n\n\tindex = mit->size;\n\tswap = ((mit->ait->ao->flags & NOTSWAPPED) != \\\n\t\t(PyArray_FLAGS(arr) & NOTSWAPPED));\n\n copyswap = PyArray_DESCR(arr)->copyswap;\n\tPyArray_MapIterReset(mit);\n /* Need to decref OBJECT arrays */\n if (PyTypeNum_ISOBJECT(typecode.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 copyswap(mit->dataptr, NULL, swap, \n sizeof(PyObject *));\n PyArray_MapIterNext(mit);\n PyArray_ITER_NEXT(it);\n if (it->index == it->size)\n PyArray_ITER_RESET(it);\n }\n return 0;\n }\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\treturn 0;\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 0-dimensional arrays */\n\nstatic PyObject *\narray_subscript(PyArrayObject *self, PyObject *op) \n{\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n\tintp offset;\n int nd, i;\n PyArrayObject *other;\n\tPyArrayMapIterObject *mit;\n\n if (PyArray_IsScalar(op, Integer) || PyInt_Check(op) || \\\n PyLong_Check(op)) {\n intp value;\n value = PyArray_PyIntAsIntp(op);\n if (PyErr_Occurred())\n PyErr_Clear();\n else if (value >= 0) {\n if (value <= MAX_INT)\n return array_item(self, (int) value);\n }\n else if (value < 0) {\n if (value >= -MAX_INT) {\n if (self->nd > 0) value += self->dimensions[0];\n return array_item(self, (int) value);\n }\n }\n }\n\n\tif (PyArrayMapIter_Check(op)) {\n\t\tmit = (PyArrayMapIterObject *)op;\n\t\t/* bind to current array */\n\t\tPyArray_MapIterBind(mit, self);\n\t\t\n\t\t/* If the mapiterator was created with standard indexing\n\t\t behavior, fall through to view-based code */\n\t\tif (!mit->view) return PyArray_GetMap(mit);\n\t\top = mit->indexobj;\n\t}\n\telse { /* wrap arguments into a mapiter object */\n\t\tmit = (PyArrayMapIterObject *)PyArray_MapIterNew(op);\n\t\tif (mit == NULL) return NULL;\n\t\tif (!mit->view) { /* fancy indexing */\n\t\t\tPyArray_MapIterBind(mit, self);\n\t\t\tother = (PyArrayObject *)PyArray_GetMap(mit);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn (PyObject *)other;\n\t\t}\n\t\tPy_DECREF(mit);\n\t}\n\n\ti = PyArray_PyIntAsInt(op);\n\tif (!error_converting(i)) {\n\t\tif (i < 0 && self->nd > 0) i = i+self->dimensions[0];\n\t\treturn array_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\tif ((other = (PyArrayObject *)\t\t\t\t\t\\\n\t PyArray_New(self->ob_type, nd, dimensions, self->descr->type_num,\n\t\t\t strides, self->data+offset, \n\t\t\t self->itemsize, self->flags,\n\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 \narray_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op) \n{\n int ret, 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\n\tif (PyArrayMapIter_Check(index)) {\n\t\tmit = (PyArrayMapIterObject *)index;\n\t\t/* bind behavior to current array */\n\t\tPyArray_MapIterBind(mit, self);\n\t\t\t\n\t\t/* fall through if standard view-based map iterator */\n\t\tif (!mit->view) return PyArray_SetMap(mit, op);\n\t\tindex = mit->indexobj;\n\t}\n\telse {\n\t\tmit = (PyArrayMapIterObject *)PyArray_MapIterNew(index);\n\t\tif (mit == NULL) return -1;\n\t\tif (!mit->view) {\n\t\t\tPyArray_MapIterBind(mit, self);\n\t\t\tret = PyArray_SetMap(mit, op);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn ret;\n\t\t}\n\t\tPy_DECREF((PyObject*)mit);\n\t}\n\n\ti = PyArray_PyIntAsInt(index);\n\tif (!error_converting(i)) {\n\t\treturn array_ass_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 ret = PyArray_CopyObject(tmp, op);\n Py_DECREF(tmp);\n\t\n return ret;\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 \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\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}\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}\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 PyObject *args, *ret;\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n args = Py_BuildValue(\"(OO)\", m1, m2);\n ret = PyObject_Call(op, args, NULL);\n Py_DECREF(args);\n return ret;\n}\n\nstatic PyObject *\nPyArray_GenericUnaryFunction(PyArrayObject *m1, PyObject *op) \n{\n PyObject *args, *ret;\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n args = Py_BuildValue(\"(O)\", m1);\n ret = PyObject_Call(op, args, NULL);\n Py_DECREF(args);\n return ret;\n}\n\nstatic PyObject *\nPyArray_GenericInplaceBinaryFunction(PyArrayObject *m1, \n\t\t\t\t PyObject *m2, PyObject *op) \n{\n PyObject *args, *ret;\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n args = Py_BuildValue(\"(OOO)\", m1, m2, m1);\n ret = PyObject_Call(op, args, NULL);\n Py_DECREF(args);\n return ret;\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_all_nonzero(PyArrayObject *mp) \n{\n\tintp index;\n\tPyArrayIterObject *it;\n\tBool anyTRUE = 0;\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->nonzero(it->dataptr, mp)) {\n\t\t\tanyTRUE = 1;\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 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->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->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->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->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->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_all_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 r = (PyArrayObject *)\\\n\t\tPyArray_New(self->ob_type, self->nd, self->dimensions, \n\t\t\t self->descr->type_num, self->strides, data,\n\t\t\t self->itemsize, 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 any(self == el) */\n\n return PyObject_RichCompareBool((PyObject *)self, el, Py_EQ);\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 *)realloc(*string, *max_n); }\n\t\n if (nd == 0) {\n\t\t\n if ((op = descr->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\tfree(string); return NULL; \n\t}\n\t\n\tif (PyArray_ISFLEXIBLE(self)) {\n\t\tchar buf[100];\n\t\tsnprintf(buf, sizeof(buf), \"%d\", self->itemsize);\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 free(string);\n return ret;\n}\n\nstatic PyObject *PyArray_StrFunction=NULL;\nstatic PyObject *PyArray_ReprFunction=NULL;\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\n\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) \n{\n PyObject *array_other, *result;\n\n switch (cmp_op) \n {\n case Py_LT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less);\n case Py_LE:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less_equal);\n case Py_EQ:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then return the integer\n\t\t\t object 0. This fixes code that used to\n\t\t\t allow equality comparisons between arrays\n\t\t\t and other objects which would give a result\n\t\t\t of 0\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n result = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.equal);\n /* If the comparison results in NULL, then the \n\t\t\t two array objects can not be compared together so \n\t\t\t return zero \n */\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n return result;\n case Py_NE:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then objects cannot be \n\t\t\t compared and cannot be equal, therefore, \n\t\t\t return True;\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n result = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.not_equal);\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n return result;\n case Py_GT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.greater);\n case Py_GE:\n return PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t other, \n\t\t\t\t\t \t n_ops.greater_equal);\n }\n return NULL;\n}\n\nstatic PyObject *\n_check_axis(PyArrayObject *arr, int *axis, int flags)\n{\n\tPyObject *temp;\n\tint n = arr->nd;\n\n\tif ((*axis >= MAX_DIMS) || (n==0)) {\n\t\ttemp = PyArray_Ravel(arr,0);\n\t\t*axis = 0;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_FromAny((PyObject *)arr, NULL, \n\t\t\t\t\t 0, 0, flags);\n\t\t\tif (temp == NULL) return NULL;\n\t\t}\n\t\telse {\n\t\t\tPy_INCREF(arr);\n\t\t\ttemp = (PyObject *)arr;\n\t\t}\n\t}\n\tif (*axis < 0) *axis += n;\n\tif ((*axis < 0) || (*axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", *axis);\n\t\tPy_DECREF(temp);\n\t\treturn NULL;\n\t}\n\treturn temp;\n}\n\n#include \"arraymethods.c\"\n\n/* Lifted from numarray */\nstatic PyObject *\nPyArray_IntTupleFromIntp(int len, intp *vals)\n{\n\tint i;\n PyObject *intTuple = PyTuple_New(len);\n if (!intTuple) goto fail;\n for(i=0; ind == 0) return 1;\n\tsd = ap->itemsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\n\t}\n\treturn 1;\n}\n\n\nstatic int \n_IsFortranContiguous(PyArrayObject *ap) \n{\n\tint sd;\n\tint i;\n\t\n\tif (ap->nd == 0) return 1;\n\tsd = ap->itemsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i=0; i< ap->nd; ++i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\n\t}\n\treturn 1;\n}\n\nstatic int\n_IsAligned(PyArrayObject *ap) \n{\n\tint i, alignment, aligned=1;\n\tintp ptr;\n\tint type = ap->descr->type_num;\n\n\tif ((type == PyArray_STRING) || (type == PyArray_VOID))\n\t\treturn 1;\n\n\talignment = ap->descr->alignment;\n\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\tPyBufferProcs *pb;\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\tpb = base->ob_type->tp_as_buffer;\n\tif (pb == NULL || pb->bf_getwritebuffer == NULL)\n\t\treturn FALSE;\n\t\n\treturn TRUE;\n}\n\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\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not \n walk outside of the memory implied by either numbytes or\n a single segment array of the provided dimensions and element size if\n numbytes is 0 */\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, \n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\t\n\tif (numbytes == 0) \n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\t\n\tfor (i=0; i numbytes) {\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\treturn TRUE;\n\t\n}\n\n\n/* This is the main array creation routine. */\n\n/* Flags argument has multiple related meanings \n depending on data and strides: \n\n If data is given, then flags is flags associated with data. \n If strides is not given, then a contiguous strides array will be created\n and the CONTIGUOUS bit will be set. If the flags argument \n has the FORTRAN bit set, then a FORTRAN-style strides array will be\n created (and of course the FORTRAN flag bit will be set). \n\n If data is not given but created here, then flags will be DEFAULT_FLAGS\n and a non-zero flags argument can be used to indicate a FORTRAN style\n array is desired. \n*/\n\nstatic intp\n_array_fill_strides(intp *strides, intp *dims, int nd, intp itemsize, \n\t\t int inflag, int *objflags) \n{\n\tint i;\n\t/* Only make Fortran strides if not contiguous as well */\n\tif ((inflag & FORTRAN) && !(inflag & CONTIGUOUS)) {\n\t\tfor (i=0; i 1) *objflags &= ~CONTIGUOUS;\n\t\telse *objflags |= CONTIGUOUS;\n\t}\n\telse {\n\t\tfor (i=nd-1;i>=0;i--) {\n\t\t\tstrides[i] = itemsize;\n\t\t\titemsize *= dims[i] ? dims[i] : 1;\n\t\t}\n\t\t*objflags |= CONTIGUOUS;\n\t\tif (nd > 1) *objflags &= ~FORTRAN;\n\t\telse *objflags |= FORTRAN;\n\t}\n\treturn itemsize;\n}\n\n\t\nstatic PyObject *\nPyArray_New(PyTypeObject *subtype, int nd, intp *dims, int type_num,\n intp *strides, char *data, int itemsize, int flags,\n\t PyObject *obj)\n{\n\tPyArrayObject *self;\n\tPyArray_Descr *descr;\n\tregister int i;\n\tintp sd, temp=-1;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\tif (descr == NULL) return NULL;\n\n\tif (nd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"number of dimensions must be >=0\");\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 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\treturn NULL;\n\t\t}\n\t}\n\t\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) return NULL;\t\n\tself->descr = descr;\n\tself->dimensions = 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\n\tif (PyTypeNum_ISFLEXIBLE(type_num)) {\n\t\tif (itemsize < 1) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"type must provide an itemsize\");\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn NULL;\n\t\t}\n\t\tself->itemsize = itemsize;\n\t\t/* Guarantee that these kind of arrays are never byteswapped\n\t\t unknowingly. \n\t\t*/\n\t\tif (type_num != PyArray_UNICODE)\n\t\t\tself->flags |= NOTSWAPPED;\n\t}\n\telse self->itemsize = descr->elsize; \n\t\t\n\tsd = self->itemsize;\n\t\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn PyErr_NoMemory();\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\tPyDimMem_FREE(self->dimensions);\n\t\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\t\treturn NULL;\n\t\t\t}\t\t\t\t\n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t}\n \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 (a.data) doesn't work\n\t\t as it should. */\n\n\t\tif (sd==0) sd = sizeof(intp);\n\n\t\tif ((data = PyDataMem_NEW(sd))==NULL) {\n\t\t\tPyDimMem_FREE(self->dimensions);\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn PyErr_NoMemory();\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\n\t\t/* It is bad to have unitialized OBJECT pointers */\n\t\t/* We shouldn't need to check for the OBJECT Letter\n\t\t but perhaps it's best. */\n\t\tif (type_num == PyArray_OBJECT || \\\n\t\t type_num == PyArray_OBJECTLTR) {\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\tself->nd = nd;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\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;\n\t\tif (temp==-1) { /* 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\tres = PyObject_CallMethod((PyObject *)self, \n\t\t\t\t\t \"__array_finalize__\",\n\t\t\t\t\t \"O\", obj);\n\t\tif (res == NULL) {\n\t\t\tPyDimMem_FREE(self->dimensions);\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn NULL;\n\t\t}\n\t\telse Py_DECREF(res);\n\t}\n\n\treturn (PyObject *)self;\n}\n\n\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\n newsize = PyArray_MultiplyList(new_dimensions, new_nd);\n\n if (newsize == 0) {\n PyErr_SetString(PyExc_ValueError, \n \"newsize is zero; cannot delete an array \"\\\n \"in this way\");\n return NULL;\n }\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 = (((PyObject *)self)->ob_refcnt);\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\n\t\t/* Reallocate space if needed */\n\t\tnew_data = PyDataMem_RENEW(self->data, \n\t\t\t\t\t newsize*(self->itemsize));\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->itemsize;\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->itemsize;\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 */\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; idataptr, fromptr, itemsize);\n\t\t\tPyArray_ITER_NEXT(iter);\n\t\t}\n\n\t\tPy_DECREF(iter);\n\t\tPy_DECREF(behaved);\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\", \"strides\", \n \"swap\", \"fortran\", NULL};\n\tint itemsize = 0;\n\tPyArray_Typecode typecode = {PyArray_NOTYPE, 0, 0};\n\tint type_num = PyArray_NOTYPE;\n PyArray_Dims dims = {NULL, 0};\n PyArray_Dims strides = {NULL, 0};\n PyArray_Chunk buffer;\n\tint fortran = 0;\n int swapped = 0;\n\tPyArrayObject *ret;\n\n\tbuffer.ptr = NULL; \n /* Usually called with shape and type\n but can also be called with buffer, strides, and swapped info\n */\n\n\t/* For now, let's just use this to create an empty, contiguous \n\t array of a specific type and shape. \n\t*/\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&O&ii\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &dims, \n PyArray_TypecodeConverter,\n\t\t\t\t\t &typecode, \n PyArray_BufferConverter,\n &buffer,\n &PyArray_IntpConverter, \n &strides,\n &swapped, &fortran)) \n\t\treturn NULL;\n\t\n if (typecode.type_num ==PyArray_NOTYPE) {\n\t\ttypecode.type_num = PyArray_DOUBLE;\n\t\ttypecode.itemsize = sizeof(double);\n\t}\n\ttype_num = typecode.type_num;\n\titemsize = typecode.itemsize;\n\n\n if (dims.ptr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"need to give a \"\\\n \"valid shape as the first argument\");\n goto fail;\n }\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)PyArray_New(subtype, (int)dims.len, \n dims.ptr, type_num,\n NULL, NULL, itemsize, \n fortran, NULL);\n \n if (ret == NULL) goto fail;\n if (type_num == PyArray_OBJECT) { /* place Py_None */\n PyArray_FillObjectArray(ret, Py_None);\n }\n }\n else { /* buffer given -- use it */\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = buffer.len / itemsize;\n }\n else if (buffer.len < itemsize* \\\n PyArray_MultiplyList(dims.ptr, dims.len)) {\n PyErr_SetString(PyExc_TypeError, \n \"buffer is too small for \" \\\n \"requested array\");\n goto fail;\n }\n if (strides.ptr != NULL) {\n\t\t\tif (strides.len != dims.len) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides, if given, must be \"\\\n\t\t\t\t\t\t\"the same length as shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CheckStrides(itemsize, strides.len, \n\t\t\t\t\t\t buffer.len,\n\t\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides is incompatible \"\\\n\t\t\t\t\t\t\"with shape of requested\"\\\n\t\t\t\t\t\t\"array and size of buffer\");\n\t\t\t\tgoto fail;\n\t\t\t}\n }\n if (type_num == PyArray_OBJECT) {\n PyErr_SetString(PyExc_TypeError, \"cannot construct \"\\\n \"an object array from buffer data\");\n goto fail;\n }\n /* get writeable and aligned */\n if (fortran) buffer.flags |= FORTRAN;\n if (!(swapped)) buffer.flags |= NOTSWAPPED;\n ret = (PyArrayObject *)PyArray_New(subtype, dims.len, \n dims.ptr, type_num,\n strides.ptr,\n (char *)buffer.ptr, \n itemsize, \n buffer.flags, NULL); \n if (ret == 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 PyArray_Return(ret);\n \n fail:\n if (dims.ptr) PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return NULL;\n}\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 static PyObject *module=NULL;\n\n if (module==NULL) {\n module = PyImport_ImportModule(\"scipy.base._internal\");\n if (module == NULL) return NULL;\n }\n return PyObject_CallMethod(module, \"flagsobj\", \"Oii\", \n self, self->flags, 0);\n}\n\n/*\nstatic int\narray_flags_set(PyArrayObject *self, PyObject *obj) \n{\n\tint flagback = self->flags;\n\n if (PyDict_Check(obj)) {\n PyObject *new;\n\t\tnew = PyDict_GetItemString(obj, \"ALIGNED\");\n\t\tif (new) {\n\t\t\tif (PyObject_Not(new)) self->flags &= ~ALIGNED;\n\t\t\telse if (_IsAligned(self)) self->flags |= ALIGNED;\n\t\t\telse {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"cannot set aligned flag of \" \\\n\t\t\t\t\t\t\"mis-aligned array to True\");\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t}\n new = PyDict_GetItemString(obj, \"UPDATEIFCOPY\");\n if (new) {\n if (PyObject_Not(new)) {\n self->flags &= ~UPDATEIFCOPY;\n Py_DECREF(self->base);\n self->base = NULL;\n }\n else {\n\t\t\t\tself->flags = flagback;\n PyErr_SetString(PyExc_ValueError, \n \"cannot set UPDATEIFCOPY \" \\\n \"flag to True\");\n return -1;\n }\n }\n new = PyDict_GetItemString(obj, \"WRITEABLE\");\n if (new) {\n\t\t\tif (PyObject_IsTrue(new)) {\n\t\t\t\tif (_IsWriteable(self)) {\n\t\t\t\t\tself->flags |= WRITEABLE;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tself->flags = flagback;\n\t\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\t\"cannot set \"\t\\\n\t\t\t\t\t\t\t\"WRITEABLE \"\t\\\n\t\t\t\t\t\t\t\"flag to True of \"\\\n\t\t\t\t\t\t\t\"this array \");\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n else\n self->flags &= ~WRITEABLE;\n }\n new = PyDict_GetItemString(obj, \"NOTSWAPPED\");\n if (new) {\n if (PyObject_IsTrue(new))\n self->flags |= NOTSWAPPED;\n else {\n self->flags &= ~NOTSWAPPED;\n\t\t\t}\n\t\t}\n return 0;\n }\n PyErr_SetString(PyExc_ValueError, \n \"object must be a dictionary\");\n return -1;\n}\n*/\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\tif (!PyTuple_Check(val)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"shape must be a tuple\");\n\t\treturn -1;\n\t}\n\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\n\t\n\tif (self->nd > 0) { /* Free old dimensions and strides */\n\t\tPyDimMem_FREE(self->dimensions);\n\t}\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;\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\treturn -1;\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->itemsize;\n\t\n\tif (!PyArray_CheckStrides(self->itemsize, self->nd, numbytes, \n\t\t\t\t self->dimensions, newstrides.ptr)) {\n\t\tPyErr_SetString(PyExc_ValueError, \"strides is not \"\\\n\t\t\t\t\"compatible with available memory\");\n\t\treturn -1;\n\t}\n\tmemcpy(self->strides, newstrides.ptr, sizeof(intp)*newstrides.len);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\treturn 0;\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->itemsize);\n}\n\nstatic PyObject *\narray_size_get(PyArrayObject *self)\n{\n\tlonglong size=PyArray_SIZE(self);\n\tif (size > MAX_INT || size < MIN_INT)\n\t\treturn PyLong_FromLongLong((longlong) size);\n\telse \n\t\treturn PyInt_FromLong((long) size);\n}\n\n\nstatic PyObject *\narray_typechar_get(PyArrayObject *self)\n{\n\tif PyArray_ISFLEXIBLE(self) \n\t\treturn PyString_FromFormat(\"%c%d\", (self->descr->type),\n\t\t\t\t\t self->itemsize);\n\telse \n\t\treturn PyString_FromStringAndSize(&(self->descr->type), 1);\n}\n\nstatic PyObject *\narray_typestr_get(PyArrayObject *self)\n{\n\tstatic char endians[] = \"<>\";\n\tchar endian;\n\tint which;\n\tunsigned long val = 1;\n\tchar *s;\n\tchar basic_=self->descr->kind;\n\n\ts = (char *)&val; /* s[0] == 0 implies big-endian */\n\twhich = (PyArray_ISNOTSWAPPED(self) ? 0 : 1);\n\tif (s[0] == 0) which = 1 - which;\n\tendian = endians[which]; \n\t\n\tif ((basic_==PyArray_VOIDLTR) || (basic_==PyArray_STRINGLTR) || \\\n\t (basic_==PyArray_OBJECTLTR) || (self->itemsize == 1))\n\t\treturn PyString_FromFormat(\"|%c%d\", basic_, self->itemsize);\n\telse\n\t\treturn PyString_FromFormat(\"%c%c%d\", endian, basic_,\n\t\t\t\t\t self->itemsize);\n}\n\nstatic PyObject *\narray_descr_get(PyArrayObject *self)\n{\n\tPyObject *res;\n\tPyObject *dobj;\n\n\t/* hand this off to the typeobject */\n\t/* or give default */\n\tif (PyArray_ISUSERDEF(self)) {\n\t\tres = PyObject_GetAttrString((PyObject *)self->descr->typeobj, \n\t\t\t\t\t \"__array_descr__\");\n\t\tif (res) return res;\n\t\tPyErr_Clear();\n\t}\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\n\nstatic PyObject *\narray_type_get(PyArrayObject *self)\n{\n\treturn PyArray_TypeObjectFromType(self->descr->type_num);\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*/\n\nstatic int\narray_type_set(PyArrayObject *self, PyObject *arg)\n{\n PyArray_Typecode newtype = {PyArray_NOTYPE, 0, 0};\n intp newdim;\n int index;\n char *msg = \"new type not compatible with array.\";\n\n if ((PyArray_TypecodeConverter(arg, &newtype) < 0) ||\n newtype.type_num == PyArray_NOTYPE) {\n PyErr_SetString(PyExc_TypeError, \"invalid type for array\");\n return -1;\n }\n if (!(PyArray_ISONESEGMENT(self) ||\t\t\\\n\t (newtype.itemsize != self->itemsize))) {\n PyErr_SetString(PyExc_ValueError, msg);\n return -1; \n }\n\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\n if (newtype.itemsize < self->itemsize) {\n /* if it is compatible increase the size of the dimension\n at end (or at the front for FORTRAN)\n */\n if (self->itemsize % newtype.itemsize != 0) {\n PyErr_SetString(PyExc_ValueError, msg);\n return -1;\n }\n newdim = self->itemsize / newtype.itemsize;\n\t\tself->dimensions[index] *= newdim;\n self->strides[index] = newtype.itemsize;\n\t}\n \n else if (newtype.itemsize > self->itemsize) {\n \n /* Determine if last (or first if FORTRAN) dimension\n is compatible */\n\n\t\tnewdim = self->dimensions[index] * self->itemsize;\n if ((newdim % newtype.itemsize) != 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, msg);\n return -1;\n }\n\t\t\n self->dimensions[index] = newdim / newtype.itemsize;\n self->strides[index] = newtype.itemsize;\n\t\t\n }\n\t\n \n /* fall through -- adjust type*/\n\n self->descr = PyArray_DescrFromType(newtype.type_num);\n self->itemsize = newtype.itemsize;\n PyArray_UpdateFlags(self, ALIGNED);\n return 0;\n\n}\n\n\n\nstatic PyObject *\narray_base_get(PyArrayObject *self)\n{\n\tif (self->base == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\telse {\n\t\tPy_INCREF(self->base);\n\t\treturn self->base;\n\t}\n}\n\n\nstatic PyObject *\narray_real_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *)ret;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n}\n\n\nstatic int\narray_real_set(PyArrayObject *self, PyObject *val)\n{\n\tPyArrayObject *ret;\n\tPyArrayObject *new;\n\tint rint;\n\n\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0);\n\tif (new == NULL) return -1;\n\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) 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\treturn rint;\n}\n\nstatic PyObject *\narray_imag_get(PyArrayObject *self)\n{\t\n\tPyArrayObject *ret;\n\tint itemsize;\n\tint typenum;\n PyArray_Typecode type;\n\t\n\ttype.type_num = self->descr->type_num;\n\ttype.itemsize = self->itemsize;\n\ttype.fortran = PyArray_ISFORTRAN(self);\n\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\titemsize = self->itemsize >> 1;\n\t\ttypenum = self->descr->type_num - PyArray_NUM_FLOATTYPE;\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 typenum,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data + itemsize,\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\tret = (PyArrayObject *)PyArray_Zeros(self->nd, \n\t\t\t\t\t\t self->dimensions, &type);\n\t\tret->flags &= ~WRITEABLE;\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic int\narray_imag_set(PyArrayObject *self, PyObject *val)\n{\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyArrayObject *ret;\n\t\tPyArrayObject *new;\n\t\tint rint;\n\n\t\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0); \n\t\tif (new == NULL) return -1;\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides+ \\\n\t\t\t\t\t\t (self->itemsize >> 1) ,\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) {\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_Typecode typecode;\n int swap;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode.type_num = self->descr->type_num;\n\ttypecode.itemsize = self->itemsize;\n\ttypecode.fortran = PyArray_ISFORTRAN(self);\n\t\n\tarr = PyArray_FromAny(val, &typecode, \n\t\t\t 0, 0, FORCECAST);\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->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 copyswap(selfit->dataptr, NULL, swap, \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->itemsize);\n copyswap(selfit->dataptr, NULL, swap, self->itemsize);\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\t{\"base\",\n\t (getter)array_base_get,\n\t NULL,\n\t \"base object\"},\n {\"dtype\", \n\t (getter)array_type_get, \n\t (setter)array_type_set,\n\t \"get array type class\"},\n\t{\"dtypechar\",\n\t (getter)array_typechar_get,\n\t NULL,\n\t \"get array type character code\"},\n\t{\"dtypestr\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"get array type string\"},\n {\"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_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\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\n\nstatic char Arraytype__doc__[] = \n \"A array object represents a multidimensional, homogeneous array\\n\"\n\t\" of basic values. Arrays are sequence, mapping and numeric\\n\"\n\t\" objects. More information is available in the scipy module and\\n\"\n\t\" by looking at the methods and attributes of an array.\";\n\nstatic PyTypeObject PyBigArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"scipy.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 \n offsetof(PyArrayObject, weakreflist), /*tp_weaklistoffset */\n\n /* Iterator support (use standard) */\n\n (getiterfunc)0, \t\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 0,\t /* tp_alloc */ \n (newfunc)array_new,\t\t /* tp_new */\n 0,\t \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 \"scipy.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) \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 if (PySequence_Length(s) == 0) \n\t\treturn 1;\n\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);\n\t\tif(d >= 0) d++;\n\t}\n Py_DECREF(e);\n return d;\n}\n\nstatic int\ndiscover_itemsize(PyObject *s, int nd, int *itemsize) \n{\n\tint n, r, i;\n\tPyObject *e;\n\t\n\tn = PyObject_Length(s);\n\n\tif ((nd == 0) || PyString_Check(s) ||\t\t\\\n\t PyUnicode_Check(s) || PyBuffer_Check(s)) {\n\t\tif PyUnicode_Check(s) \n\t\t\t*itemsize = MAX(*itemsize, sizeof(Py_UNICODE)*n);\n\t\telse\n\t\t\t*itemsize = MAX(*itemsize, n);\n\t\treturn 0;\n\t}\n\tfor (i=0; i n_lower) n_lower = d[1];\n }\n d[1] = n_lower;\n\t\n return 0;\n}\n\nstatic void\n_array_small_type(int chktype, int mintype, int chksize, int minsize, \n\t\t PyArray_Typecode *outtype)\n{\n\touttype->type_num = MAX(chktype, mintype);\n\tif (PyTypeNum_ISFLEXIBLE(outtype->type_num) &&\t\\\n\t PyTypeNum_ISFLEXIBLE(mintype)) {\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 == PyArray_STRING) {\n\t\t\touttype->itemsize = MAX(chksize, 2*minsize);\n\t\t}\n\t\telse {\n\t\t\touttype->itemsize = MAX(chksize, minsize);\n\t\t}\n\t}\n\telse {\n\t\touttype->itemsize = chksize;\n\t}\n\treturn;\t\n}\n\nstatic void\n_array_find_type(PyObject *op, PyArray_Typecode *minitype, \n\t\t PyArray_Typecode *outtype, int max)\n{\n int l;\n PyObject *ip;\n\tint chktype=0;\n\tint chksize=0;\n\tint mintype, minsize;\n\n\tif (minitype == NULL) {\n\t\tmintype = PyArray_BOOL;\n\t\tminsize = sizeof(Bool);\n\t}\n\telse {\n\t\tmintype = minitype->type_num;\n\t\tminsize = minitype->itemsize;\n\t}\n\n \n if (max < 0 || mintype == -1) goto deflt;\n\t\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_TYPE(op);\n\t\tchksize = PyArray_ITEMSIZE(op);\n\t\tgoto finish;\n\t}\n\t\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tPyArray_TypecodeFromScalar(op, outtype);\n\t\tchktype = outtype->type_num;\n\t\tchksize = outtype->itemsize;\n\t\tgoto finish;\n\t}\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_TYPE(ip);\n\t\t\tchksize = PyArray_ITEMSIZE(ip);\n\t\t\tgoto finish;\n\t\t}\n } \n\t\n\tif (PyObject_HasAttrString(op, \"__array_typestr__\")) {\n\t\tint swap=0, res;\n\t\tip = PyObject_GetAttrString(op, \"__array_typestr__\");\n\t\tif (ip && PyString_Check(ip)) {\n\t\t\tres = _array_typecode_fromstr(PyString_AS_STRING(ip), \n\t\t\t\t\t\t &swap, outtype); \n\t\t\tif (res >= 0) {\n\t\t\t\tPy_DECREF(ip);\n\t\t\t\tchktype = outtype->type_num;\n\t\t\t\tchksize = outtype->itemsize;\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t}\n\t\tPy_XDECREF(ip);\n\t}\n\n if (PyString_Check(op)) {\n\t\tchktype = PyArray_STRING;\n\t\tchksize = PyString_GET_SIZE(op);\n\t\tgoto finish;\n }\n\n\tif (PyUnicode_Check(op)) {\n\t\tchktype = PyArray_UNICODE;\n\t\tchksize = PyUnicode_GET_DATA_SIZE(op);\n\t\tgoto finish;\n\t}\n\n\tif (PyBuffer_Check(op)) {\n\t\tchktype = PyArray_VOID;\n\t\tchksize = op->ob_type->tp_as_sequence->sq_length(op);\n\t\tPyErr_Clear();\n\t\tgoto finish;\n\t}\n\n\tif (PyInstance_Check(op)) goto deflt;\n\t\n if (PySequence_Check(op)) {\n\t\tPyArray_Typecode newtype;\n\t\tnewtype.type_num = mintype;\n\t\tnewtype.itemsize = minsize;\n\t\tnewtype.fortran = 0;\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 && mintype == 0) {\n\t\t\tnewtype.type_num = PyArray_INTP;\n\t\t\tnewtype.itemsize = sizeof(intp);\n\t\t}\n while (--l >= 0) {\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\t_array_find_type(ip, &newtype, outtype, max-1);\n\t\t\t_array_small_type(outtype->type_num,\n\t\t\t\t\t newtype.type_num, \n\t\t\t\t\t outtype->itemsize,\n\t\t\t\t\t newtype.itemsize,\n\t\t\t\t\t &newtype);\n Py_DECREF(ip);\n }\n\t\tchktype = newtype.type_num;\n\t\tchksize = newtype.itemsize;\n\t\tgoto finish;\n }\n\t\n\tif (PyBool_Check(op)) {\n\t\tchktype = PyArray_BOOL;\n\t\tchksize = sizeof(Bool);\n\t\tgoto finish;\t\t\n\t}\n else if (PyInt_Check(op)) {\n\t\tchktype = PyArray_LONG;\n\t\tchksize = sizeof(long);\n\t\tgoto finish;\n } else if (PyFloat_Check(op)) {\n\t\tchktype = PyArray_DOUBLE;\n\t\tchksize = sizeof(double);\n\t\tgoto finish;\n\t} else if (PyComplex_Check(op)) {\n\t\tchktype = PyArray_CDOUBLE;\n\t\tchksize = sizeof(cdouble);\n\t\tgoto finish;\n\t}\n\n deflt:\n\tchktype = PyArray_OBJECT;\n\tchksize = sizeof(void *);\n\n finish:\n\t_array_small_type(chktype, mintype, chksize, minsize, \n\t\t\t outtype);\n\treturn;\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\" */ \nstatic PyObject *\nArray_FromScalar(PyObject *op, PyArray_Typecode *typecode) \n{\n PyArrayObject *ret;\n\tint itemsize; \n\tint type;\n\t\n\titemsize = typecode->itemsize;\n\ttype = typecode->type_num;\n\n\tif (itemsize == 0 && PyTypeNum_ISFLEXIBLE(type)) {\n\t\titemsize = PyObject_Length(op);\n\t}\n\n\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, 0, NULL, type,\n\t\t\t\t\t NULL, NULL, itemsize, 0, NULL);\n\n\tif (ret == NULL) return NULL;\n\n ret->descr->setitem(op, ret->data, ret);\n\t\n if (PyErr_Occurred()) {\n array_dealloc(ret);\n return NULL;\n } else {\n return (PyObject *)ret;\n }\n}\n\n\nstatic PyObject *\nArray_FromSequence(PyObject *s, PyArray_Typecode *typecode, int min_depth, \n\t\t int max_depth)\n{\n PyArrayObject *r;\n int nd;\n\tintp *d;\n\tint stop_at_string;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->itemsize;\n\t\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 if (!((nd=discover_depth(s, MAX_DIMS+1, stop_at_string)) > 0)) {\n\t\tif (nd==0)\n\t\t\treturn Array_FromScalar(s, typecode);\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid input sequence\");\n return NULL;\n }\n\t\n if ((max_depth && nd > max_depth) ||\t\\\n\t (min_depth && nd < min_depth)) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid number of dimensions\");\n return NULL;\n }\n\t\n\tif ((d=PyDimMem_NEW(nd)) == NULL) {\n\t\treturn PyErr_NoMemory();\n }\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) {\n\t\tPyDimMem_FREE(d);\n\t\treturn NULL;\n\t}\n\tif (itemsize == 0 && PyTypeNum_ISFLEXIBLE(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) {\n\t\t\tPyDimMem_FREE(d);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n r=(PyArrayObject*)PyArray_New(&PyArray_Type, nd, d, \n\t\t\t\t type, NULL, NULL,\n\t\t\t\t itemsize, \n\t\t\t\t typecode->fortran, NULL);\n\n PyDimMem_FREE(d);\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\n\nstatic int \nPyArray_ValidType(int type) \n{\n\tPyArray_Descr *descr;\n\t\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr==NULL) return 0;\n\treturn 1;\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->itemsize;\n\tint nels = PyArray_BUFSIZE;\n\tint el;\n\tint inswap, outswap=0;\n\tint obuf=!PyArray_ISCARRAY(out);\n\tint oelsize = out->itemsize;\n\tPyArray_VectorUnaryFunc *castfunc;\n PyArray_CopySwapFunc *in_csn;\n PyArray_CopySwapFunc *out_csn;\n\tint retval = -1;\n\n\tcastfunc = in->descr->cast[out->descr->type_num];\n in_csn = in->descr->copyswap;\n out_csn = out->descr->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\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\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->itemsize * 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\n/* For backward compatibility */\n\nstatic PyObject *\nPyArray_Cast(PyArrayObject *mp, int type_num) \n{\n\tPyArray_Typecode type;\n\tPyArray_Descr *descr;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\ttype.itemsize = descr->elsize;\n\ttype.type_num = descr->type_num;\n\ttype.fortran = 0;\n\t\n\treturn PyArray_CastToType(mp, &type);\n}\n\nstatic PyObject * \nPyArray_CastToType(PyArrayObject *mp, PyArray_Typecode *at) \n{\n\tPyObject *out;\n\tint ret;\n\n\tif ((mp->descr->type_num == at->type_num) && \\\n\t (at->itemsize==0 || mp->itemsize == at->itemsize) &&\n\t PyArray_ISBEHAVED_RO(mp)) {\n\t\tPy_INCREF(mp);\n\t\treturn (PyObject *)mp;\n\t}\n\t\t\n\tif (at->itemsize == 0) {\n\t\tif (mp->descr->type_num == PyArray_STRING &&\t\\\n\t\t at->type_num == PyArray_UNICODE)\n\t\t\tat->itemsize = mp->itemsize*sizeof(Py_UNICODE);\n\t\tif (mp->descr->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING) \n\t\t\tat->itemsize = mp->itemsize/sizeof(Py_UNICODE);\n\t\tif (at->type_num == PyArray_VOID)\n\t\t\tat->itemsize = mp->itemsize;\n\t}\n\n\tout = PyArray_New(mp->ob_type, mp->nd, \n\t\t\t mp->dimensions, \n\t\t\t at->type_num,\n\t\t\t NULL, NULL, at->itemsize, \n\t\t\t at->fortran, (PyObject *)mp);\n\tif (out == NULL) return NULL;\n\tret = PyArray_CastTo((PyArrayObject *)out, mp);\n\tif (ret != -1) return out;\n\n\tPy_DECREF(out);\n\treturn NULL;\n\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\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\tsimple = ((PyArray_ISCARRAY(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY(mp) && PyArray_ISFARRAY(out)));\n\t\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->itemsize * outsize;\n\t\tintp ncopies = outsize / mpsize;\n\n\t\twhile(ncopies--) {\n\t\t\tinptr = mp->data;\n\t\t\tmp->descr->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\nstatic PyObject *\narray_fromarray(PyArrayObject *arr, PyArray_Typecode *typecode, int flags) \n{\n\t\n\tPyArrayObject *ret=NULL;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->itemsize;\n\tint copy = 0;\n\tint arrflags;\n\tPyArray_Typecode oldtype;\n\tchar *msg = \"cannot copy back to a read-only array\";\n PyTypeObject *subtype;\n\n\toldtype.type_num = PyArray_TYPE(arr);\n\toldtype.itemsize = PyArray_ITEMSIZE(arr);\n\toldtype.fortran = 0;\n\n subtype = arr->ob_type;\n\n\tif (type == PyArray_NOTYPE) type = arr->descr->type_num;\n\tif (itemsize == 0) itemsize = arr->itemsize;\n\ttypecode->type_num = type;\n\ttypecode->itemsize = itemsize;\n\n\t/* Don't copy if sizes are compatible */\n\tif (PyArray_EquivalentTypes(&oldtype, typecode)) {\n\t\tarrflags = arr->flags;\n\n\t\tcopy = (flags & ENSURECOPY) || \\\n\t\t\t((flags & CONTIGUOUS) && (!(arrflags & CONTIGUOUS))) \\\n\t\t\t|| (PyArray_ITEMSIZE(arr) != itemsize) || \\\n\t\t\t((flags & ALIGNED) && (!(arrflags & ALIGNED))) || \\\n\t\t\t((flags & NOTSWAPPED) && (!(arrflags & NOTSWAPPED))) \\\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 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_New(subtype, \n\t\t\t\t\t arr->nd, \n\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t type,\n\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t itemsize,\n\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t (PyObject *)arr);\n\t\t\tif (PyArray_CopyInto(ret, arr) == -1) 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 ret = (PyArrayObject *) \\\n PyArray_New(&PyArray_Type,\n arr->nd,\n arr->dimensions,\n arr->descr->type_num,\n arr->strides,\n arr->data,\n arr->itemsize,\n arr->flags,NULL);\n if (ret == NULL) return NULL;\n ret->base = (PyObject *)arr;\n ret->flags &= ~UPDATEIFCOPY;\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_CanCastSafely(PyArray_TYPE(arr), type)) {\n if ((flags & UPDATEIFCOPY) && \\\n (!PyArray_ISWRITEABLE(arr))) {\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_New(subtype, arr->nd,\n arr->dimensions, typecode->type_num,\n NULL, NULL, typecode->itemsize,\n typecode->fortran, \n (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\nstatic int\n_array_typecode_fromstr(char *str, int *swap, PyArray_Typecode *type)\n{\n int type_num;\n char typechar;\n int size;\n unsigned long number = 1;\n char *s;\n char msg[] = \"unsupported typestring\";\n \n s = (char *)&number; /* s[0] == 0 implies big-endian */\n\n *swap = 0;\n\n if (str[0] == '<' || str[0] == '>') {\n\tif ((str[0] == '<') && (s[0] == 0)) *swap = 1;\n\telse if ((str[0] == '>') && (s[0] != 0)) *swap = 1;\n }\n str += 1;\n \n#define _MY_FAIL {\t\t\t\t \\\n\t PyErr_SetString(PyExc_ValueError, msg); \\\n\t return -1;\t\t\t \\\n }\t\t\n\n typechar = str[0];\n size = atoi(str + 1);\n switch (typechar) {\n case 'b':\n\t if (size == sizeof(Bool))\n\t\t type_num = PyArray_BOOL;\t \n\t else _MY_FAIL \n\t break;\t\t \n case 'u':\n if (size == sizeof(uintp))\n type_num = PyArray_UINTP;\n\t else if (size == sizeof(char))\n\t\t type_num = PyArray_UBYTE;\n\t else if (size == sizeof(short)) \n\t\t type_num = PyArray_USHORT;\n\t else if (size == sizeof(int)) \n\t\t type_num = PyArray_UINT;\n\t else if (size == sizeof(ulong)) \n\t\t type_num = PyArray_ULONG;\n\t else if (size == sizeof(ulonglong))\n\t\t type_num = PyArray_ULONGLONG;\n\t else _MY_FAIL\n\t break;\t\t \n case 'i':\n if (size == sizeof(intp))\n type_num = PyArray_INTP;\n\t else if (size == sizeof(char)) \n\t\t type_num = PyArray_BYTE;\n\t else if (size == sizeof(short)) \n\t\t type_num = PyArray_SHORT;\n\t else if (size == sizeof(int))\n\t\t type_num = PyArray_INT;\n\t else if (size == sizeof(long)) \n\t\t type_num = PyArray_LONG;\n\t else if (size == sizeof(longlong))\n\t\t type_num = PyArray_LONGLONG;\n\t else _MY_FAIL\n\t break;\t\t \n case 'f':\n\t if (size == sizeof(float))\n\t\t type_num = PyArray_FLOAT;\n\t else if (size == sizeof(double))\n\t\t type_num = PyArray_DOUBLE;\n\t else if (size == sizeof(longdouble))\n\t\t type_num = PyArray_LONGDOUBLE;\n\t else _MY_FAIL\n\t break;\n case 'c':\n\t if (size == sizeof(float)*2)\n\t\t type_num = PyArray_CFLOAT;\n\t else if (size == sizeof(double)*2)\n\t\t type_num = PyArray_CDOUBLE;\n\t else if (size == sizeof(longdouble)*2)\n\t\t type_num = PyArray_CLONGDOUBLE;\n\t else _MY_FAIL\n\t break;\n case 'O':\n\t if (size == sizeof(PyObject *))\n\t\t type_num = PyArray_OBJECT;\n\t else _MY_FAIL\n\t break;\n case 'S':\n\t type_num = PyArray_STRING;\n\t break;\n case 'U':\n\t type_num = PyArray_UNICODE;\n\t size *= sizeof(Py_UNICODE);\n\t break;\t \n case 'V':\n\t type_num = PyArray_VOID;\n\t break;\n default:\n\t _MY_FAIL\n }\n\n#undef _MY_FAIL\n\n type->type_num = type_num;\n type->itemsize = size;\n type->fortran = 0;\n return 0;\n}\n\nstatic PyObject *\narray_frominterface(PyObject *input, PyArray_Typecode *intype, int flags)\n{\n\tPyObject *attr=NULL, *item=NULL, *r;\n\tPyArrayObject *ret=NULL;\n\tPyArray_Typecode type;\n\tchar *data;\n\tint buffer_len;\n\tint res, i, n;\n\tintp dims[MAX_DIMS], strides[MAX_DIMS];\n\tint swap;\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\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) {Py_XDECREF(attr); return NULL;}\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t}\n\telse {\n\t\tif (PyTuple_GET_SIZE(attr) != 2) {\n\t\t\tPy_DECREF(attr);\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\treturn NULL;\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\tPy_DECREF(attr);\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\treturn NULL;\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 = PyObject_GetAttrString(input, \"__array_typestr__\");\n\tif (!PyString_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_typestr__ must be a string\");\n\t\tPy_DECREF(attr);\n\t\treturn NULL;\t\n\t}\n\tres = _array_typecode_fromstr(PyString_AS_STRING(attr), &swap, &type);\n\tPy_DECREF(attr);\n\tif (res < 0) return NULL;\n \n\tattr = PyObject_GetAttrString(input, \"__array_shape__\");\n\tif (!PyTuple_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_shape__ must be a tuple\");\n\t\tPy_DECREF(attr);\n\t\treturn NULL;\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\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\treturn NULL;\n\t\t}\n\t\tfor (i=0; istrides, strides, n*sizeof(intp));\n\t}\n\n\tif (swap) {\n\t\tPyObject *tmp;\n tmp = PyArray_Byteswap(ret, TRUE);\n\t\tPy_DECREF(tmp);\n\t}\n\n\tPyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n\tr = array_fromarray(ret, intype, flags);\n\tPy_DECREF(ret);\n\treturn r;\n}\n\nstatic PyObject *\narray_fromattr(PyObject *op, PyArray_Typecode *typecode, int flags) \n{\n PyObject *new, *r;\n\t \n if (typecode->type_num == PyArray_NOTYPE) {\n new = PyObject_CallMethod(op, \"__array__\", NULL);\n } else {\n\t\tPyArray_Descr *descr;\n\t\tPyObject *obj;\n\n\t\tdescr = PyArray_DescrFromType(typecode->type_num);\n\t\tif (PyTypeNum_ISFLEXIBLE(typecode->type_num)) {\n\t\t\tobj = PyString_FromFormat(\"%c%d\", descr->type,\n\t\t\t\t\t\t typecode->itemsize);\n\t\t}\n\t\telse { \n\t\t\tobj = (PyObject *)(descr->typeobj); Py_INCREF(obj);\n\t\t}\n\t\tnew = PyObject_CallMethod(op, \"__array__\", \"N\", obj);\n }\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 r = array_fromarray((PyArrayObject *)new, typecode, flags);\n Py_DECREF(new);\n return r;\n} \n\n\nstatic PyObject *\narray_fromobject(PyObject *op, PyArray_Typecode *typecode, int min_depth, \n\t\t int max_depth, int flags) \n{\n /* This is the main code to make a NumPy array from a Python\n Object. It is called from lot's of different places which\n is why there are so many checks. The comments try to\n explain some of the checks. */\n\n\tint type = typecode->type_num;\n PyObject *r=NULL;\n\n\t/* Is input object already an array? */\n\t/* This is where the flags are used */\n if (PyArray_Check(op)) \n\t\tr = array_fromarray((PyArrayObject *)op, typecode, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, typecode);\n\t}\n\telse if (PyObject_HasAttrString(op, \"__array__\")) {\n\t\t/* Code that returns the object to convert for a non\n\t\t multiarray input object from the __array__ attribute of the\n\t\t object. */\n r = array_fromattr(op, typecode, flags);\n\t}\n\telse if (PyObject_HasAttrString(op, \"__array_shape__\") &&\n\t\t PyObject_HasAttrString(op, \"__array_typestr__\")) {\n\t\tr = array_frominterface(op, typecode, flags);\n\t}\n\telse {\n\t\tif (type == PyArray_NOTYPE) {\n\t\t\t_array_find_type(op, NULL, typecode, MAX_DIMS);\n\t\t}\n\t\tif (PySequence_Check(op))\n\t\t\tr = Array_FromSequence(op, typecode, \n\t\t\t\t\t min_depth, max_depth);\n\t\telse\n\t\t\tr = Array_FromScalar(op, typecode);\n\t}\n\n /* If we didn't succed return NULL */\n if (r == NULL) return NULL;\n\t\n\t/* Be sure we succeed here */\n\t\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"internal error: array_fromobject \"\\\n\t\t\t\t\"not producing an array\");\n\t\tPy_DECREF(r);\n return NULL;\n }\n\n if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {\n Py_DECREF(r);\n PyErr_SetString(PyExc_ValueError, \n \"object of too small depth for desired array\");\n return NULL;\n }\n if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {\n Py_DECREF(r);\n PyErr_SetString(PyExc_ValueError, \n \"object too deep for desired array\");\n return NULL;\n }\n return r;\n}\n\nstatic void\nPyArray_ArrayType(PyObject *op, PyArray_Typecode *intype, \n\t\t PyArray_Typecode *outtype) \n{\n\t_array_find_type(op, intype, outtype, MAX_DIMS);\n\treturn;\n}\n\nstatic int \nPyArray_ObjectType(PyObject *op, int minimum_type) \n{\n\tPyArray_Typecode intype, outtype;\n\tintype.type_num = minimum_type;\n\t_array_find_type(op, &intype, &outtype, MAX_DIMS);\n\treturn outtype.type_num;\n}\n\n\n\n/* flags is any of \n CONTIGUOUS, \n FORTRAN, (or set typecode->fortran=1)\n ALIGNED, \n NOTSWAPPED, \n WRITEABLE, \n ENSURECOPY, \n UPDATEIFCOPY,\n FORCECAST,\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, NOTSWAPPED, and WRITEABLE\n and therefore it is redundant to include those as well. \n\n BEHAVED_FLAGS == ALIGNED | NOTSWAPPED | WRITEABLE\n BEHAVED_FLAGS_RO == ALIGNED | NOTSWAPPED\n CARRAY_FLAGS = CONTIGUOUS | BEHAVED_FLAGS\n FARRAY_FLAGS = FORTRAN | BEHAVED_FLAGS\n \n By default, the returned array will be a copy of the object, \n (C) contiguous in memory, aligned, notswapped, and writeable.\n \n So CONTIGUOUS | ENSURECOPY passed in means that the returned\n array does not have to be CONTIGUOUS or a COPY but should be\n ALIGNED, NOTSWAPPED and WRITEABLE. \n\n typecode->fortran can be set to request a\n fortran-contiguous array. Fortran arrays are always behaved (aligned, \n notswapped, and writeable) and not (C) CONTIGUOUS. Note that either\n FORTRAN in the flag or typecode->fortran = 1 is enough to request\n a FORTRAN-style array. \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\nstatic PyObject *\nPyArray_FromAny(PyObject *op, PyArray_Typecode *typecode, int min_depth, \n\t\tint max_depth, int requires) \n{\n \tPyArray_Typecode mine = {PyArray_NOTYPE, 0, 0};\n\tPyArray_Typecode *type;\n\t\n\tif (typecode == NULL) type = &mine;\n\telse type = typecode;\n\t\t\n\tif (requires & ENSURECOPY) {\n\t\trequires |= DEFAULT_FLAGS;\n\t}\n\t/* Ensure that type->fortran and flags & FORTRAN are the\n\t same */\n\tif (requires & FORTRAN) typecode->fortran = 1;\n\tif (type->fortran == 1) {\n\t\trequires |= FARRAY_FLAGS;\n\t\tif (min_depth > 2) requires &= ~CONTIGUOUS;\n\t}\n\n\t/* make sure itemsize is not 0 unless warranted. */\n\tif ((type->itemsize == 0) && (type->type_num != PyArray_NOTYPE)) {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(type->type_num);\n\t\tif (descr != NULL) type->itemsize = descr->elsize;\n\t\telse return NULL;\n\t}\n\t\n\treturn array_fromobject(op, type, min_depth, max_depth, \n\t\t\t\trequires);\t\n}\n\n/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0, 0) */\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\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);\n Py_DECREF(op);\n return new;\n}\n\n/* These are all compressed into a single API */\n/* Deprecated calls -- Use PyArray_FromAny */\n\nstatic PyObject *\nPyArray_FromObject(PyObject *op, int type, int min_depth, int max_depth) \n{\n\tPyArray_Typecode typecode = {0, 0, 0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth,\n\t\t\t max_depth, BEHAVED_FLAGS | ENSUREARRAY);\n}\n\nstatic PyObject *\nPyArray_ContiguousFromObject(PyObject *op, int type, int min_depth, \n\t\t\t int max_depth) \n{\n\tPyArray_Typecode typecode = {0, 0, 0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth,\n\t\t\t max_depth, DEFAULT_FLAGS | ENSUREARRAY);\n}\n\nstatic PyObject *\nPyArray_CopyFromObject(PyObject *op, int type, int min_depth, \n\t\t int max_depth) \n{\n\tPyArray_Typecode typecode = {0, 0, 0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth, max_depth,\n\t\t\t ENSURECOPY | ENSUREARRAY);\n}\n\n/* End of deprecated */\n\nstatic PyObject *\nPyArray_ContiguousFromAny(PyObject *op, int type, int min_depth, \n\t\t\t int max_depth)\n{\n\tPyArray_Typecode typecode = {0,0,0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth,\n\t\t\t max_depth, DEFAULT_FLAGS);\n}\t\n\nstatic int \nPyArray_CanCastSafely(int fromtype, int totype) \n{\n\tPyArray_Descr *from, *to;\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\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 (to->elsize > from->elsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (to->elsize >= from->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (from->elsize < 8)\n return (to->elsize > from->elsize);\n else\n return (to->elsize >= from->elsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (from->elsize < 8)\n return ((to->elsize >> 1) > from->elsize);\n else\n return ((to->elsize >> 1) >= from->elsize);\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 (to->elsize > from->elsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (to->elsize >= from->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (from->elsize < 8)\n return (to->elsize > from->elsize);\n else\n return (to->elsize >= from->elsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (from->elsize < 8)\n return ((to->elsize >> 1) > from->elsize);\n else\n return ((to->elsize >> 1) >= from->elsize);\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 ((to->elsize >> 1) >= from->elsize);\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\nstatic Bool\nPyArray_CanCastTo(PyArray_Typecode *from, PyArray_Typecode *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->itemsize <= to->itemsize);\n\t\t\t}\n\t\t\telse if (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->itemsize * sizeof(Py_UNICODE)\\\n\t\t\t\t <= to->itemsize);\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->itemsize <= to->itemsize);\n\t\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 scipy's arraymap ****/\n/* and Python's array iterator ***/\n \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 = PyObject_GC_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 PyObject_GC_Track(it);\n return (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 PyObject_GC_UnTrack(it);\n Py_XDECREF(it->ao);\n PyObject_GC_Del(it);\n }\n\nstatic int\narrayiter_traverse(PyArrayIterObject *it, visitproc visit, void *arg)\n{\n if (it->ao != NULL)\n return visit((PyObject *)(it->ao), arg);\n return 0;\n}\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->itemsize;\n\tr = PyArray_New(self->ao->ob_type, 1, &count, \n\t\t\tself->ao->descr->type_num, NULL, NULL,\n\t\t\titemsize, 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->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->itemsize;\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\tr = PyArray_New(self->ao->ob_type, ind->nd, ind->dimensions,\n\t\t\tself->ao->descr->type_num, NULL, \n\t\t\tNULL, self->ao->itemsize, \n\t\t\t0, (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)->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\tint i;\n\tPyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tint 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\t\t\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\n\t/* Tuples 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\tr = PyArray_New(self->ao->ob_type, 1, &ii, \n\t\t\t\t\tself->ao->descr->type_num, NULL, \n\t\t\t\t\tNULL, self->ao->itemsize, 0,\n\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 */\n\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->itemsize;\n\t\tr = PyArray_New(self->ao->ob_type, 1, &n_steps, \n\t\t\t\tself->ao->descr->type_num, NULL, NULL,\n\t\t\t\tsize, 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)->copyswap;\n\t\twhile(n_steps--) {\n copyswap(dptr, self->dataptr, swap, size);\n\t\t\tfor(i=0; i< step_size; i++) \n\t\t\t\tPyArray_ITER_NEXT(self);\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\tif (PyArray_IsScalar(ind, Integer) || PyList_Check(ind)) {\n\t\tobj = PyArray_FromAny(ind, &indtype, 0, 0, FORCECAST);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tr = iter_subscript_Bool(self, (PyArrayObject *)obj);\n\t\t} \n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, &indtype, 0, 0, \n\t\t\t\t\t FORCECAST | BEHAVED_FLAGS);\n\t\t\tif (new==NULL) goto fail;\n\t\t\tobj = new;\n\t\t\tr = iter_subscript_int(self, (PyArrayObject *)obj);\n\t\t}\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\t\"unsupported iterator index\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPy_DECREF(obj);\n\t\treturn r;\n\t}\n\n\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\n fail:\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->itemsize;\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->copyswap;\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(self->dataptr, val->dataptr, swap,\n itemsize);\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t\tPyArray_ITER_NEXT(val);\n\t\tif (val->index==val->size) \n\t\t\tPyArray_ITER_RESET(val);\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_Typecode typecode;\n\tintp num;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\titemsize = typecode.itemsize = self->ao->itemsize;\n\ttypecode.type_num = self->ao->descr->type_num;\n copyswap = self->ao->descr->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\n\nstatic int\niter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val) \n{\n\tint i;\n\tPyObject *arrval=NULL;\n\tPyArrayIterObject *val_it=NULL;\n\tPyArray_Typecode type;\n\tPyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tint swap;\n\tint itemsize;\n\tint start, step_size;\n\tintp n_steps;\n\tPyObject *obj;\n PyArray_CopySwapFunc *copyswap;\n\t\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\ti = iter_ass_subscript(self, ind, val);\n\t\tPy_DECREF(ind);\n\t\treturn i;\n\t}\n\t\n\ttype.type_num = self->ao->descr->type_num;\n\titemsize = type.itemsize = self->ao->itemsize;\n\t\n\tarrval = PyArray_FromAny(val, &type, 0, 0, 0);\n\tif (arrval==NULL) return -1;\n\tval_it = (PyArrayIterObject *)PyArray_IterNew(arrval);\n\tif (val_it==NULL) goto fail;\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\n copyswap = PyArray_DESCR(arrval)->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\tgoto succeed;\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 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 copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, itemsize);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\tgoto succeed;\n\t\t}\n\t\twhile(n_steps--) {\n copyswap(self->dataptr, val_it->dataptr,\n swap, itemsize);\n\t\t\tfor(i=0; i < step_size; i++) \n\t\t\t\tPyArray_ITER_NEXT(self);\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\tgoto succeed;\n\t} \n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tif (PyArray_IsScalar(ind, Integer))\n\t\tobj = PyArray_FromScalar(ind, &indtype);\n\telse if (PyList_Check(ind)) {\n\t\tobj = PyArray_FromAny(ind, &indtype, 0, 0, FORCECAST);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tif (iter_ass_sub_Bool(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto fail;\n\t\t} \n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, &indtype, 0, 0, \n\t\t\t\t\t FORCECAST | BEHAVED_FLAGS);\n\t\t\tif (new==NULL) goto fail;\n\t\t\tPy_DECREF(obj);\n\t\t\tobj = new;\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 fail;\n\t\t}\n\t\telse goto fail;\n\t\tPy_DECREF(obj);\n\t\tgoto succeed;\n\t}\n\n\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\tgoto fail;\n\n succeed:\n\tPy_DECREF(val_it);\n\tPy_DECREF(arrval);\n\treturn 0;\n\n fail:\n\tPy_XDECREF(val_it);\n\tPy_XDECREF(arrval);\n\treturn -1;\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 if (PyArray_ISCONTIGUOUS(it->ao)) {\n r = PyArray_New(it->ao->ob_type, 1, &size, \n\t\t\t\tit->ao->descr->type_num,\n NULL, it->ao->data, it->ao->itemsize, \n\t\t\t\tit->ao->flags,\n (PyObject *)it->ao); \n\t\tif (r==NULL) return NULL;\n }\n else {\n r = PyArray_New(it->ao->ob_type, 1, &size, \n\t\t\t\tit->ao->descr->type_num,\n NULL, NULL, it->ao->itemsize, 0, \n (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\n\nstatic PyTypeObject PyArrayIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"scipy.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 | Py_TPFLAGS_HAVE_GC,/* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)arrayiter_traverse,\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)arrayiter_next,\t\t/* tp_iternext */\n iter_methods,\t\t\t\t/* tp_methods */\n};\n\n/** END of Array Iterator **/\n\n\n\n/*********************** Subscript Array Iterator *************************\n * *\n * This object handles subscript behavior for array objects. *\n * It is an iterator object with a next method *\n * It abstracts the n-dimensional mapping behavior to make the looping *\n * code more understandable (maybe) *\n * and so that indexing can be set up ahead of time *\n */ \n\n/* This checks the args for any fancy indexing objects */\n\n#define SOBJ_NOTFANCY 0 \n#define SOBJ_ISFANCY 1\n#define SOBJ_BADARRAY 2\n#define SOBJ_TOOMANY 3\n#define SOBJ_LISTTUP 4\n\nstatic int\nfancy_indexing_check(PyObject *args)\n{\n\tint i, n;\n\tPyObject *obj;\n\tint retval = SOBJ_NOTFANCY;\n\n\tif (PyTuple_Check(args)) {\n\t\tn = PyTuple_GET_SIZE(args);\n\t\tif (n >= MAX_DIMS) return SOBJ_TOOMANY;\n\t\tfor (i=0; i=MAX_DIMS) return SOBJ_ISFANCY;\n\t\tfor (i=0; i SOBJ_ISFANCY) return retval;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* convert an indexing object to an INTP indexing array iterator\n if possible -- otherwise, it is a Slice or Ellipsis object\n and has to be interpreted on bind to a particular \n array so leave it NULL for now.\n */\nstatic int\n_convert_obj(PyObject *obj, PyArrayIterObject **iter)\n{\n\tPyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tPyObject *arr;\n\n\tif (PySlice_Check(obj) || (obj == Py_Ellipsis))\n\t\t*iter = NULL;\n\telse {\n\t\tarr = PyArray_FromAny(obj, &indtype, 0, 0, FORCECAST);\n\t\tif (arr == NULL) return -1;\n\t\t*iter = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (*iter == NULL) return -1;\n\t}\n\treturn 0;\n}\n\n/* Adjust dimensionality and strides for index object iterators \n --- i.e. broadcast\n */\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->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->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=NULL, *obj=NULL;\n\tint i, j, n, curraxis, ellipexp, noellip;\n\tPyArrayIterObject *it;\n\tintp dimsize;\n\tintp *indptr;\n\n\t/* Remove old binding if any */\n\tPy_XDECREF(mit->ait);\n\tmit->ait = NULL;\n\n\tPy_XDECREF(mit->subspace);\n\tmit->subspace = NULL;\n\t\n\tsubnd = arr->nd - mit->numiter;\n\tif (subnd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"too many indices for array\");\n\t\treturn;\n\t}\n\n\tmit->ait = (PyArrayIterObject *)PyArray_IterNew((PyObject *)arr);\n\tif (mit->ait == NULL) return;\n\n\t/* If this is just a view, then do nothing more */\n\t/* views are handled by just adjusting the strides\n\t and dimensions of the object.\n\t*/\n\t \n\tif (mit->view) return;\n\n\t/* no subspace iteration needed. 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\tif (mit->subspace == NULL) goto fail;\n\tPy_DECREF(sub);\n\n\t/* Expand dimensions of result */\n\tn = mit->subspace->ao->nd;\n\tfor (i=0; idimensions[mit->nd+i] = mit->subspace->ao->dimensions[i];\n\tmit->nd += n;\n\n\t/* Now, we still need to interpret the ellipsis and slice objects \n\t to determine which axes the indexing arrays are referring to\n\t*/\n\tn = PyTuple_GET_SIZE(mit->indexobj);\n\n\t/* The number of dimensions an ellipsis takes up */\n\tellipexp = arr->nd - n + 1;\n\t/* Now fill in iteraxes -- remember indexing arrays have been \n converted to 0's in mit->indexobj */\n\tcurraxis = 0;\n\tj = 0;\n\tnoellip = 1; /* Only expand the first ellipsis */\n\tmemset(mit->bscoord, 0, sizeof(intp)*arr->nd);\n\tfor (i=0; iindexobj, i);\n\t\tif (PyInt_Check(obj) || PyLong_Check(obj)) \n\t\t\tmit->iteraxes[j++] = curraxis++;\n\t\telse if (noellip && obj == Py_Ellipsis) {\n\t\t\tcurraxis += ellipexp;\n\t\t\tnoellip = 0;\n\t\t}\n\t\telse {\n\t\t\tint start=0;\n\t\t\tint 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}\t\t\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn;\n\n fail:\n\tPy_XDECREF(sub);\n\tPy_XDECREF(mit->ait);\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_Typecode typecode = {PyArray_BOOL, 0, 0};\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\tba = (PyArrayObject *)PyArray_FromAny(myBool, &typecode, 0, 0, \n\t\t\t\t\t CARRAY_FLAGS);\n\tif (ba == NULL) return -1;\n\tnd = ba->nd;\n\tfor (j=0; jdata;\n\tcount = 0;\n\n\t/* pre-determine how many nonzero entries there are */\n\tfor (i=0; iao->data;\n\t\tcoords[j] = 0;\n\t\tdims_m1[j] = ba->dimensions[j]-1;\n\t}\n\n\tptr = (Bool *)ba->data;\n\n\tif (count == 0) return nd;\n\n\t/* Loop through the Boolean array and copy coordinates\n\t for non-zero entries */\n\tfor (i=0; i=0; j--) {\n\t\t\tif (coords[j] < dims_m1[j]) {\n\t\t\t\tcoords[j]++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcoords[j] = 0;\n\t\t\t}\n\t\t}\n\t}\n\treturn nd;\n\n fail:\n\tfor (j=0; jiters[i] = NULL;\n \tmit->view = 0;\n \tmit->index = 0;\n \tmit->ait = NULL;\n \tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tfancy = fancy_indexing_check(indexobj);\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\tif (fancy == SOBJ_NOTFANCY) { /* bail out */\n\t\tmit->view = 1;\n\t\tgoto ret;\n\t}\n\n\tif (fancy == SOBJ_BADARRAY) {\n\t\tPyErr_SetString(PyExc_TypeError,\t\t\t\\\n\t\t\t\t\"arrays used as indexes must be of \" \\\n\t\t\t\t\"integer type\");\n\t\tgoto fail;\n\t}\n\tif (fancy == SOBJ_TOOMANY) {\n\t\tPyErr_SetString(PyExc_TypeError, \"too many indicies\");\n\t\tgoto fail;\n\t}\n\n\tif (fancy == SOBJ_LISTTUP) {\n\t\tPyObject *newobj;\n\t\tnewobj = PySequence_Tuple(indexobj);\n\t\tif (newobj == NULL) goto fail;\n\t\tPy_DECREF(indexobj);\n\t\tindexobj = newobj;\n\t\tmit->indexobj = indexobj;\n\t}\n\n#undef SOBJ_NOTFANCY \n#undef SOBJ_ISFANCY \n#undef SOBJ_BADARRAY \n#undef SOBJ_TOOMANY \n#undef SOBJ_LISTTUP \n\n\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\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 (PyList_Check(indexobj) || PyArray_Check(indexobj)) {\n\t\tmit->numiter = 1;\n\t\tarr = PyArray_FromAny(indexobj, &indtype, 0, 0, FORCECAST);\n\t\tif (arr == NULL) goto fail;\n\t\tmit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (mit->iters[0] == NULL) 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(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\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = new;\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\t/* Store the number of iterators actually converted */\n\t\t/* These will be mapped to actual axes at bind time */\n\t\tif (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)\n\t\t\tgoto fail;\n\t}\n\n ret:\n PyObject_GC_Track(mit);\n return (PyObject *)mit;\n \n fail:\n\tPy_XDECREF(arr);\n\tPy_XDECREF(mit->indexobj);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n PyObject_GC_Del(mit);\n\treturn NULL;\n}\n\n\n/* return unbound mapiter object */\n\nstatic PyObject *\narraymapiter_new(PyTypeObject *type, PyObject *args, PyObject *kwds) \n{\n\tPyObject *newtup, *res;\n\tint n;\n\n\tif (!PyTuple_Check(args)) {\n\t\tPyErr_BadInternalCall();\n\t\treturn NULL;\n\t}\n\n\tn = PyTuple_GET_SIZE(args);\n\t\n\tif (n < 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"must be initialized with >= 1 argument\");\n\t\treturn NULL;\n\t}\n\t\n\tif (n > 1) {\n\t\tnewtup = PyTuple_GetSlice(args, 0, n);\n\t\tif (newtup == NULL) return NULL;\n\t\tres = PyArray_MapIterNew(newtup);\n\t\tPy_DECREF(newtup);\n\t}\n\telse { /* n == 1 */\n\t\tnewtup = PyTuple_GET_ITEM(args, 0);\n\t\tres = PyArray_MapIterNew(newtup);\n\t}\n\n\treturn res; \t\n}\n\n\n/* Returns a 0-dim array holding the element desired */\n/*\nstatic PyObject *\narraymapiter_next(PyArrayMapIterObject *mit)\n{\n\tPyObject *ret;\n\tif (mit->ait == NULL) return NULL;\n\tif (mit->view) return NULL;\n\tif (mit->index < mit->size) {\n\t\tret = PyArray_ToScalar(mit->dataptr, mit->ait->ao);\n\t\tPyArray_MapIterNext(mit);\n\t\treturn ret;\n\t}\n return NULL;\n}\n*/\n\nstatic void\narraymapiter_dealloc(PyArrayMapIterObject *mit)\n{\n\tint i;\n PyObject_GC_UnTrack(mit);\n Py_XDECREF(mit->ait);\n\tPy_XDECREF(mit->indexobj);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n PyObject_GC_Del(mit);\n}\n\nstatic int\narraymapiter_traverse(PyArrayMapIterObject *mit, visitproc visit, void *arg)\n{\n\tint ret, i;\n if (mit->ait != NULL)\n if ((ret = visit((PyObject *)(mit->ait), arg)) != 0) \n\t\t\treturn ret;\t\n\n\tif (mit->iters != NULL) \n\t\tfor (i=0; inumiter; i++) \n\t\t\tif (mit->iters[i] != NULL) \n\t\t\t\tif ((ret=visit((PyObject *)mit->iters[i], \n\t\t\t\t\t arg)) != 0)\n\t\t\t\t\treturn ret;\n\n\tif (mit->indexobj != NULL)\n\t\tif ((ret = visit(mit->indexobj, arg)) != 0) return ret;\n\t\n return 0;\n}\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 MapIterNew must be \n that does not work. 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 char doc_mapiter_bind[] = \"obj.bind(a)\\n Bind an array to the \"\\\n\t\"mapiter object\";\n\nstatic PyObject *\nmapiter_bind(PyArrayMapIterObject *mit, PyObject *args)\n{\n\tPyArrayObject *arr;\n\n if (!PyArg_ParseTuple(args, \"O!\", &PyArray_Type, &arr)) return NULL;\n\n \tPyArray_MapIterBind(mit, arr);\n\n\tif (mit->ait == NULL) return NULL;\n\t\n \tPyArray_MapIterReset(mit);\n\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyMethodDef mapiter_methods[] = {\n\t{\"bind\", (PyCFunction)mapiter_bind, 1, doc_mapiter_bind},\n {NULL,\t\tNULL}\t\t\n};\n*/\n\n\nstatic PyTypeObject PyArrayMapIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"scipy.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 | Py_TPFLAGS_HAVE_GC,/* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)arraymapiter_traverse,\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, /*arraymapiter_next,*/\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 (newfunc)arraymapiter_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n\n};\n\n/** END of Subscript Iterator **/\n\n\n\n", "source_code_before": " /*\n Provide multidimensional arrays as a basic object type in python. \n\nBased on Original Numeric implementation\nCopyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\nwith contributions from many Numeric Python developers 1995-2004 *\n\nHeavily modified in 2005 with inspiration from Numarray \n\nby\n\nTravis Oliphant\nAssistant Professor at\nBrigham Young University \n\nmaintainer email: oliphant.travis@ieee.org\n\nNumarray design (which provided guidance) by \nSpace Science Telescope Institute \n (J. Todd Miller, Perry Greenfield, Rick White)\n\n*/\n\n/* $Id: arrayobject.c,v 1.59 2005/09/14 00:14:00 teoliphant Exp $ */\n\n/*\n#include \"Python.h\"\n#include \"structmember.h\"\n\n#define _MULTIARRAYMODULE\n#include \"Numeric3/arrayobject.h\"\n*/\n\n/* Helper functions */\n\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\n\nstatic intp\nPyArray_PyIntAsIntp(PyObject *o)\n{\n\tlonglong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr=NULL;\n\tPyArray_Typecode typecode = {PyArray_INTP, 0, 0};\n\tintp ret;\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\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\tarr = PyArray_CastToType((PyArrayObject *)o, &typecode);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tarr = PyArray_FromScalar(o, &typecode);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((intp *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\t\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONGLONG != SIZEOF_PY_INTPTR_T)\n\tif ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C intp\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (intp) long_value;\n}\n\n\nstatic PyObject *array_int(PyArrayObject *v);\n\nstatic int\nPyArray_PyIntAsInt(PyObject *o)\n{\n\tlong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr=NULL;\n\tPyArray_Typecode typecode = {PyArray_INT, 0, 0};\n\tint ret;\n\t\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\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\tarr = PyArray_CastToType((PyArrayObject *)o, &typecode);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tarr = PyArray_FromScalar(o, &typecode);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((int *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONG != SIZEOF_INT)\n\tif ((long_value < INT_MIN) || (long_value > INT_MAX)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C int\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (int) long_value;\n}\n\n\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\nstatic char *\nPyArray_Zero(PyArrayObject *arr)\n{\n char *zeroval;\n char *buf;\n int buf_len;\n PyObject *obj, *ret;\n\n zeroval = PyDataMem_NEW(arr->itemsize);\n if (zeroval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n if (PyArray_ISOBJECT(arr)) {\n obj=PyInt_FromLong((long) 0);\n memcpy(zeroval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return zeroval;\n }\n ret = PyObject_GetAttrString((PyObject *)arr, \"_zero\");\n if (ret != NULL) {\n if (PyObject_AsReadBuffer(ret, (const void **)&buf, \n &buf_len) < 0) {\n PyErr_SetString(PyExc_ValueError, \n \"_zero not returning \" \\\n \"writeable buffer\");\n Py_DECREF(ret);\n return NULL;\n }\n memcpy(zeroval, buf, buf_len);\n Py_DECREF(ret);\n }\n if (PyErr_Occurred()) PyErr_Clear();\n memset(zeroval, 0, arr->itemsize);\n return zeroval;\n}\n\nstatic char *\nPyArray_One(PyArrayObject *arr)\n{\n char *oneval;\n char *buf;\n int buf_len, ret2;\n PyObject *obj, *ret;\n\n oneval = PyDataMem_NEW(arr->itemsize);\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 ret = PyObject_GetAttrString((PyObject *)arr, \"_one\");\n if (ret != NULL) {\n if (PyObject_AsReadBuffer(ret, (const void **)&buf, \n &buf_len) < 0) {\n PyErr_SetString(PyExc_ValueError, \n \"_one not returning \" \\\n \"writeable buffer\");\n Py_DECREF(ret);\n PyDataMem_FREE(oneval);\n return NULL;\n }\n memcpy(oneval, buf, buf_len);\n Py_DECREF(ret);\n }\n if (PyErr_Occurred()) PyErr_Clear();\n\n ret2 = arr->descr->setitem(obj, oneval, arr);\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->itemsize;\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 *)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 { free(new_data); return NULL; }\n}\n\n/* end Helper functions */\n\n\nstatic PyObject *PyArray_New(PyTypeObject *, int nd, intp *, \n int, intp *, char *, 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. */\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/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\n\nstatic char *\nindex2ptr(PyArrayObject *mp, int i) \n{\n\tif (i==0 && (mp->nd == 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\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\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->copyswap;\n\tcopyswapn = dest->descr->copyswapn;\n\n elsize = dest->itemsize;\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->itemsize;\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\tPyArray_Typecode typecode;\n\n\n\ttypecode.type_num = dest->descr->type_num;\n\ttypecode.itemsize = dest->itemsize;\n\ttypecode.fortran = PyArray_ISFORTRAN(dest);\n\t\t\t\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n\t\t\t\t\t &typecode, 0,\n\t\t\t\t\t dest->nd, 0);\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\nstatic PyObject *\nPyArray_FromDimsAndDataAndDescr(int nd, int *d, \n PyArray_Descr *descr,\n char *data) {\n\tPyObject *ret;\n\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\n\tintp newd[MAX_DIMS];\n\t\n\tfor (i=0; itype_num, NULL, data, descr->elsize, \n\t\t\t CARRAY_FLAGS, NULL);\n#else\n\tret = PyArray_New(&PyArray_Type, nd, (intp *)d, \n descr->type_num, NULL, data, descr->elsize, \n\t\t\t CARRAY_FLAGS, NULL);\n#endif\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_FromDimsAndData(int nd, int *d, int type, char *data) \n{\n\tPyObject *ret;\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\t\n\tintp newd[MAX_DIMS];\n\n\tfor (i=0; iob_type, m1->nd, \n\t\t\t\t\t m1->dimensions,\n\t\t\t\t\t m1->descr->type_num,\n\t\t\t\t\t NULL, NULL, m1->itemsize,\n\t\t\t\t\t 0, (PyObject *)m1);\n\t\n if (PyArray_CopyInto(ret, m1) == -1) return NULL;\n\t\n return (PyObject *)ret;\n}\n\n\nstatic PyObject *array_item(PyArrayObject *, int);\n\nstatic PyObject *\nPyArray_Scalar(char *data, int type_num, int itemsize, int swap)\n{\n PyArray_Descr *descr;\n\tPyTypeObject *type;\n\tPyObject *obj;\t\n\tchar *destptr;\n PyArray_CopySwapFunc *copyswap;\n\n descr = PyArray_DescrFromType(type_num);\n if (descr == NULL) return NULL;\n type = descr->typeobj;\n copyswap = descr->copyswap;\n\tif (type_num == PyArray_STRING) \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_ISFLEXIBLE(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 {\n\t\t\tdestptr = PyDataMem_NEW(itemsize);\n\t\t\tif (destptr == NULL) {\n\t\t\t\tPyObject_Del(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tif (type_num == PyArray_UNICODE) {\n\t\t\t\tPyUnicode_AS_UNICODE(obj) = \\\n\t\t\t\t\t(Py_UNICODE *)destptr;\n\t\t\t\t((PyUnicodeObject*)obj)->length = itemsize / \\\n\t\t\t\t\tsizeof(Py_UNICODE);\n\t\t\t\t((PyUnicodeObject*)obj)->hash = -1;\n\t\t\t}\n\t\t\telse {\n\t\t\t\t((PyVoidScalarObject *)obj)->obval = destptr;\n\t\t\t\t((PyVoidScalarObject *)obj)->ob_size = itemsize;\n\t\t\t}\n\t\t}\n\t}\n\telse {\n\t\tdestptr = &(((PyScalarObject*)obj)->obval);\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*/\nstatic PyObject *\nPyArray_ToScalar(char *data, PyArrayObject *arr)\n{\n\tint type_num = arr->descr->type_num;\n\tint itemsize = arr->itemsize;\n int swap = !(PyArray_ISNOTSWAPPED(arr));\n\n\treturn PyArray_Scalar(data, type_num, itemsize, swap);\n}\n\n\n/* Return Python scalar if 0-d array object is encountered */\n\nstatic PyObject *\nPyArray_Return(PyArrayObject *mp) \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((PyObject *)mp) && 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*/\nstatic int \nPyArray_RegisterDataType(PyTypeObject *type)\n{\n\tPyArray_Descr *descr;\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 = malloc(sizeof(PyArray_Descr));\n\tmemcpy(descr, PyArray_DescrFromType(PyArray_VOID), \n\t sizeof(PyArray_Descr));\n\ttypenum = PyArray_USERDEF + PyArray_NUMUSERTYPES;\n\tdescr->type_num = typenum;\n\tdescr->typeobj = 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 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 frees the copy of the Descr_table already there.\n places a pointer to the new one into the slot.\n*/\nstatic int\nPyArray_RegisterDescrForType(int typenum, PyArray_Descr *descr)\n{\n\tPyArray_Descr *old;\n\tint i;\n\n\tif (!PyTypeNum_ISUSERDEF(typenum)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"data type not registered\");\n\t\treturn -1;\n\t}\n\told = userdescrs[typenum-PyArray_USERDEF];\n\tdescr->typeobj = old->typeobj;\n\tdescr->type_num = typenum;\n\n#define _NULL_CHECK(member) \\\n\tif (descr->member == NULL) descr->member = old->member\n\n\tfor (i=0; imember == 0) descr->member = old->member\n\n\t_ZERO_CHECK(kind);\n\t_ZERO_CHECK(type);\n\t_ZERO_CHECK(elsize);\n\t_ZERO_CHECK(alignment);\n#undef _ZERO_CHECK\n\n\tfree(old);\n\tuserdescrs[typenum-PyArray_USERDEF] = descr;\n\treturn 0;\n}\n\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 n3 = strlen((const char *)sep);\n if (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 \"\\\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->itemsize,\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->itemsize,\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 = strlen((const char *)format);\n while(it->index < it->size) {\n obj = self->descr->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\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->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\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 if (PyArray_TYPE(self) == PyArray_OBJECT) {\n PyErr_SetString(PyExc_ValueError, \"a string for the data\"\\\n\t\t\t\t\"in an object array is not appropriate\");\n return NULL;\n }\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->itemsize;\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 != NULL)) {\n\t\t/* Free internal references if an Object array */\n\t\tPyArray_XDECREF(self);\n\n PyDataMem_FREE(self->data);\n }\n\t\n if (self->dimensions != NULL) {\n PyDimMem_FREE(self->dimensions); \n\t}\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\n\nstatic PyObject *\narray_item(PyArrayObject *self, int i) \n{\n char *item;\n PyArrayObject *r;\n\n\n\tif(self->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n if ((item = index2ptr(self, i)) == NULL) return NULL;\n\n\tr = (PyArrayObject *)PyArray_New(self->ob_type, \n\t\t\t\t\t self->nd-1, self->dimensions+1, \n\t\t\t\t\t self->descr->type_num, \n\t\t\t\t\t self->strides+1, item, \n\t\t\t\t\t self->itemsize, self->flags,\n\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_item(self, i));\n}\n\n\nstatic int \narray_ass_item(PyArrayObject *self, int 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\n if (i < 0) i = i+self->dimensions[0];\n\n if (self->nd > 1) {\n if((tmp = (PyArrayObject *)array_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->setitem(v, item, self) == -1) return -1;\n return 0;\n}\n\n/* -------------------------------------------------------------- */\nstatic int\nslice_coerce_index(PyObject *o, int *v)\n{\n\t*v = PyArray_PyIntAsInt(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, int length,\n int *start, int *stop, int *step,\n intp *slicelength)\n{\n\tint 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 int\nparse_subindex(PyObject *op, int *step_size, intp *n_steps, int max)\n{\n\tint 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\tint 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_PyIntAsInt(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, start, offset, n_add, n_pseudo;\n int step_size;\n\tintp n_steps;\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, *tup;\n\tint n1, n2, n3, val;\n\tint i;\n\n\ttup = PyTuple_New(mit->nd);\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\tPyTuple_SET_ITEM(tup, i++, PyInt_FromLong((long)val++));\n\tval = 0;\n\twhile(val < n1)\n\t\tPyTuple_SET_ITEM(tup, i++, PyInt_FromLong((long)val++));\n\tval = n1+n2;\n\twhile(val < n3)\n\t\tPyTuple_SET_ITEM(tup, i++, PyInt_FromLong((long)val++));\n\n\tnew = PyArray_Transpose(*ret, tup);\n\tPy_DECREF(tup);\n\tPy_DECREF(*ret);\n\t*ret = (PyArrayObject *)new;\n}\n\n\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\tret = (PyArrayObject *)\\\n\t\tPyArray_New(temp->ob_type, mit->nd, mit->dimensions, \n\t\t\t temp->descr->type_num, NULL, NULL, \n\t\t\t temp->itemsize, \n\t\t\t PyArray_ISFORTRAN(temp),\n\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\treturn NULL;\n\tindex = it->size;\n\tswap = ((temp->flags & NOTSWAPPED) != (ret->flags & NOTSWAPPED));\n copyswap = ret->descr->copyswap;\n\tPyArray_MapIterReset(mit);\n\twhile (index--) {\n copyswap(it->dataptr, mit->dataptr, swap, ret->itemsize);\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\tPyArray_Typecode typecode = {0, 0, 0};\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Unbound Map Iterator */\n\tif (mit->ait == NULL) return -1;\n\n\ttypecode.type_num = mit->ait->ao->descr->type_num;\n\ttypecode.itemsize = mit->ait->ao->itemsize;\n\n\tarr = PyArray_FromAny(op, &typecode, \n\t\t\t 0, 0, FORCECAST);\n\tif (arr == NULL) return -1;\n\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, (PyArrayObject **)&arr);\n\t\t}\n\t}\n\t\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) \n\t\treturn -1;\n\n\tindex = mit->size;\n\tswap = ((mit->ait->ao->flags & NOTSWAPPED) != \\\n\t\t(PyArray_FLAGS(arr) & NOTSWAPPED));\n\n copyswap = PyArray_DESCR(arr)->copyswap;\n\tPyArray_MapIterReset(mit);\n /* Need to decref OBJECT arrays */\n if (PyTypeNum_ISOBJECT(typecode.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 copyswap(mit->dataptr, NULL, swap, \n sizeof(PyObject *));\n PyArray_MapIterNext(mit);\n PyArray_ITER_NEXT(it);\n if (it->index == it->size)\n PyArray_ITER_RESET(it);\n }\n return 0;\n }\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\treturn 0;\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 0-dimensional arrays */\n\nstatic PyObject *\narray_subscript(PyArrayObject *self, PyObject *op) \n{\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n\tintp offset;\n int nd, i;\n PyArrayObject *other;\n\tPyArrayMapIterObject *mit;\n\n if (PyArray_IsScalar(op, Integer) || PyInt_Check(op) || \\\n PyLong_Check(op)) {\n intp value;\n value = PyArray_PyIntAsIntp(op);\n if (PyErr_Occurred())\n PyErr_Clear();\n else if (value >= 0) {\n if (value <= MAX_INT)\n return array_item(self, (int) value);\n }\n else if (value < 0) {\n if (value >= -MAX_INT) {\n if (self->nd > 0) value += self->dimensions[0];\n return array_item(self, (int) value);\n }\n }\n }\n\n\tif (PyArrayMapIter_Check(op)) {\n\t\tmit = (PyArrayMapIterObject *)op;\n\t\t/* bind to current array */\n\t\tPyArray_MapIterBind(mit, self);\n\t\t\n\t\t/* If the mapiterator was created with standard indexing\n\t\t behavior, fall through to view-based code */\n\t\tif (!mit->view) return PyArray_GetMap(mit);\n\t\top = mit->indexobj;\n\t}\n\telse { /* wrap arguments into a mapiter object */\n\t\tmit = (PyArrayMapIterObject *)PyArray_MapIterNew(op);\n\t\tif (mit == NULL) return NULL;\n\t\tif (!mit->view) { /* fancy indexing */\n\t\t\tPyArray_MapIterBind(mit, self);\n\t\t\tother = (PyArrayObject *)PyArray_GetMap(mit);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn (PyObject *)other;\n\t\t}\n\t\tPy_DECREF(mit);\n\t}\n\n\ti = PyArray_PyIntAsInt(op);\n\tif (!error_converting(i)) {\n\t\tif (i < 0 && self->nd > 0) i = i+self->dimensions[0];\n\t\treturn array_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\tif ((other = (PyArrayObject *)\t\t\t\t\t\\\n\t PyArray_New(self->ob_type, nd, dimensions, self->descr->type_num,\n\t\t\t strides, self->data+offset, \n\t\t\t self->itemsize, self->flags,\n\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 \narray_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op) \n{\n int ret, 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\n\tif (PyArrayMapIter_Check(index)) {\n\t\tmit = (PyArrayMapIterObject *)index;\n\t\t/* bind behavior to current array */\n\t\tPyArray_MapIterBind(mit, self);\n\t\t\t\n\t\t/* fall through if standard view-based map iterator */\n\t\tif (!mit->view) return PyArray_SetMap(mit, op);\n\t\tindex = mit->indexobj;\n\t}\n\telse {\n\t\tmit = (PyArrayMapIterObject *)PyArray_MapIterNew(index);\n\t\tif (mit == NULL) return -1;\n\t\tif (!mit->view) {\n\t\t\tPyArray_MapIterBind(mit, self);\n\t\t\tret = PyArray_SetMap(mit, op);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn ret;\n\t\t}\n\t\tPy_DECREF((PyObject*)mit);\n\t}\n\n\ti = PyArray_PyIntAsInt(index);\n\tif (!error_converting(i)) {\n\t\treturn array_ass_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 ret = PyArray_CopyObject(tmp, op);\n Py_DECREF(tmp);\n\t\n return ret;\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 \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\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}\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}\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 PyObject *args, *ret;\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n args = Py_BuildValue(\"(OO)\", m1, m2);\n ret = PyObject_Call(op, args, NULL);\n Py_DECREF(args);\n return ret;\n}\n\nstatic PyObject *\nPyArray_GenericUnaryFunction(PyArrayObject *m1, PyObject *op) \n{\n PyObject *args, *ret;\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n args = Py_BuildValue(\"(O)\", m1);\n ret = PyObject_Call(op, args, NULL);\n Py_DECREF(args);\n return ret;\n}\n\nstatic PyObject *\nPyArray_GenericInplaceBinaryFunction(PyArrayObject *m1, \n\t\t\t\t PyObject *m2, PyObject *op) \n{\n PyObject *args, *ret;\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n args = Py_BuildValue(\"(OOO)\", m1, m2, m1);\n ret = PyObject_Call(op, args, NULL);\n Py_DECREF(args);\n return ret;\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_all_nonzero(PyArrayObject *mp) \n{\n\tintp index;\n\tPyArrayIterObject *it;\n\tBool anyTRUE = 0;\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->nonzero(it->dataptr, mp)) {\n\t\t\tanyTRUE = 1;\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 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->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->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->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->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->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_all_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 r = (PyArrayObject *)\\\n\t\tPyArray_New(self->ob_type, self->nd, self->dimensions, \n\t\t\t self->descr->type_num, self->strides, data,\n\t\t\t self->itemsize, 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 any(self == el) */\n\n return PyObject_RichCompareBool((PyObject *)self, el, Py_EQ);\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 *)realloc(*string, *max_n); }\n\t\n if (nd == 0) {\n\t\t\n if ((op = descr->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\tfree(string); return NULL; \n\t}\n\t\n\tif (PyArray_ISFLEXIBLE(self)) {\n\t\tchar buf[100];\n\t\tsnprintf(buf, sizeof(buf), \"%d\", self->itemsize);\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 free(string);\n return ret;\n}\n\nstatic PyObject *PyArray_StrFunction=NULL;\nstatic PyObject *PyArray_ReprFunction=NULL;\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\n\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) \n{\n PyObject *array_other, *result;\n\n switch (cmp_op) \n {\n case Py_LT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less);\n case Py_LE:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less_equal);\n case Py_EQ:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then return the integer\n\t\t\t object 0. This fixes code that used to\n\t\t\t allow equality comparisons between arrays\n\t\t\t and other objects which would give a result\n\t\t\t of 0\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n result = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.equal);\n /* If the comparison results in NULL, then the \n\t\t\t two array objects can not be compared together so \n\t\t\t return zero \n */\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n return result;\n case Py_NE:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then objects cannot be \n\t\t\t compared and cannot be equal, therefore, \n\t\t\t return True;\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n result = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.not_equal);\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n return result;\n case Py_GT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.greater);\n case Py_GE:\n return PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t other, \n\t\t\t\t\t \t n_ops.greater_equal);\n }\n return NULL;\n}\n\nstatic PyObject *\n_check_axis(PyArrayObject *arr, int *axis, int flags)\n{\n\tPyObject *temp;\n\tint n = arr->nd;\n\n\tif ((*axis >= MAX_DIMS) || (n==0)) {\n\t\ttemp = PyArray_Ravel(arr,0);\n\t\t*axis = 0;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_FromAny((PyObject *)arr, NULL, \n\t\t\t\t\t 0, 0, flags);\n\t\t\tif (temp == NULL) return NULL;\n\t\t}\n\t\telse {\n\t\t\tPy_INCREF(arr);\n\t\t\ttemp = (PyObject *)arr;\n\t\t}\n\t}\n\tif (*axis < 0) *axis += n;\n\tif ((*axis < 0) || (*axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", *axis);\n\t\tPy_DECREF(temp);\n\t\treturn NULL;\n\t}\n\treturn temp;\n}\n\n#include \"arraymethods.c\"\n\n/* Lifted from numarray */\nstatic PyObject *\nPyArray_IntTupleFromIntp(int len, intp *vals)\n{\n\tint i;\n PyObject *intTuple = PyTuple_New(len);\n if (!intTuple) goto fail;\n for(i=0; ind == 0) return 1;\n\tsd = ap->itemsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\n\t}\n\treturn 1;\n}\n\n\nstatic int \n_IsFortranContiguous(PyArrayObject *ap) \n{\n\tint sd;\n\tint i;\n\t\n\tif (ap->nd == 0) return 1;\n\tsd = ap->itemsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i=0; i< ap->nd; ++i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\n\t}\n\treturn 1;\n}\n\nstatic int\n_IsAligned(PyArrayObject *ap) \n{\n\tint i, alignment, aligned=1;\n\tintp ptr;\n\tint type = ap->descr->type_num;\n\n\tif ((type == PyArray_STRING) || (type == PyArray_VOID))\n\t\treturn 1;\n\n\talignment = ap->descr->alignment;\n\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\tPyBufferProcs *pb;\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\tpb = base->ob_type->tp_as_buffer;\n\tif (pb == NULL || pb->bf_getwritebuffer == NULL)\n\t\treturn FALSE;\n\t\n\treturn TRUE;\n}\n\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\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not \n walk outside of the memory implied by either numbytes or\n a single segment array of the provided dimensions and element size if\n numbytes is 0 */\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, \n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\t\n\tif (numbytes == 0) \n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\t\n\tfor (i=0; i numbytes) {\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\treturn TRUE;\n\t\n}\n\n\n/* This is the main array creation routine. */\n\n/* Flags argument has multiple related meanings \n depending on data and strides: \n\n If data is given, then flags is flags associated with data. \n If strides is not given, then a contiguous strides array will be created\n and the CONTIGUOUS bit will be set. If the flags argument \n has the FORTRAN bit set, then a FORTRAN-style strides array will be\n created (and of course the FORTRAN flag bit will be set). \n\n If data is not given but created here, then flags will be DEFAULT_FLAGS\n and a non-zero flags argument can be used to indicate a FORTRAN style\n array is desired. \n*/\n\nstatic intp\n_array_fill_strides(intp *strides, intp *dims, int nd, intp itemsize, \n\t\t int inflag, int *objflags) \n{\n\tint i;\n\t/* Only make Fortran strides if not contiguous as well */\n\tif ((inflag & FORTRAN) && !(inflag & CONTIGUOUS)) {\n\t\tfor (i=0; i 1) *objflags &= ~CONTIGUOUS;\n\t\telse *objflags |= CONTIGUOUS;\n\t}\n\telse {\n\t\tfor (i=nd-1;i>=0;i--) {\n\t\t\tstrides[i] = itemsize;\n\t\t\titemsize *= dims[i] ? dims[i] : 1;\n\t\t}\n\t\t*objflags |= CONTIGUOUS;\n\t\tif (nd > 1) *objflags &= ~FORTRAN;\n\t\telse *objflags |= FORTRAN;\n\t}\n\treturn itemsize;\n}\n\n\t\nstatic PyObject *\nPyArray_New(PyTypeObject *subtype, int nd, intp *dims, int type_num,\n intp *strides, char *data, int itemsize, int flags,\n\t PyObject *obj)\n{\n\tPyArrayObject *self;\n\tPyArray_Descr *descr;\n\tregister int i;\n\tintp sd, temp=-1;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\tif (descr == NULL) return NULL;\n\n\tif (nd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"number of dimensions must be >=0\");\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 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\treturn NULL;\n\t\t}\n\t}\n\t\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) return NULL;\t\n\tself->descr = descr;\n\tself->dimensions = 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\n\tif (PyTypeNum_ISFLEXIBLE(type_num)) {\n\t\tif (itemsize < 1) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"type must provide an itemsize\");\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn NULL;\n\t\t}\n\t\tself->itemsize = itemsize;\n\t\t/* Guarantee that these kind of arrays are never byteswapped\n\t\t unknowingly. \n\t\t*/\n\t\tif (type_num != PyArray_UNICODE)\n\t\t\tself->flags |= NOTSWAPPED;\n\t}\n\telse self->itemsize = descr->elsize; \n\t\t\n\tsd = self->itemsize;\n\t\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn PyErr_NoMemory();\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\tPyDimMem_FREE(self->dimensions);\n\t\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\t\treturn NULL;\n\t\t\t}\t\t\t\t\n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t}\n \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 (a.data) doesn't work\n\t\t as it should. */\n\n\t\tif (sd==0) sd = sizeof(intp);\n\n\t\tif ((data = PyDataMem_NEW(sd))==NULL) {\n\t\t\tPyDimMem_FREE(self->dimensions);\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn PyErr_NoMemory();\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\n\t\t/* It is bad to have unitialized OBJECT pointers */\n\t\t/* We shouldn't need to check for the OBJECT Letter\n\t\t but perhaps it's best. */\n\t\tif (type_num == PyArray_OBJECT || \\\n\t\t type_num == PyArray_OBJECTLTR) {\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\tself->nd = nd;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\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;\n\t\tif (temp==-1) { /* 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\tres = PyObject_CallMethod((PyObject *)self, \n\t\t\t\t\t \"__array_finalize__\",\n\t\t\t\t\t \"O\", obj);\n\t\tif (res == NULL) {\n\t\t\tPyDimMem_FREE(self->dimensions);\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn NULL;\n\t\t}\n\t\telse Py_DECREF(res);\n\t}\n\n\treturn (PyObject *)self;\n}\n\n\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\n newsize = PyArray_MultiplyList(new_dimensions, new_nd);\n\n if (newsize == 0) {\n PyErr_SetString(PyExc_ValueError, \n \"newsize is zero; cannot delete an array \"\\\n \"in this way\");\n return NULL;\n }\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 = (((PyObject *)self)->ob_refcnt);\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\n\t\t/* Reallocate space if needed */\n\t\tnew_data = PyDataMem_RENEW(self->data, \n\t\t\t\t\t newsize*(self->itemsize));\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->itemsize;\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->itemsize;\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 */\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; idataptr, fromptr, itemsize);\n\t\t\tPyArray_ITER_NEXT(iter);\n\t\t}\n\n\t\tPy_DECREF(iter);\n\t\tPy_DECREF(behaved);\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\", \"strides\", \n \"swap\", \"fortran\", NULL};\n\tint itemsize = 0;\n\tPyArray_Typecode typecode = {PyArray_NOTYPE, 0, 0};\n\tint type_num = PyArray_NOTYPE;\n PyArray_Dims dims = {NULL, 0};\n PyArray_Dims strides = {NULL, 0};\n PyArray_Chunk buffer;\n\tint fortran = 0;\n int swapped = 0;\n\tPyArrayObject *ret;\n\n\tbuffer.ptr = NULL; \n /* Usually called with shape and type\n but can also be called with buffer, strides, and swapped info\n */\n\n\t/* For now, let's just use this to create an empty, contiguous \n\t array of a specific type and shape. \n\t*/\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&O&ii\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &dims, \n PyArray_TypecodeConverter,\n\t\t\t\t\t &typecode, \n PyArray_BufferConverter,\n &buffer,\n &PyArray_IntpConverter, \n &strides,\n &swapped, &fortran)) \n\t\treturn NULL;\n\t\n if (typecode.type_num ==PyArray_NOTYPE) {\n\t\ttypecode.type_num = PyArray_DOUBLE;\n\t\ttypecode.itemsize = sizeof(double);\n\t}\n\ttype_num = typecode.type_num;\n\titemsize = typecode.itemsize;\n\n\n if (dims.ptr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"need to give a \"\\\n \"valid shape as the first argument\");\n goto fail;\n }\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)PyArray_New(subtype, (int)dims.len, \n dims.ptr, type_num,\n NULL, NULL, itemsize, \n fortran, NULL);\n \n if (ret == NULL) goto fail;\n if (type_num == PyArray_OBJECT) { /* place Py_None */\n PyArray_FillObjectArray(ret, Py_None);\n }\n }\n else { /* buffer given -- use it */\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = buffer.len / itemsize;\n }\n else if (buffer.len < itemsize* \\\n PyArray_MultiplyList(dims.ptr, dims.len)) {\n PyErr_SetString(PyExc_TypeError, \n \"buffer is too small for \" \\\n \"requested array\");\n goto fail;\n }\n if (strides.ptr != NULL) {\n\t\t\tif (strides.len != dims.len) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides, if given, must be \"\\\n\t\t\t\t\t\t\"the same length as shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CheckStrides(itemsize, strides.len, \n\t\t\t\t\t\t buffer.len,\n\t\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides is incompatible \"\\\n\t\t\t\t\t\t\"with shape of requested\"\\\n\t\t\t\t\t\t\"array and size of buffer\");\n\t\t\t\tgoto fail;\n\t\t\t}\n }\n if (type_num == PyArray_OBJECT) {\n PyErr_SetString(PyExc_TypeError, \"cannot construct \"\\\n \"an object array from buffer data\");\n goto fail;\n }\n /* get writeable and aligned */\n if (fortran) buffer.flags |= FORTRAN;\n if (!(swapped)) buffer.flags |= NOTSWAPPED;\n ret = (PyArrayObject *)PyArray_New(subtype, dims.len, \n dims.ptr, type_num,\n strides.ptr,\n (char *)buffer.ptr, \n itemsize, \n buffer.flags, NULL); \n if (ret == 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 PyArray_Return(ret);\n \n fail:\n if (dims.ptr) PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return NULL;\n}\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 static PyObject *module=NULL;\n\n if (module==NULL) {\n module = PyImport_ImportModule(\"scipy.base._internal\");\n if (module == NULL) return NULL;\n }\n return PyObject_CallMethod(module, \"flagsobj\", \"Oii\", \n self, self->flags, 0);\n}\n\n/*\nstatic int\narray_flags_set(PyArrayObject *self, PyObject *obj) \n{\n\tint flagback = self->flags;\n\n if (PyDict_Check(obj)) {\n PyObject *new;\n\t\tnew = PyDict_GetItemString(obj, \"ALIGNED\");\n\t\tif (new) {\n\t\t\tif (PyObject_Not(new)) self->flags &= ~ALIGNED;\n\t\t\telse if (_IsAligned(self)) self->flags |= ALIGNED;\n\t\t\telse {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"cannot set aligned flag of \" \\\n\t\t\t\t\t\t\"mis-aligned array to True\");\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t}\n new = PyDict_GetItemString(obj, \"UPDATEIFCOPY\");\n if (new) {\n if (PyObject_Not(new)) {\n self->flags &= ~UPDATEIFCOPY;\n Py_DECREF(self->base);\n self->base = NULL;\n }\n else {\n\t\t\t\tself->flags = flagback;\n PyErr_SetString(PyExc_ValueError, \n \"cannot set UPDATEIFCOPY \" \\\n \"flag to True\");\n return -1;\n }\n }\n new = PyDict_GetItemString(obj, \"WRITEABLE\");\n if (new) {\n\t\t\tif (PyObject_IsTrue(new)) {\n\t\t\t\tif (_IsWriteable(self)) {\n\t\t\t\t\tself->flags |= WRITEABLE;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tself->flags = flagback;\n\t\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\t\"cannot set \"\t\\\n\t\t\t\t\t\t\t\"WRITEABLE \"\t\\\n\t\t\t\t\t\t\t\"flag to True of \"\\\n\t\t\t\t\t\t\t\"this array \");\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n else\n self->flags &= ~WRITEABLE;\n }\n new = PyDict_GetItemString(obj, \"NOTSWAPPED\");\n if (new) {\n if (PyObject_IsTrue(new))\n self->flags |= NOTSWAPPED;\n else {\n self->flags &= ~NOTSWAPPED;\n\t\t\t}\n\t\t}\n return 0;\n }\n PyErr_SetString(PyExc_ValueError, \n \"object must be a dictionary\");\n return -1;\n}\n*/\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\tif (!PyTuple_Check(val)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"shape must be a tuple\");\n\t\treturn -1;\n\t}\n\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\n\t\n\tif (self->nd > 0) { /* Free old dimensions and strides */\n\t\tPyDimMem_FREE(self->dimensions);\n\t}\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;\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\treturn -1;\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->itemsize;\n\t\n\tif (!PyArray_CheckStrides(self->itemsize, self->nd, numbytes, \n\t\t\t\t self->dimensions, newstrides.ptr)) {\n\t\tPyErr_SetString(PyExc_ValueError, \"strides is not \"\\\n\t\t\t\t\"compatible with available memory\");\n\t\treturn -1;\n\t}\n\tmemcpy(self->strides, newstrides.ptr, sizeof(intp)*newstrides.len);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\treturn 0;\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->itemsize);\n}\n\nstatic PyObject *\narray_size_get(PyArrayObject *self)\n{\n\tlonglong size=PyArray_SIZE(self);\n\tif (size > MAX_INT || size < MIN_INT)\n\t\treturn PyLong_FromLongLong((longlong) size);\n\telse \n\t\treturn PyInt_FromLong((long) size);\n}\n\n\nstatic PyObject *\narray_typechar_get(PyArrayObject *self)\n{\n\tif PyArray_ISFLEXIBLE(self) \n\t\treturn PyString_FromFormat(\"%c%d\", (self->descr->type),\n\t\t\t\t\t self->itemsize);\n\telse \n\t\treturn PyString_FromStringAndSize(&(self->descr->type), 1);\n}\n\nstatic PyObject *\narray_typestr_get(PyArrayObject *self)\n{\n\tstatic char endians[] = \"<>\";\n\tchar endian;\n\tint which;\n\tunsigned long val = 1;\n\tchar *s;\n\tchar basic_=self->descr->kind;\n\n\ts = (char *)&val; /* s[0] == 0 implies big-endian */\n\twhich = (PyArray_ISNOTSWAPPED(self) ? 0 : 1);\n\tif (s[0] == 0) which = 1 - which;\n\tendian = endians[which]; \n\t\n\tif ((basic_==PyArray_VOIDLTR) || (basic_==PyArray_STRINGLTR) || \\\n\t (basic_==PyArray_OBJECTLTR) || (self->itemsize == 1))\n\t\treturn PyString_FromFormat(\"|%c%d\", basic_, self->itemsize);\n\telse\n\t\treturn PyString_FromFormat(\"%c%c%d\", endian, basic_,\n\t\t\t\t\t self->itemsize);\n}\n\nstatic PyObject *\narray_descr_get(PyArrayObject *self)\n{\n\tPyObject *res;\n\tPyObject *dobj;\n\n\t/* hand this off to the typeobject */\n\t/* or give default */\n\tif (PyArray_ISUSERDEF(self)) {\n\t\tres = PyObject_GetAttrString((PyObject *)self->descr->typeobj, \n\t\t\t\t\t \"__array_descr__\");\n\t\tif (res) return res;\n\t\tPyErr_Clear();\n\t}\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\n\nstatic PyObject *\narray_type_get(PyArrayObject *self)\n{\n\treturn PyArray_TypeObjectFromType(self->descr->type_num);\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*/\n\nstatic int\narray_type_set(PyArrayObject *self, PyObject *arg)\n{\n PyArray_Typecode newtype = {PyArray_NOTYPE, 0, 0};\n intp newdim;\n int index;\n char *msg = \"new type not compatible with array.\";\n\n if ((PyArray_TypecodeConverter(arg, &newtype) < 0) ||\n newtype.type_num == PyArray_NOTYPE) {\n PyErr_SetString(PyExc_TypeError, \"invalid type for array\");\n return -1;\n }\n if (!(PyArray_ISONESEGMENT(self) ||\t\t\\\n\t (newtype.itemsize != self->itemsize))) {\n PyErr_SetString(PyExc_ValueError, msg);\n return -1; \n }\n\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\n if (newtype.itemsize < self->itemsize) {\n /* if it is compatible increase the size of the dimension\n at end (or at the front for FORTRAN)\n */\n if (self->itemsize % newtype.itemsize != 0) {\n PyErr_SetString(PyExc_ValueError, msg);\n return -1;\n }\n newdim = self->itemsize / newtype.itemsize;\n\t\tself->dimensions[index] *= newdim;\n self->strides[index] = newtype.itemsize;\n\t}\n \n else if (newtype.itemsize > self->itemsize) {\n \n /* Determine if last (or first if FORTRAN) dimension\n is compatible */\n\n\t\tnewdim = self->dimensions[index] * self->itemsize;\n if ((newdim % newtype.itemsize) != 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, msg);\n return -1;\n }\n\t\t\n self->dimensions[index] = newdim / newtype.itemsize;\n self->strides[index] = newtype.itemsize;\n\t\t\n }\n\t\n \n /* fall through -- adjust type*/\n\n self->descr = PyArray_DescrFromType(newtype.type_num);\n self->itemsize = newtype.itemsize;\n PyArray_UpdateFlags(self, ALIGNED);\n return 0;\n\n}\n\n\n\nstatic PyObject *\narray_base_get(PyArrayObject *self)\n{\n\tif (self->base == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\telse {\n\t\tPy_INCREF(self->base);\n\t\treturn self->base;\n\t}\n}\n\n\nstatic PyObject *\narray_real_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *)ret;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n}\n\n\nstatic int\narray_real_set(PyArrayObject *self, PyObject *val)\n{\n\tPyArrayObject *ret;\n\tPyArrayObject *new;\n\tint rint;\n\n\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0);\n\tif (new == NULL) return -1;\n\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) 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\treturn rint;\n}\n\nstatic PyObject *\narray_imag_get(PyArrayObject *self)\n{\t\n\tPyArrayObject *ret;\n\tint itemsize;\n\tint typenum;\n PyArray_Typecode type;\n\t\n\ttype.type_num = self->descr->type_num;\n\ttype.itemsize = self->itemsize;\n\ttype.fortran = PyArray_ISFORTRAN(self);\n\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\titemsize = self->itemsize >> 1;\n\t\ttypenum = self->descr->type_num - PyArray_NUM_FLOATTYPE;\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 typenum,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data + itemsize,\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\tret = (PyArrayObject *)PyArray_Zeros(self->nd, \n\t\t\t\t\t\t self->dimensions, &type);\n\t\tret->flags &= ~WRITEABLE;\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic int\narray_imag_set(PyArrayObject *self, PyObject *val)\n{\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyArrayObject *ret;\n\t\tPyArrayObject *new;\n\t\tint rint;\n\n\t\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0); \n\t\tif (new == NULL) return -1;\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides+ \\\n\t\t\t\t\t\t (self->itemsize >> 1) ,\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) {\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_Typecode typecode;\n int swap;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode.type_num = self->descr->type_num;\n\ttypecode.itemsize = self->itemsize;\n\ttypecode.fortran = PyArray_ISFORTRAN(self);\n\t\n\tarr = PyArray_FromAny(val, &typecode, \n\t\t\t 0, 0, FORCECAST);\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->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 copyswap(selfit->dataptr, NULL, swap, \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->itemsize);\n copyswap(selfit->dataptr, NULL, swap, self->itemsize);\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\t{\"base\",\n\t (getter)array_base_get,\n\t NULL,\n\t \"base object\"},\n {\"dtype\", \n\t (getter)array_type_get, \n\t (setter)array_type_set,\n\t \"get array type class\"},\n\t{\"dtypechar\",\n\t (getter)array_typechar_get,\n\t NULL,\n\t \"get array type character code\"},\n\t{\"dtypestr\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"get array type string\"},\n {\"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_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\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\n\nstatic char Arraytype__doc__[] = \n \"A array object represents a multidimensional, homogeneous array\\n\"\n\t\" of basic values. Arrays are sequence, mapping and numeric\\n\"\n\t\" objects. More information is available in the scipy module and\\n\"\n\t\" by looking at the methods and attributes of an array.\";\n\nstatic PyTypeObject PyBigArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"scipy.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 \n offsetof(PyArrayObject, weakreflist), /*tp_weaklistoffset */\n\n /* Iterator support (use standard) */\n\n (getiterfunc)0, \t\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 0,\t /* tp_alloc */ \n (newfunc)array_new,\t\t /* tp_new */\n 0,\t \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 \"scipy.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) \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 if (PySequence_Length(s) == 0) \n\t\treturn 1;\n\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);\n\t\tif(d >= 0) d++;\n\t}\n Py_DECREF(e);\n return d;\n}\n\nstatic int\ndiscover_itemsize(PyObject *s, int nd, int *itemsize) \n{\n\tint n, r, i;\n\tPyObject *e;\n\t\n\tn = PyObject_Length(s);\n\n\tif ((nd == 0) || PyString_Check(s) ||\t\t\\\n\t PyUnicode_Check(s) || PyBuffer_Check(s)) {\n\t\tif PyUnicode_Check(s) \n\t\t\t*itemsize = MAX(*itemsize, sizeof(Py_UNICODE)*n);\n\t\telse\n\t\t\t*itemsize = MAX(*itemsize, n);\n\t\treturn 0;\n\t}\n\tfor (i=0; i n_lower) n_lower = d[1];\n }\n d[1] = n_lower;\n\t\n return 0;\n}\n\nstatic void\n_array_small_type(int chktype, int mintype, int chksize, int minsize, \n\t\t PyArray_Typecode *outtype)\n{\n\touttype->type_num = MAX(chktype, mintype);\n\tif (PyTypeNum_ISFLEXIBLE(outtype->type_num) &&\t\\\n\t PyTypeNum_ISFLEXIBLE(mintype)) {\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 == PyArray_STRING) {\n\t\t\touttype->itemsize = MAX(chksize, 2*minsize);\n\t\t}\n\t\telse {\n\t\t\touttype->itemsize = MAX(chksize, minsize);\n\t\t}\n\t}\n\telse {\n\t\touttype->itemsize = chksize;\n\t}\n\treturn;\t\n}\n\nstatic void\n_array_find_type(PyObject *op, PyArray_Typecode *minitype, \n\t\t PyArray_Typecode *outtype, int max)\n{\n int l;\n PyObject *ip;\n\tint chktype=0;\n\tint chksize=0;\n\tint mintype, minsize;\n\n\tif (minitype == NULL) {\n\t\tmintype = PyArray_BOOL;\n\t\tminsize = sizeof(Bool);\n\t}\n\telse {\n\t\tmintype = minitype->type_num;\n\t\tminsize = minitype->itemsize;\n\t}\n\n \n if (max < 0 || mintype == -1) goto deflt;\n\t\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_TYPE(op);\n\t\tchksize = PyArray_ITEMSIZE(op);\n\t\tgoto finish;\n\t}\n\t\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tPyArray_TypecodeFromScalar(op, outtype);\n\t\tchktype = outtype->type_num;\n\t\tchksize = outtype->itemsize;\n\t\tgoto finish;\n\t}\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_TYPE(ip);\n\t\t\tchksize = PyArray_ITEMSIZE(ip);\n\t\t\tgoto finish;\n\t\t}\n } \n\t\n\tif (PyObject_HasAttrString(op, \"__array_typestr__\")) {\n\t\tint swap=0, res;\n\t\tip = PyObject_GetAttrString(op, \"__array_typestr__\");\n\t\tif (ip && PyString_Check(ip)) {\n\t\t\tres = _array_typecode_fromstr(PyString_AS_STRING(ip), \n\t\t\t\t\t\t &swap, outtype); \n\t\t\tif (res >= 0) {\n\t\t\t\tPy_DECREF(ip);\n\t\t\t\tchktype = outtype->type_num;\n\t\t\t\tchksize = outtype->itemsize;\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t}\n\t\tPy_XDECREF(ip);\n\t}\n\n if (PyString_Check(op)) {\n\t\tchktype = PyArray_STRING;\n\t\tchksize = PyString_GET_SIZE(op);\n\t\tgoto finish;\n }\n\n\tif (PyUnicode_Check(op)) {\n\t\tchktype = PyArray_UNICODE;\n\t\tchksize = PyUnicode_GET_DATA_SIZE(op);\n\t\tgoto finish;\n\t}\n\n\tif (PyBuffer_Check(op)) {\n\t\tchktype = PyArray_VOID;\n\t\tchksize = op->ob_type->tp_as_sequence->sq_length(op);\n\t\tPyErr_Clear();\n\t\tgoto finish;\n\t}\n\n\tif (PyInstance_Check(op)) goto deflt;\n\t\n if (PySequence_Check(op)) {\n\t\tPyArray_Typecode newtype;\n\t\tnewtype.type_num = mintype;\n\t\tnewtype.itemsize = minsize;\n\t\tnewtype.fortran = 0;\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 && mintype == 0) {\n\t\t\tnewtype.type_num = PyArray_INTP;\n\t\t\tnewtype.itemsize = sizeof(intp);\n\t\t}\n while (--l >= 0) {\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\t_array_find_type(ip, &newtype, outtype, max-1);\n\t\t\t_array_small_type(outtype->type_num,\n\t\t\t\t\t newtype.type_num, \n\t\t\t\t\t outtype->itemsize,\n\t\t\t\t\t newtype.itemsize,\n\t\t\t\t\t &newtype);\n Py_DECREF(ip);\n }\n\t\tchktype = newtype.type_num;\n\t\tchksize = newtype.itemsize;\n\t\tgoto finish;\n }\n\t\n\tif (PyBool_Check(op)) {\n\t\tchktype = PyArray_BOOL;\n\t\tchksize = sizeof(Bool);\n\t\tgoto finish;\t\t\n\t}\n else if (PyInt_Check(op)) {\n\t\tchktype = PyArray_LONG;\n\t\tchksize = sizeof(long);\n\t\tgoto finish;\n } else if (PyFloat_Check(op)) {\n\t\tchktype = PyArray_DOUBLE;\n\t\tchksize = sizeof(double);\n\t\tgoto finish;\n\t} else if (PyComplex_Check(op)) {\n\t\tchktype = PyArray_CDOUBLE;\n\t\tchksize = sizeof(cdouble);\n\t\tgoto finish;\n\t}\n\n deflt:\n\tchktype = PyArray_OBJECT;\n\tchksize = sizeof(void *);\n\n finish:\n\t_array_small_type(chktype, mintype, chksize, minsize, \n\t\t\t outtype);\n\treturn;\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\" */ \nstatic PyObject *\nArray_FromScalar(PyObject *op, PyArray_Typecode *typecode) \n{\n PyArrayObject *ret;\n\tint itemsize = 0;\n\tint type = typecode->type_num;\n\n\tif PyTypeNum_ISFLEXIBLE(type) {\n\t\titemsize = PyObject_Length(op);\n\t}\n\n\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, 0, NULL, type,\n\t\t\t\t\t NULL, NULL, itemsize, 0, NULL);\n\n\tif (ret == NULL) return NULL;\n\n ret->descr->setitem(op, ret->data, ret);\n\t\n if (PyErr_Occurred()) {\n array_dealloc(ret);\n return NULL;\n } else {\n return (PyObject *)ret;\n }\n}\n\n\nstatic PyObject *\nArray_FromSequence(PyObject *s, PyArray_Typecode *typecode, int min_depth, \n\t\t int max_depth)\n{\n PyArrayObject *r;\n int nd;\n\tintp *d;\n\tint stop_at_string;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->itemsize;\n\t\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 if (!((nd=discover_depth(s, MAX_DIMS+1, stop_at_string)) > 0)) {\n\t\tif (nd==0)\n\t\t\treturn Array_FromScalar(s, typecode);\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid input sequence\");\n return NULL;\n }\n\t\n if ((max_depth && nd > max_depth) ||\t\\\n\t (min_depth && nd < min_depth)) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid number of dimensions\");\n return NULL;\n }\n\t\n\tif ((d=PyDimMem_NEW(nd)) == NULL) {\n\t\treturn PyErr_NoMemory();\n }\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) {\n\t\tPyDimMem_FREE(d);\n\t\treturn NULL;\n\t}\n\tif (itemsize == 0 && PyTypeNum_ISFLEXIBLE(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) {\n\t\t\tPyDimMem_FREE(d);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n r=(PyArrayObject*)PyArray_New(&PyArray_Type, nd, d, \n\t\t\t\t type, NULL, NULL,\n\t\t\t\t itemsize, \n\t\t\t\t typecode->fortran, NULL);\n\n PyDimMem_FREE(d);\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\n\nstatic int \nPyArray_ValidType(int type) \n{\n\tPyArray_Descr *descr;\n\t\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr==NULL) return 0;\n\treturn 1;\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->itemsize;\n\tint nels = PyArray_BUFSIZE;\n\tint el;\n\tint inswap, outswap=0;\n\tint obuf=!PyArray_ISCARRAY(out);\n\tint oelsize = out->itemsize;\n\tPyArray_VectorUnaryFunc *castfunc;\n PyArray_CopySwapFunc *in_csn;\n PyArray_CopySwapFunc *out_csn;\n\tint retval = -1;\n\n\tcastfunc = in->descr->cast[out->descr->type_num];\n in_csn = in->descr->copyswap;\n out_csn = out->descr->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\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\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->itemsize * 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\n/* For backward compatibility */\n\nstatic PyObject *\nPyArray_Cast(PyArrayObject *mp, int type_num) \n{\n\tPyArray_Typecode type;\n\tPyArray_Descr *descr;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\ttype.itemsize = descr->elsize;\n\ttype.type_num = descr->type_num;\n\ttype.fortran = 0;\n\t\n\treturn PyArray_CastToType(mp, &type);\n}\n\nstatic PyObject * \nPyArray_CastToType(PyArrayObject *mp, PyArray_Typecode *at) \n{\n\tPyObject *out;\n\tint ret;\n\n\tif ((mp->descr->type_num == at->type_num) && \\\n\t (at->itemsize==0 || mp->itemsize == at->itemsize) &&\n\t PyArray_ISBEHAVED_RO(mp)) {\n\t\tPy_INCREF(mp);\n\t\treturn (PyObject *)mp;\n\t}\n\t\t\n\tif (at->itemsize == 0) {\n\t\tif (mp->descr->type_num == PyArray_STRING &&\t\\\n\t\t at->type_num == PyArray_UNICODE)\n\t\t\tat->itemsize = mp->itemsize*sizeof(Py_UNICODE);\n\t\tif (mp->descr->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING) \n\t\t\tat->itemsize = mp->itemsize/sizeof(Py_UNICODE);\n\t\tif (at->type_num == PyArray_VOID)\n\t\t\tat->itemsize = mp->itemsize;\n\t}\n\n\tout = PyArray_New(mp->ob_type, mp->nd, \n\t\t\t mp->dimensions, \n\t\t\t at->type_num,\n\t\t\t NULL, NULL, at->itemsize, \n\t\t\t at->fortran, (PyObject *)mp);\n\tif (out == NULL) return NULL;\n\tret = PyArray_CastTo((PyArrayObject *)out, mp);\n\tif (ret != -1) return out;\n\n\tPy_DECREF(out);\n\treturn NULL;\n\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\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\tsimple = ((PyArray_ISCARRAY(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY(mp) && PyArray_ISFARRAY(out)));\n\t\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->itemsize * outsize;\n\t\tintp ncopies = outsize / mpsize;\n\n\t\twhile(ncopies--) {\n\t\t\tinptr = mp->data;\n\t\t\tmp->descr->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\nstatic PyObject *\narray_fromarray(PyArrayObject *arr, PyArray_Typecode *typecode, int flags) \n{\n\t\n\tPyArrayObject *ret=NULL;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->itemsize;\n\tint copy = 0;\n\tint arrflags;\n\tPyArray_Typecode oldtype;\n\tchar *msg = \"cannot copy back to a read-only array\";\n PyTypeObject *subtype;\n\n\toldtype.type_num = PyArray_TYPE(arr);\n\toldtype.itemsize = PyArray_ITEMSIZE(arr);\n\toldtype.fortran = 0;\n\n subtype = arr->ob_type;\n\n\tif (type == PyArray_NOTYPE) type = arr->descr->type_num;\n\tif (itemsize == 0) itemsize = arr->itemsize;\n\ttypecode->type_num = type;\n\ttypecode->itemsize = itemsize;\n\n\t/* Don't copy if sizes are compatible */\n\tif (PyArray_EquivalentTypes(&oldtype, typecode)) {\n\t\tarrflags = arr->flags;\n\n\t\tcopy = (flags & ENSURECOPY) || \\\n\t\t\t((flags & CONTIGUOUS) && (!(arrflags & CONTIGUOUS))) \\\n\t\t\t|| (PyArray_ITEMSIZE(arr) != itemsize) || \\\n\t\t\t((flags & ALIGNED) && (!(arrflags & ALIGNED))) || \\\n\t\t\t((flags & NOTSWAPPED) && (!(arrflags & NOTSWAPPED))) \\\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 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_New(subtype, \n\t\t\t\t\t arr->nd, \n\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t type,\n\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t itemsize,\n\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t (PyObject *)arr);\n\t\t\tif (PyArray_CopyInto(ret, arr) == -1) 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 ret = (PyArrayObject *) \\\n PyArray_New(&PyArray_Type,\n arr->nd,\n arr->dimensions,\n arr->descr->type_num,\n arr->strides,\n arr->data,\n arr->itemsize,\n arr->flags,NULL);\n if (ret == NULL) return NULL;\n ret->base = (PyObject *)arr;\n ret->flags &= ~UPDATEIFCOPY;\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_CanCastSafely(PyArray_TYPE(arr), type)) {\n if ((flags & UPDATEIFCOPY) && \\\n (!PyArray_ISWRITEABLE(arr))) {\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_New(subtype, arr->nd,\n arr->dimensions, typecode->type_num,\n NULL, NULL, typecode->itemsize,\n typecode->fortran, \n (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\nstatic int\n_array_typecode_fromstr(char *str, int *swap, PyArray_Typecode *type)\n{\n int type_num;\n char typechar;\n int size;\n unsigned long number = 1;\n char *s;\n char msg[] = \"unsupported typestring\";\n \n s = (char *)&number; /* s[0] == 0 implies big-endian */\n\n *swap = 0;\n\n if (str[0] == '<' || str[0] == '>') {\n\tif ((str[0] == '<') && (s[0] == 0)) *swap = 1;\n\telse if ((str[0] == '>') && (s[0] != 0)) *swap = 1;\n }\n str += 1;\n \n#define _MY_FAIL {\t\t\t\t \\\n\t PyErr_SetString(PyExc_ValueError, msg); \\\n\t return -1;\t\t\t \\\n }\t\t\n\n typechar = str[0];\n size = atoi(str + 1);\n switch (typechar) {\n case 'b':\n\t if (size == sizeof(Bool))\n\t\t type_num = PyArray_BOOL;\t \n\t else _MY_FAIL \n\t break;\t\t \n case 'u':\n if (size == sizeof(uintp))\n type_num = PyArray_UINTP;\n\t else if (size == sizeof(char))\n\t\t type_num = PyArray_UBYTE;\n\t else if (size == sizeof(short)) \n\t\t type_num = PyArray_USHORT;\n\t else if (size == sizeof(int)) \n\t\t type_num = PyArray_UINT;\n\t else if (size == sizeof(ulong)) \n\t\t type_num = PyArray_ULONG;\n\t else if (size == sizeof(ulonglong))\n\t\t type_num = PyArray_ULONGLONG;\n\t else _MY_FAIL\n\t break;\t\t \n case 'i':\n if (size == sizeof(intp))\n type_num = PyArray_INTP;\n\t else if (size == sizeof(char)) \n\t\t type_num = PyArray_BYTE;\n\t else if (size == sizeof(short)) \n\t\t type_num = PyArray_SHORT;\n\t else if (size == sizeof(int))\n\t\t type_num = PyArray_INT;\n\t else if (size == sizeof(long)) \n\t\t type_num = PyArray_LONG;\n\t else if (size == sizeof(longlong))\n\t\t type_num = PyArray_LONGLONG;\n\t else _MY_FAIL\n\t break;\t\t \n case 'f':\n\t if (size == sizeof(float))\n\t\t type_num = PyArray_FLOAT;\n\t else if (size == sizeof(double))\n\t\t type_num = PyArray_DOUBLE;\n\t else if (size == sizeof(longdouble))\n\t\t type_num = PyArray_LONGDOUBLE;\n\t else _MY_FAIL\n\t break;\n case 'c':\n\t if (size == sizeof(float)*2)\n\t\t type_num = PyArray_CFLOAT;\n\t else if (size == sizeof(double)*2)\n\t\t type_num = PyArray_CDOUBLE;\n\t else if (size == sizeof(longdouble)*2)\n\t\t type_num = PyArray_CLONGDOUBLE;\n\t else _MY_FAIL\n\t break;\n case 'O':\n\t if (size == sizeof(PyObject *))\n\t\t type_num = PyArray_OBJECT;\n\t else _MY_FAIL\n\t break;\n case 'S':\n\t type_num = PyArray_STRING;\n\t break;\n case 'U':\n\t type_num = PyArray_UNICODE;\n\t size *= sizeof(Py_UNICODE);\n\t break;\t \n case 'V':\n\t type_num = PyArray_VOID;\n\t break;\n default:\n\t _MY_FAIL\n }\n\n#undef _MY_FAIL\n\n type->type_num = type_num;\n type->itemsize = size;\n type->fortran = 0;\n return 0;\n}\n\nstatic PyObject *\narray_frominterface(PyObject *input, PyArray_Typecode *intype, int flags)\n{\n\tPyObject *attr=NULL, *item=NULL, *r;\n\tPyArrayObject *ret=NULL;\n\tPyArray_Typecode type;\n\tchar *data;\n\tint buffer_len;\n\tint res, i, n;\n\tintp dims[MAX_DIMS], strides[MAX_DIMS];\n\tint swap;\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\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) {Py_XDECREF(attr); return NULL;}\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t}\n\telse {\n\t\tif (PyTuple_GET_SIZE(attr) != 2) {\n\t\t\tPy_DECREF(attr);\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\treturn NULL;\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\tPy_DECREF(attr);\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\treturn NULL;\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 = PyObject_GetAttrString(input, \"__array_typestr__\");\n\tif (!PyString_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_typestr__ must be a string\");\n\t\tPy_DECREF(attr);\n\t\treturn NULL;\t\n\t}\n\tres = _array_typecode_fromstr(PyString_AS_STRING(attr), &swap, &type);\n\tPy_DECREF(attr);\n\tif (res < 0) return NULL;\n \n\tattr = PyObject_GetAttrString(input, \"__array_shape__\");\n\tif (!PyTuple_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_shape__ must be a tuple\");\n\t\tPy_DECREF(attr);\n\t\treturn NULL;\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\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\treturn NULL;\n\t\t}\n\t\tfor (i=0; istrides, strides, n*sizeof(intp));\n\t}\n\n\tif (swap) {\n\t\tPyObject *tmp;\n tmp = PyArray_Byteswap(ret, TRUE);\n\t\tPy_DECREF(tmp);\n\t}\n\n\tPyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n\tr = array_fromarray(ret, intype, flags);\n\tPy_DECREF(ret);\n\treturn r;\n}\n\nstatic PyObject *\narray_fromattr(PyObject *op, PyArray_Typecode *typecode, int flags) \n{\n PyObject *new, *r;\n\t \n if (typecode->type_num == PyArray_NOTYPE) {\n new = PyObject_CallMethod(op, \"__array__\", NULL);\n } else {\n\t\tPyArray_Descr *descr;\n\t\tPyObject *obj;\n\n\t\tdescr = PyArray_DescrFromType(typecode->type_num);\n\t\tif (PyTypeNum_ISFLEXIBLE(typecode->type_num)) {\n\t\t\tobj = PyString_FromFormat(\"%c%d\", descr->type,\n\t\t\t\t\t\t typecode->itemsize);\n\t\t}\n\t\telse { \n\t\t\tobj = (PyObject *)(descr->typeobj); Py_INCREF(obj);\n\t\t}\n\t\tnew = PyObject_CallMethod(op, \"__array__\", \"N\", obj);\n }\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 r = array_fromarray((PyArrayObject *)new, typecode, flags);\n Py_DECREF(new);\n return r;\n} \n\n\nstatic PyObject *\narray_fromobject(PyObject *op, PyArray_Typecode *typecode, int min_depth, \n\t\t int max_depth, int flags) \n{\n /* This is the main code to make a NumPy array from a Python\n Object. It is called from lot's of different places which\n is why there are so many checks. The comments try to\n explain some of the checks. */\n\n\tint type = typecode->type_num;\n PyObject *r=NULL;\n\n\t/* Is input object already an array? */\n\t/* This is where the flags are used */\n if (PyArray_Check(op)) \n\t\tr = array_fromarray((PyArrayObject *)op, typecode, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, typecode);\n\t}\n\telse if (PyObject_HasAttrString(op, \"__array__\")) {\n\t\t/* Code that returns the object to convert for a non\n\t\t multiarray input object from the __array__ attribute of the\n\t\t object. */\n r = array_fromattr(op, typecode, flags);\n\t}\n\telse if (PyObject_HasAttrString(op, \"__array_shape__\") &&\n\t\t PyObject_HasAttrString(op, \"__array_typestr__\")) {\n\t\tr = array_frominterface(op, typecode, flags);\n\t}\n\telse {\n\t\tif (type == PyArray_NOTYPE) {\n\t\t\t_array_find_type(op, NULL, typecode, MAX_DIMS);\n\t\t}\n\t\tif (PySequence_Check(op))\n\t\t\tr = Array_FromSequence(op, typecode, \n\t\t\t\t\t min_depth, max_depth);\n\t\telse\n\t\t\tr = Array_FromScalar(op, typecode);\n\t}\n\n /* If we didn't succed return NULL */\n if (r == NULL) return NULL;\n\t\n\t/* Be sure we succeed here */\n\t\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"internal error: array_fromobject \"\\\n\t\t\t\t\"not producing an array\");\n\t\tPy_DECREF(r);\n return NULL;\n }\n\n if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {\n Py_DECREF(r);\n PyErr_SetString(PyExc_ValueError, \n \"object of too small depth for desired array\");\n return NULL;\n }\n if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {\n Py_DECREF(r);\n PyErr_SetString(PyExc_ValueError, \n \"object too deep for desired array\");\n return NULL;\n }\n return r;\n}\n\nstatic void\nPyArray_ArrayType(PyObject *op, PyArray_Typecode *intype, \n\t\t PyArray_Typecode *outtype) \n{\n\t_array_find_type(op, intype, outtype, MAX_DIMS);\n\treturn;\n}\n\nstatic int \nPyArray_ObjectType(PyObject *op, int minimum_type) \n{\n\tPyArray_Typecode intype, outtype;\n\tintype.type_num = minimum_type;\n\t_array_find_type(op, &intype, &outtype, MAX_DIMS);\n\treturn outtype.type_num;\n}\n\n\n\n/* flags is any of \n CONTIGUOUS, \n FORTRAN, (or set typecode->fortran=1)\n ALIGNED, \n NOTSWAPPED, \n WRITEABLE, \n ENSURECOPY, \n UPDATEIFCOPY,\n FORCECAST,\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, NOTSWAPPED, and WRITEABLE\n and therefore it is redundant to include those as well. \n\n BEHAVED_FLAGS == ALIGNED | NOTSWAPPED | WRITEABLE\n BEHAVED_FLAGS_RO == ALIGNED | NOTSWAPPED\n CARRAY_FLAGS = CONTIGUOUS | BEHAVED_FLAGS\n FARRAY_FLAGS = FORTRAN | BEHAVED_FLAGS\n \n By default, the returned array will be a copy of the object, \n (C) contiguous in memory, aligned, notswapped, and writeable.\n \n So CONTIGUOUS | ENSURECOPY passed in means that the returned\n array does not have to be CONTIGUOUS or a COPY but should be\n ALIGNED, NOTSWAPPED and WRITEABLE. \n\n typecode->fortran can be set to request a\n fortran-contiguous array. Fortran arrays are always behaved (aligned, \n notswapped, and writeable) and not (C) CONTIGUOUS. Note that either\n FORTRAN in the flag or typecode->fortran = 1 is enough to request\n a FORTRAN-style array. \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\nstatic PyObject *\nPyArray_FromAny(PyObject *op, PyArray_Typecode *typecode, int min_depth, \n\t\tint max_depth, int requires) \n{\n \tPyArray_Typecode mine = {PyArray_NOTYPE, 0, 0};\n\tPyArray_Typecode *type;\n\t\n\tif (typecode == NULL) type = &mine;\n\telse type = typecode;\n\t\t\n\tif (requires & ENSURECOPY) {\n\t\trequires |= DEFAULT_FLAGS;\n\t}\n\t/* Ensure that type->fortran and flags & FORTRAN are the\n\t same */\n\tif (requires & FORTRAN) typecode->fortran = 1;\n\tif (type->fortran == 1) {\n\t\trequires |= FARRAY_FLAGS;\n\t\tif (min_depth > 2) requires &= ~CONTIGUOUS;\n\t}\n\n\t/* make sure itemsize is not 0 unless warranted. */\n\tif ((type->itemsize == 0) && (type->type_num != PyArray_NOTYPE)) {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(type->type_num);\n\t\tif (descr != NULL) type->itemsize = descr->elsize;\n\t\telse return NULL;\n\t}\n\t\n\treturn array_fromobject(op, type, min_depth, max_depth, \n\t\t\t\trequires);\t\n}\n\n/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0, 0) */\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\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);\n Py_DECREF(op);\n return new;\n}\n\n/* These are all compressed into a single API */\n/* Deprecated calls -- Use PyArray_FromAny */\n\nstatic PyObject *\nPyArray_FromObject(PyObject *op, int type, int min_depth, int max_depth) \n{\n\tPyArray_Typecode typecode = {0, 0, 0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth,\n\t\t\t max_depth, BEHAVED_FLAGS | ENSUREARRAY);\n}\n\nstatic PyObject *\nPyArray_ContiguousFromObject(PyObject *op, int type, int min_depth, \n\t\t\t int max_depth) \n{\n\tPyArray_Typecode typecode = {0, 0, 0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth,\n\t\t\t max_depth, DEFAULT_FLAGS | ENSUREARRAY);\n}\n\nstatic PyObject *\nPyArray_CopyFromObject(PyObject *op, int type, int min_depth, \n\t\t int max_depth) \n{\n\tPyArray_Typecode typecode = {0, 0, 0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth, max_depth,\n\t\t\t ENSURECOPY | ENSUREARRAY);\n}\n\n/* End of deprecated */\n\nstatic PyObject *\nPyArray_ContiguousFromAny(PyObject *op, int type, int min_depth, \n\t\t\t int max_depth)\n{\n\tPyArray_Typecode typecode = {0,0,0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth,\n\t\t\t max_depth, DEFAULT_FLAGS);\n}\t\n\nstatic int \nPyArray_CanCastSafely(int fromtype, int totype) \n{\n\tPyArray_Descr *from, *to;\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\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 (to->elsize > from->elsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (to->elsize >= from->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (from->elsize < 8)\n return (to->elsize > from->elsize);\n else\n return (to->elsize >= from->elsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (from->elsize < 8)\n return ((to->elsize >> 1) > from->elsize);\n else\n return ((to->elsize >> 1) >= from->elsize);\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 (to->elsize > from->elsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (to->elsize >= from->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (from->elsize < 8)\n return (to->elsize > from->elsize);\n else\n return (to->elsize >= from->elsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (from->elsize < 8)\n return ((to->elsize >> 1) > from->elsize);\n else\n return ((to->elsize >> 1) >= from->elsize);\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 ((to->elsize >> 1) >= from->elsize);\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\nstatic Bool\nPyArray_CanCastTo(PyArray_Typecode *from, PyArray_Typecode *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->itemsize <= to->itemsize);\n\t\t\t}\n\t\t\telse if (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->itemsize * sizeof(Py_UNICODE)\\\n\t\t\t\t <= to->itemsize);\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->itemsize <= to->itemsize);\n\t\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 scipy's arraymap ****/\n/* and Python's array iterator ***/\n \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 = PyObject_GC_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 PyObject_GC_Track(it);\n return (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 PyObject_GC_UnTrack(it);\n Py_XDECREF(it->ao);\n PyObject_GC_Del(it);\n }\n\nstatic int\narrayiter_traverse(PyArrayIterObject *it, visitproc visit, void *arg)\n{\n if (it->ao != NULL)\n return visit((PyObject *)(it->ao), arg);\n return 0;\n}\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->itemsize;\n\tr = PyArray_New(self->ao->ob_type, 1, &count, \n\t\t\tself->ao->descr->type_num, NULL, NULL,\n\t\t\titemsize, 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->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->itemsize;\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\tr = PyArray_New(self->ao->ob_type, ind->nd, ind->dimensions,\n\t\t\tself->ao->descr->type_num, NULL, \n\t\t\tNULL, self->ao->itemsize, \n\t\t\t0, (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)->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\tint i;\n\tPyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tint 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\t\t\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\n\t/* Tuples 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\tr = PyArray_New(self->ao->ob_type, 1, &ii, \n\t\t\t\t\tself->ao->descr->type_num, NULL, \n\t\t\t\t\tNULL, self->ao->itemsize, 0,\n\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 */\n\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->itemsize;\n\t\tr = PyArray_New(self->ao->ob_type, 1, &n_steps, \n\t\t\t\tself->ao->descr->type_num, NULL, NULL,\n\t\t\t\tsize, 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)->copyswap;\n\t\twhile(n_steps--) {\n copyswap(dptr, self->dataptr, swap, size);\n\t\t\tfor(i=0; i< step_size; i++) \n\t\t\t\tPyArray_ITER_NEXT(self);\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\tif (PyArray_IsScalar(ind, Integer) || PyList_Check(ind)) {\n\t\tobj = PyArray_FromAny(ind, &indtype, 0, 0, FORCECAST);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tr = iter_subscript_Bool(self, (PyArrayObject *)obj);\n\t\t} \n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, &indtype, 0, 0, \n\t\t\t\t\t FORCECAST | BEHAVED_FLAGS);\n\t\t\tif (new==NULL) goto fail;\n\t\t\tobj = new;\n\t\t\tr = iter_subscript_int(self, (PyArrayObject *)obj);\n\t\t}\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\t\"unsupported iterator index\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPy_DECREF(obj);\n\t\treturn r;\n\t}\n\n\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\n fail:\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->itemsize;\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->copyswap;\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(self->dataptr, val->dataptr, swap,\n itemsize);\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t\tPyArray_ITER_NEXT(val);\n\t\tif (val->index==val->size) \n\t\t\tPyArray_ITER_RESET(val);\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_Typecode typecode;\n\tintp num;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\titemsize = typecode.itemsize = self->ao->itemsize;\n\ttypecode.type_num = self->ao->descr->type_num;\n copyswap = self->ao->descr->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\n\nstatic int\niter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val) \n{\n\tint i;\n\tPyObject *arrval=NULL;\n\tPyArrayIterObject *val_it=NULL;\n\tPyArray_Typecode type;\n\tPyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tint swap;\n\tint itemsize;\n\tint start, step_size;\n\tintp n_steps;\n\tPyObject *obj;\n PyArray_CopySwapFunc *copyswap;\n\t\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\ti = iter_ass_subscript(self, ind, val);\n\t\tPy_DECREF(ind);\n\t\treturn i;\n\t}\n\t\n\ttype.type_num = self->ao->descr->type_num;\n\titemsize = type.itemsize = self->ao->itemsize;\n\t\n\tarrval = PyArray_FromAny(val, &type, 0, 0, 0);\n\tif (arrval==NULL) return -1;\n\tval_it = (PyArrayIterObject *)PyArray_IterNew(arrval);\n\tif (val_it==NULL) goto fail;\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\n copyswap = PyArray_DESCR(arrval)->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\tgoto succeed;\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 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 copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, itemsize);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\tgoto succeed;\n\t\t}\n\t\twhile(n_steps--) {\n copyswap(self->dataptr, val_it->dataptr,\n swap, itemsize);\n\t\t\tfor(i=0; i < step_size; i++) \n\t\t\t\tPyArray_ITER_NEXT(self);\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\tgoto succeed;\n\t} \n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tif (PyArray_IsScalar(ind, Integer))\n\t\tobj = PyArray_FromScalar(ind, &indtype);\n\telse if (PyList_Check(ind)) {\n\t\tobj = PyArray_FromAny(ind, &indtype, 0, 0, FORCECAST);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tif (iter_ass_sub_Bool(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto fail;\n\t\t} \n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, &indtype, 0, 0, \n\t\t\t\t\t FORCECAST | BEHAVED_FLAGS);\n\t\t\tif (new==NULL) goto fail;\n\t\t\tPy_DECREF(obj);\n\t\t\tobj = new;\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 fail;\n\t\t}\n\t\telse goto fail;\n\t\tPy_DECREF(obj);\n\t\tgoto succeed;\n\t}\n\n\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\tgoto fail;\n\n succeed:\n\tPy_DECREF(val_it);\n\tPy_DECREF(arrval);\n\treturn 0;\n\n fail:\n\tPy_XDECREF(val_it);\n\tPy_XDECREF(arrval);\n\treturn -1;\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 if (PyArray_ISCONTIGUOUS(it->ao)) {\n r = PyArray_New(it->ao->ob_type, 1, &size, \n\t\t\t\tit->ao->descr->type_num,\n NULL, it->ao->data, it->ao->itemsize, \n\t\t\t\tit->ao->flags,\n (PyObject *)it->ao); \n\t\tif (r==NULL) return NULL;\n }\n else {\n r = PyArray_New(it->ao->ob_type, 1, &size, \n\t\t\t\tit->ao->descr->type_num,\n NULL, NULL, it->ao->itemsize, 0, \n (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\n\nstatic PyTypeObject PyArrayIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"scipy.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 | Py_TPFLAGS_HAVE_GC,/* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)arrayiter_traverse,\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)arrayiter_next,\t\t/* tp_iternext */\n iter_methods,\t\t\t\t/* tp_methods */\n};\n\n/** END of Array Iterator **/\n\n\n\n/*********************** Subscript Array Iterator *************************\n * *\n * This object handles subscript behavior for array objects. *\n * It is an iterator object with a next method *\n * It abstracts the n-dimensional mapping behavior to make the looping *\n * code more understandable (maybe) *\n * and so that indexing can be set up ahead of time *\n */ \n\n/* This checks the args for any fancy indexing objects */\n\n#define SOBJ_NOTFANCY 0 \n#define SOBJ_ISFANCY 1\n#define SOBJ_BADARRAY 2\n#define SOBJ_TOOMANY 3\n#define SOBJ_LISTTUP 4\n\nstatic int\nfancy_indexing_check(PyObject *args)\n{\n\tint i, n;\n\tPyObject *obj;\n\tint retval = SOBJ_NOTFANCY;\n\n\tif (PyTuple_Check(args)) {\n\t\tn = PyTuple_GET_SIZE(args);\n\t\tif (n >= MAX_DIMS) return SOBJ_TOOMANY;\n\t\tfor (i=0; i=MAX_DIMS) return SOBJ_ISFANCY;\n\t\tfor (i=0; i SOBJ_ISFANCY) return retval;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* convert an indexing object to an INTP indexing array iterator\n if possible -- otherwise, it is a Slice or Ellipsis object\n and has to be interpreted on bind to a particular \n array so leave it NULL for now.\n */\nstatic int\n_convert_obj(PyObject *obj, PyArrayIterObject **iter)\n{\n\tPyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tPyObject *arr;\n\n\tif (PySlice_Check(obj) || (obj == Py_Ellipsis))\n\t\t*iter = NULL;\n\telse {\n\t\tarr = PyArray_FromAny(obj, &indtype, 0, 0, FORCECAST);\n\t\tif (arr == NULL) return -1;\n\t\t*iter = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (*iter == NULL) return -1;\n\t}\n\treturn 0;\n}\n\n/* Adjust dimensionality and strides for index object iterators \n --- i.e. broadcast\n */\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->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->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=NULL, *obj=NULL;\n\tint i, j, n, curraxis, ellipexp, noellip;\n\tPyArrayIterObject *it;\n\tintp dimsize;\n\tintp *indptr;\n\n\t/* Remove old binding if any */\n\tPy_XDECREF(mit->ait);\n\tmit->ait = NULL;\n\n\tPy_XDECREF(mit->subspace);\n\tmit->subspace = NULL;\n\t\n\tsubnd = arr->nd - mit->numiter;\n\tif (subnd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"too many indices for array\");\n\t\treturn;\n\t}\n\n\tmit->ait = (PyArrayIterObject *)PyArray_IterNew((PyObject *)arr);\n\tif (mit->ait == NULL) return;\n\n\t/* If this is just a view, then do nothing more */\n\t/* views are handled by just adjusting the strides\n\t and dimensions of the object.\n\t*/\n\t \n\tif (mit->view) return;\n\n\t/* no subspace iteration needed. 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\tif (mit->subspace == NULL) goto fail;\n\tPy_DECREF(sub);\n\n\t/* Expand dimensions of result */\n\tn = mit->subspace->ao->nd;\n\tfor (i=0; idimensions[mit->nd+i] = mit->subspace->ao->dimensions[i];\n\tmit->nd += n;\n\n\t/* Now, we still need to interpret the ellipsis and slice objects \n\t to determine which axes the indexing arrays are referring to\n\t*/\n\tn = PyTuple_GET_SIZE(mit->indexobj);\n\n\t/* The number of dimensions an ellipsis takes up */\n\tellipexp = arr->nd - n + 1;\n\t/* Now fill in iteraxes -- remember indexing arrays have been \n converted to 0's in mit->indexobj */\n\tcurraxis = 0;\n\tj = 0;\n\tnoellip = 1; /* Only expand the first ellipsis */\n\tmemset(mit->bscoord, 0, sizeof(intp)*arr->nd);\n\tfor (i=0; iindexobj, i);\n\t\tif (PyInt_Check(obj) || PyLong_Check(obj)) \n\t\t\tmit->iteraxes[j++] = curraxis++;\n\t\telse if (noellip && obj == Py_Ellipsis) {\n\t\t\tcurraxis += ellipexp;\n\t\t\tnoellip = 0;\n\t\t}\n\t\telse {\n\t\t\tint start=0;\n\t\t\tint 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}\t\t\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn;\n\n fail:\n\tPy_XDECREF(sub);\n\tPy_XDECREF(mit->ait);\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_Typecode typecode = {PyArray_BOOL, 0, 0};\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\tba = (PyArrayObject *)PyArray_FromAny(myBool, &typecode, 0, 0, \n\t\t\t\t\t CARRAY_FLAGS);\n\tif (ba == NULL) return -1;\n\tnd = ba->nd;\n\tfor (j=0; jdata;\n\tcount = 0;\n\n\t/* pre-determine how many nonzero entries there are */\n\tfor (i=0; iao->data;\n\t\tcoords[j] = 0;\n\t\tdims_m1[j] = ba->dimensions[j]-1;\n\t}\n\n\tptr = (Bool *)ba->data;\n\n\tif (count == 0) return nd;\n\n\t/* Loop through the Boolean array and copy coordinates\n\t for non-zero entries */\n\tfor (i=0; i=0; j--) {\n\t\t\tif (coords[j] < dims_m1[j]) {\n\t\t\t\tcoords[j]++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcoords[j] = 0;\n\t\t\t}\n\t\t}\n\t}\n\treturn nd;\n\n fail:\n\tfor (j=0; jiters[i] = NULL;\n \tmit->view = 0;\n \tmit->index = 0;\n \tmit->ait = NULL;\n \tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tfancy = fancy_indexing_check(indexobj);\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\tif (fancy == SOBJ_NOTFANCY) { /* bail out */\n\t\tmit->view = 1;\n\t\tgoto ret;\n\t}\n\n\tif (fancy == SOBJ_BADARRAY) {\n\t\tPyErr_SetString(PyExc_TypeError,\t\t\t\\\n\t\t\t\t\"arrays used as indexes must be of \" \\\n\t\t\t\t\"integer type\");\n\t\tgoto fail;\n\t}\n\tif (fancy == SOBJ_TOOMANY) {\n\t\tPyErr_SetString(PyExc_TypeError, \"too many indicies\");\n\t\tgoto fail;\n\t}\n\n\tif (fancy == SOBJ_LISTTUP) {\n\t\tPyObject *newobj;\n\t\tnewobj = PySequence_Tuple(indexobj);\n\t\tif (newobj == NULL) goto fail;\n\t\tPy_DECREF(indexobj);\n\t\tindexobj = newobj;\n\t\tmit->indexobj = indexobj;\n\t}\n\n#undef SOBJ_NOTFANCY \n#undef SOBJ_ISFANCY \n#undef SOBJ_BADARRAY \n#undef SOBJ_TOOMANY \n#undef SOBJ_LISTTUP \n\n\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\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 (PyList_Check(indexobj) || PyArray_Check(indexobj)) {\n\t\tmit->numiter = 1;\n\t\tarr = PyArray_FromAny(indexobj, &indtype, 0, 0, FORCECAST);\n\t\tif (arr == NULL) goto fail;\n\t\tmit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (mit->iters[0] == NULL) 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(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\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = new;\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\t/* Store the number of iterators actually converted */\n\t\t/* These will be mapped to actual axes at bind time */\n\t\tif (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)\n\t\t\tgoto fail;\n\t}\n\n ret:\n PyObject_GC_Track(mit);\n return (PyObject *)mit;\n \n fail:\n\tPy_XDECREF(arr);\n\tPy_XDECREF(mit->indexobj);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n PyObject_GC_Del(mit);\n\treturn NULL;\n}\n\n\n/* return unbound mapiter object */\n\nstatic PyObject *\narraymapiter_new(PyTypeObject *type, PyObject *args, PyObject *kwds) \n{\n\tPyObject *newtup, *res;\n\tint n;\n\n\tif (!PyTuple_Check(args)) {\n\t\tPyErr_BadInternalCall();\n\t\treturn NULL;\n\t}\n\n\tn = PyTuple_GET_SIZE(args);\n\t\n\tif (n < 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"must be initialized with >= 1 argument\");\n\t\treturn NULL;\n\t}\n\t\n\tif (n > 1) {\n\t\tnewtup = PyTuple_GetSlice(args, 0, n);\n\t\tif (newtup == NULL) return NULL;\n\t\tres = PyArray_MapIterNew(newtup);\n\t\tPy_DECREF(newtup);\n\t}\n\telse { /* n == 1 */\n\t\tnewtup = PyTuple_GET_ITEM(args, 0);\n\t\tres = PyArray_MapIterNew(newtup);\n\t}\n\n\treturn res; \t\n}\n\n\n/* Returns a 0-dim array holding the element desired */\n/*\nstatic PyObject *\narraymapiter_next(PyArrayMapIterObject *mit)\n{\n\tPyObject *ret;\n\tif (mit->ait == NULL) return NULL;\n\tif (mit->view) return NULL;\n\tif (mit->index < mit->size) {\n\t\tret = PyArray_ToScalar(mit->dataptr, mit->ait->ao);\n\t\tPyArray_MapIterNext(mit);\n\t\treturn ret;\n\t}\n return NULL;\n}\n*/\n\nstatic void\narraymapiter_dealloc(PyArrayMapIterObject *mit)\n{\n\tint i;\n PyObject_GC_UnTrack(mit);\n Py_XDECREF(mit->ait);\n\tPy_XDECREF(mit->indexobj);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n PyObject_GC_Del(mit);\n}\n\nstatic int\narraymapiter_traverse(PyArrayMapIterObject *mit, visitproc visit, void *arg)\n{\n\tint ret, i;\n if (mit->ait != NULL)\n if ((ret = visit((PyObject *)(mit->ait), arg)) != 0) \n\t\t\treturn ret;\t\n\n\tif (mit->iters != NULL) \n\t\tfor (i=0; inumiter; i++) \n\t\t\tif (mit->iters[i] != NULL) \n\t\t\t\tif ((ret=visit((PyObject *)mit->iters[i], \n\t\t\t\t\t arg)) != 0)\n\t\t\t\t\treturn ret;\n\n\tif (mit->indexobj != NULL)\n\t\tif ((ret = visit(mit->indexobj, arg)) != 0) return ret;\n\t\n return 0;\n}\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 MapIterNew must be \n that does not work. 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 char doc_mapiter_bind[] = \"obj.bind(a)\\n Bind an array to the \"\\\n\t\"mapiter object\";\n\nstatic PyObject *\nmapiter_bind(PyArrayMapIterObject *mit, PyObject *args)\n{\n\tPyArrayObject *arr;\n\n if (!PyArg_ParseTuple(args, \"O!\", &PyArray_Type, &arr)) return NULL;\n\n \tPyArray_MapIterBind(mit, arr);\n\n\tif (mit->ait == NULL) return NULL;\n\t\n \tPyArray_MapIterReset(mit);\n\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyMethodDef mapiter_methods[] = {\n\t{\"bind\", (PyCFunction)mapiter_bind, 1, doc_mapiter_bind},\n {NULL,\t\tNULL}\t\t\n};\n*/\n\n\nstatic PyTypeObject PyArrayMapIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"scipy.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 | Py_TPFLAGS_HAVE_GC,/* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)arraymapiter_traverse,\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, /*arraymapiter_next,*/\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 (newfunc)arraymapiter_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n\n};\n\n/** END of Subscript Iterator **/\n\n\n\n", "methods": [ { "name": "PyArray_PyIntAsIntp", "long_name": "PyArray_PyIntAsIntp( PyObject * o)", "filename": "arrayobject.c", "nloc": 59, "complexity": 19, "token_count": 385, "parameters": [ "o" ], "start_line": 40, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 64, "top_nesting_level": 0 }, { "name": "PyArray_PyIntAsInt", "long_name": "PyArray_PyIntAsInt( PyObject * o)", "filename": "arrayobject.c", "nloc": 57, "complexity": 19, "token_count": 389, "parameters": [ "o" ], "start_line": 109, "end_line": 169, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 61, "top_nesting_level": 0 }, { "name": "PyArray_GetPriority", "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", "filename": "arrayobject.c", "nloc": 17, "complexity": 5, "token_count": 86, "parameters": [ "obj", "default_" ], "start_line": 173, "end_line": 191, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "PyArray_Zero", "long_name": "PyArray_Zero( PyArrayObject * arr)", "filename": "arrayobject.c", "nloc": 34, "complexity": 6, "token_count": 190, "parameters": [ "arr" ], "start_line": 208, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "PyArray_One", "long_name": "PyArray_One( PyArrayObject * arr)", "filename": "arrayobject.c", "nloc": 40, "complexity": 7, "token_count": 222, "parameters": [ "arr" ], "start_line": 246, "end_line": 289, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "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": 295, "end_line": 345, "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": 368, "end_line": 399, "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": 213, "parameters": [ "src" ], "start_line": 402, "end_line": 436, "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": 449, "end_line": 471, "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": 474, "end_line": 495, "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": 499, "end_line": 537, "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": 542, "end_line": 562, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "index2ptr", "long_name": "index2ptr( PyArrayObject * mp , int i)", "filename": "arrayobject.c", "nloc": 10, "complexity": 7, "token_count": 86, "parameters": [ "mp", "i" ], "start_line": 570, "end_line": 580, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "PyArray_Size", "long_name": "PyArray_Size( PyObject * op)", "filename": "arrayobject.c", "nloc": 9, "complexity": 2, "token_count": 33, "parameters": [ "op" ], "start_line": 583, "end_line": 591, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "PyArray_CopyInto", "long_name": "PyArray_CopyInto( PyArrayObject * dest , PyArrayObject * src)", "filename": "arrayobject.c", "nloc": 71, "complexity": 16, "token_count": 427, "parameters": [ "dest", "src" ], "start_line": 604, "end_line": 684, "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": 16, "complexity": 2, "token_count": 98, "parameters": [ "dest", "src_object" ], "start_line": 688, "end_line": 707, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "PyArray_FromDimsAndDataAndDescr", "long_name": "PyArray_FromDimsAndDataAndDescr( int nd , int * d , PyArray_Descr * descr , char * data)", "filename": "arrayobject.c", "nloc": 15, "complexity": 3, "token_count": 121, "parameters": [ "nd", "d", "descr", "data" ], "start_line": 715, "end_line": 734, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "PyArray_FromDimsAndData", "long_name": "PyArray_FromDimsAndData( int nd , int * d , int type , char * data)", "filename": "arrayobject.c", "nloc": 14, "complexity": 3, "token_count": 112, "parameters": [ "nd", "d", "type", "data" ], "start_line": 738, "end_line": 755, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "PyArray_FromDims", "long_name": "PyArray_FromDims( int nd , int * d , int type)", "filename": "arrayobject.c", "nloc": 14, "complexity": 5, "token_count": 133, "parameters": [ "nd", "d", "type" ], "start_line": 759, "end_line": 776, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "PyArray_Copy", "long_name": "PyArray_Copy( PyArrayObject * m1)", "filename": "arrayobject.c", "nloc": 11, "complexity": 2, "token_count": 77, "parameters": [ "m1" ], "start_line": 782, "end_line": 794, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "PyArray_Scalar", "long_name": "PyArray_Scalar( char * data , int type_num , int itemsize , int swap)", "filename": "arrayobject.c", "nloc": 48, "complexity": 8, "token_count": 289, "parameters": [ "data", "type_num", "itemsize", "swap" ], "start_line": 800, "end_line": 849, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "top_nesting_level": 0 }, { "name": "PyArray_ToScalar", "long_name": "PyArray_ToScalar( char * data , PyArrayObject * arr)", "filename": "arrayobject.c", "nloc": 7, "complexity": 1, "token_count": 51, "parameters": [ "data", "arr" ], "start_line": 856, "end_line": 863, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_Return", "long_name": "PyArray_Return( PyArrayObject * mp)", "filename": "arrayobject.c", "nloc": 17, "complexity": 5, "token_count": 85, "parameters": [ "mp" ], "start_line": 869, "end_line": 888, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "PyArray_RegisterDataType", "long_name": "PyArray_RegisterDataType( PyTypeObject * type)", "filename": "arrayobject.c", "nloc": 31, "complexity": 6, "token_count": 177, "parameters": [ "type" ], "start_line": 899, "end_line": 931, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "PyArray_RegisterDescrForType", "long_name": "PyArray_RegisterDescrForType( int typenum , PyArray_Descr * descr)", "filename": "arrayobject.c", "nloc": 32, "complexity": 3, "token_count": 167, "parameters": [ "typenum", "descr" ], "start_line": 941, "end_line": 984, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "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": 16, "token_count": 577, "parameters": [ "self", "fp", "sep", "format" ], "start_line": 988, "end_line": 1079, "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": 24, "complexity": 5, "token_count": 151, "parameters": [ "self" ], "start_line": 1082, "end_line": 1110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "PyArray_ToString", "long_name": "PyArray_ToString( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 34, "complexity": 6, "token_count": 191, "parameters": [ "self" ], "start_line": 1113, "end_line": 1148, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "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": 1157, "end_line": 1194, "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": 1201, "end_line": 1209, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "array_item", "long_name": "array_item( PyArrayObject * self , int i)", "filename": "arrayobject.c", "nloc": 22, "complexity": 4, "token_count": 150, "parameters": [ "self", "i" ], "start_line": 1213, "end_line": 1237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "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": 26, "parameters": [ "self", "i" ], "start_line": 1240, "end_line": 1243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "array_ass_item", "long_name": "array_ass_item( PyArrayObject * self , int i , PyObject * v)", "filename": "arrayobject.c", "nloc": 27, "complexity": 8, "token_count": 177, "parameters": [ "self", "i", "v" ], "start_line": 1247, "end_line": 1277, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "slice_coerce_index", "long_name": "slice_coerce_index( PyObject * o , int * v)", "filename": "arrayobject.c", "nloc": 9, "complexity": 2, "token_count": 40, "parameters": [ "o", "v" ], "start_line": 1281, "end_line": 1289, "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 , int length , int * start , int * stop , int * step , intp * slicelength)", "filename": "arrayobject.c", "nloc": 45, "complexity": 24, "token_count": 376, "parameters": [ "r", "length", "start", "stop", "step", "slicelength" ], "start_line": 1295, "end_line": 1345, "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 , int * step_size , intp * n_steps , int max)", "filename": "arrayobject.c", "nloc": 45, "complexity": 11, "token_count": 223, "parameters": [ "op", "step_size", "n_steps", "max" ], "start_line": 1352, "end_line": 1397, "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": 89, "complexity": 20, "token_count": 540, "parameters": [ "self", "op", "dimensions", "strides", "offset_ptr" ], "start_line": 1401, "end_line": 1496, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 96, "top_nesting_level": 0 }, { "name": "_swap_axes", "long_name": "_swap_axes( PyArrayMapIterObject * mit , PyArrayObject ** ret)", "filename": "arrayobject.c", "nloc": 24, "complexity": 4, "token_count": 187, "parameters": [ "mit", "ret" ], "start_line": 1499, "end_line": 1533, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "PyArray_GetMap", "long_name": "PyArray_GetMap( PyArrayMapIterObject * mit)", "filename": "arrayobject.c", "nloc": 36, "complexity": 8, "token_count": 252, "parameters": [ "mit" ], "start_line": 1538, "end_line": 1587, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "top_nesting_level": 0 }, { "name": "PyArray_SetMap", "long_name": "PyArray_SetMap( PyArrayMapIterObject * mit , PyObject * op)", "filename": "arrayobject.c", "nloc": 50, "complexity": 12, "token_count": 392, "parameters": [ "mit", "op" ], "start_line": 1590, "end_line": 1649, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 60, "top_nesting_level": 0 }, { "name": "array_subscript", "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", "filename": "arrayobject.c", "nloc": 61, "complexity": 19, "token_count": 425, "parameters": [ "self", "op" ], "start_line": 1670, "end_line": 1745, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 76, "top_nesting_level": 0 }, { "name": "array_ass_sub", "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", "filename": "arrayobject.c", "nloc": 43, "complexity": 9, "token_count": 251, "parameters": [ "self", "index", "op" ], "start_line": 1758, "end_line": 1810, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "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": 1818, "end_line": 1821, "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": 1840, "end_line": 1852, "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": 1855, "end_line": 1870, "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": 1874, "end_line": 1883, "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": 1886, "end_line": 1897, "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": 1965, "end_line": 1998, "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": 2005, "end_line": 2044, "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": 23, "complexity": 5, "token_count": 136, "parameters": [ "m1", "op", "axis", "rtype" ], "start_line": 2047, "end_line": 2069, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "PyArray_GenericAccumulateFunction", "long_name": "PyArray_GenericAccumulateFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", "filename": "arrayobject.c", "nloc": 23, "complexity": 5, "token_count": 136, "parameters": [ "m1", "op", "axis", "rtype" ], "start_line": 2073, "end_line": 2095, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "PyArray_GenericBinaryFunction", "long_name": "PyArray_GenericBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", "filename": "arrayobject.c", "nloc": 12, "complexity": 2, "token_count": 69, "parameters": [ "m1", "m2", "op" ], "start_line": 2099, "end_line": 2110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_GenericUnaryFunction", "long_name": "PyArray_GenericUnaryFunction( PyArrayObject * m1 , PyObject * op)", "filename": "arrayobject.c", "nloc": 12, "complexity": 2, "token_count": 63, "parameters": [ "m1", "op" ], "start_line": 2113, "end_line": 2124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_GenericInplaceBinaryFunction", "long_name": "PyArray_GenericInplaceBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", "filename": "arrayobject.c", "nloc": 13, "complexity": 2, "token_count": 71, "parameters": [ "m1", "m2", "op" ], "start_line": 2127, "end_line": 2139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 2142, "end_line": 2145, "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": 2148, "end_line": 2151, "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": 2154, "end_line": 2157, "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": 2160, "end_line": 2163, "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": 2166, "end_line": 2169, "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": 2172, "end_line": 2175, "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": 2178, "end_line": 2181, "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": 2184, "end_line": 2187, "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": 2190, "end_line": 2193, "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": 2196, "end_line": 2199, "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": 2202, "end_line": 2205, "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": 2208, "end_line": 2211, "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": 2214, "end_line": 2217, "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": 2220, "end_line": 2223, "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": 2226, "end_line": 2229, "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": 2232, "end_line": 2235, "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": 2238, "end_line": 2241, "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": 2244, "end_line": 2247, "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": 2250, "end_line": 2253, "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": 2256, "end_line": 2259, "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": 2262, "end_line": 2265, "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": 2268, "end_line": 2271, "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": 2274, "end_line": 2277, "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": 2280, "end_line": 2283, "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": 2286, "end_line": 2289, "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": 2292, "end_line": 2295, "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": 2298, "end_line": 2301, "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": 2304, "end_line": 2308, "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": 2311, "end_line": 2315, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "array_all_nonzero", "long_name": "array_all_nonzero( PyArrayObject * mp)", "filename": "arrayobject.c", "nloc": 18, "complexity": 4, "token_count": 93, "parameters": [ "mp" ], "start_line": 2319, "end_line": 2337, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "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": 2340, "end_line": 2355, "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": 143, "parameters": [ "v" ], "start_line": 2359, "end_line": 2385, "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": 143, "parameters": [ "v" ], "start_line": 2388, "end_line": 2413, "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": 124, "parameters": [ "v" ], "start_line": 2416, "end_line": 2438, "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": 124, "parameters": [ "v" ], "start_line": 2441, "end_line": 2463, "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": 124, "parameters": [ "v" ], "start_line": 2466, "end_line": 2488, "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": 2491, "end_line": 2495, "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": 34, "complexity": 11, "token_count": 258, "parameters": [ "self", "ilow", "ihigh" ], "start_line": 2556, "end_line": 2594, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "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": 2598, "end_line": 2619, "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": 4, "complexity": 1, "token_count": 26, "parameters": [ "self", "el" ], "start_line": 2622, "end_line": 2627, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "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": 308, "parameters": [ "string", "n", "max_n", "data", "nd", "dimensions", "strides", "self" ], "start_line": 2648, "end_line": 2695, "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": 222, "parameters": [ "self" ], "start_line": 2698, "end_line": 2734, "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": 2740, "end_line": 2757, "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": 2760, "end_line": 2772, "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": 2775, "end_line": 2787, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "array_richcompare", "long_name": "array_richcompare( PyArrayObject * self , PyObject * other , int cmp_op)", "filename": "arrayobject.c", "nloc": 61, "complexity": 13, "token_count": 273, "parameters": [ "self", "other", "cmp_op" ], "start_line": 2791, "end_line": 2868, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 78, "top_nesting_level": 0 }, { "name": "_check_axis", "long_name": "_check_axis( PyArrayObject * arr , int * axis , int flags)", "filename": "arrayobject.c", "nloc": 29, "complexity": 8, "token_count": 164, "parameters": [ "arr", "axis", "flags" ], "start_line": 2871, "end_line": 2900, "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": 17, "complexity": 4, "token_count": 91, "parameters": [ "len", "vals" ], "start_line": 2906, "end_line": 2922, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "PyArray_IntpFromSequence", "long_name": "PyArray_IntpFromSequence( PyObject * seq , intp * vals , int maxvals)", "filename": "arrayobject.c", "nloc": 21, "complexity": 7, "token_count": 161, "parameters": [ "seq", "vals", "maxvals" ], "start_line": 2927, "end_line": 2950, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "_IsContiguous", "long_name": "_IsContiguous( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 14, "complexity": 6, "token_count": 109, "parameters": [ "ap" ], "start_line": 2956, "end_line": 2972, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_IsFortranContiguous", "long_name": "_IsFortranContiguous( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 14, "complexity": 6, "token_count": 107, "parameters": [ "ap" ], "start_line": 2976, "end_line": 2992, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_IsAligned", "long_name": "_IsAligned( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 14, "complexity": 4, "token_count": 110, "parameters": [ "ap" ], "start_line": 2995, "end_line": 3011, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_IsWriteable", "long_name": "_IsWriteable( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 16, "complexity": 8, "token_count": 109, "parameters": [ "ap" ], "start_line": 3014, "end_line": 3047, "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": 22, "complexity": 9, "token_count": 129, "parameters": [ "ret", "flagmask" ], "start_line": 3051, "end_line": 3073, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "PyArray_CheckStrides", "long_name": "PyArray_CheckStrides( int elsize , int nd , intp numbytes , intp * dims , intp * newstrides)", "filename": "arrayobject.c", "nloc": 13, "complexity": 4, "token_count": 84, "parameters": [ "elsize", "nd", "numbytes", "dims", "newstrides" ], "start_line": 3080, "end_line": 3095, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "_array_fill_strides", "long_name": "_array_fill_strides( intp * strides , intp * dims , int nd , intp itemsize , int inflag , int * objflags)", "filename": "arrayobject.c", "nloc": 24, "complexity": 9, "token_count": 171, "parameters": [ "strides", "dims", "nd", "itemsize", "inflag", "objflags" ], "start_line": 3115, "end_line": 3139, "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 , char * data , int itemsize , int flags , PyObject * obj)", "filename": "arrayobject.c", "nloc": 117, "complexity": 27, "token_count": 713, "parameters": [ "subtype", "nd", "dims", "type_num", "strides", "data", "itemsize", "flags", "obj" ], "start_line": 3143, "end_line": 3293, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 151, "top_nesting_level": 0 }, { "name": "PyArray_Resize", "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape)", "filename": "arrayobject.c", "nloc": 87, "complexity": 15, "token_count": 501, "parameters": [ "self", "newshape" ], "start_line": 3298, "end_line": 3403, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 106, "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": 3408, "end_line": 3425, "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": 47, "complexity": 7, "token_count": 261, "parameters": [ "arr", "obj" ], "start_line": 3428, "end_line": 3480, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "top_nesting_level": 0 }, { "name": "array_new", "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", "filename": "arrayobject.c", "nloc": 100, "complexity": 20, "token_count": 589, "parameters": [ "subtype", "args", "kwds" ], "start_line": 3483, "end_line": 3598, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 116, "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": 3605, "end_line": 3608, "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": 10, "complexity": 3, "token_count": 57, "parameters": [ "self" ], "start_line": 3611, "end_line": 3621, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "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": 3694, "end_line": 3697, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "array_shape_set", "long_name": "array_shape_set( PyArrayObject * self , PyObject * val)", "filename": "arrayobject.c", "nloc": 33, "complexity": 6, "token_count": 206, "parameters": [ "self", "val" ], "start_line": 3701, "end_line": 3735, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "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": 3739, "end_line": 3742, "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": 32, "complexity": 7, "token_count": 209, "parameters": [ "self", "obj" ], "start_line": 3745, "end_line": 3778, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "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": 3782, "end_line": 3789, "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": 3792, "end_line": 3800, "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": 3804, "end_line": 3810, "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": 3813, "end_line": 3827, "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": 3830, "end_line": 3874, "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": 19, "parameters": [ "self" ], "start_line": 3878, "end_line": 3881, "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": 8, "complexity": 3, "token_count": 45, "parameters": [ "self" ], "start_line": 3884, "end_line": 3891, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "array_typechar_get", "long_name": "array_typechar_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 8, "complexity": 2, "token_count": 47, "parameters": [ "self" ], "start_line": 3895, "end_line": 3902, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "array_typestr_get", "long_name": "array_typestr_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 19, "complexity": 7, "token_count": 141, "parameters": [ "self" ], "start_line": 3905, "end_line": 3925, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "array_descr_get", "long_name": "array_descr_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 19, "complexity": 5, "token_count": 128, "parameters": [ "self" ], "start_line": 3928, "end_line": 3950, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "array_type_get", "long_name": "array_type_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 4, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 3954, "end_line": 3957, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "array_type_set", "long_name": "array_type_set( PyArrayObject * self , PyObject * arg)", "filename": "arrayobject.c", "nloc": 41, "complexity": 10, "token_count": 294, "parameters": [ "self", "arg" ], "start_line": 3969, "end_line": 4027, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 59, "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": 4032, "end_line": 4042, "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": 4046, "end_line": 4071, "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": 31, "complexity": 4, "token_count": 177, "parameters": [ "self", "val" ], "start_line": 4075, "end_line": 4107, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "array_imag_get", "long_name": "array_imag_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 34, "complexity": 3, "token_count": 200, "parameters": [ "self" ], "start_line": 4110, "end_line": 4145, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "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": 203, "parameters": [ "self", "val" ], "start_line": 4148, "end_line": 4185, "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": 4188, "end_line": 4191, "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": 51, "complexity": 9, "token_count": 368, "parameters": [ "self", "val" ], "start_line": 4194, "end_line": 4248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 55, "top_nesting_level": 0 }, { "name": "discover_depth", "long_name": "discover_depth( PyObject * s , int max , int stop_at_string)", "filename": "arrayobject.c", "nloc": 23, "complexity": 14, "token_count": 169, "parameters": [ "s", "max", "stop_at_string" ], "start_line": 4423, "end_line": 4448, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "discover_itemsize", "long_name": "discover_itemsize( PyObject * s , int nd , int * itemsize)", "filename": "arrayobject.c", "nloc": 21, "complexity": 9, "token_count": 161, "parameters": [ "s", "nd", "itemsize" ], "start_line": 4451, "end_line": 4473, "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": 4480, "end_line": 4506, "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( int chktype , int mintype , int chksize , int minsize , PyArray_Typecode * outtype)", "filename": "arrayobject.c", "nloc": 19, "complexity": 5, "token_count": 100, "parameters": [ "chktype", "mintype", "chksize", "minsize", "outtype" ], "start_line": 4509, "end_line": 4529, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "_array_find_type", "long_name": "_array_find_type( PyObject * op , PyArray_Typecode * minitype , PyArray_Typecode * outtype , int max)", "filename": "arrayobject.c", "nloc": 126, "complexity": 28, "token_count": 671, "parameters": [ "op", "minitype", "outtype", "max" ], "start_line": 4532, "end_line": 4673, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 142, "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": 4676, "end_line": 4699, "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_Typecode * typecode)", "filename": "arrayobject.c", "nloc": 21, "complexity": 5, "token_count": 132, "parameters": [ "op", "typecode" ], "start_line": 4703, "end_line": 4729, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 0 }, { "name": "Array_FromSequence", "long_name": "Array_FromSequence( PyObject * s , PyArray_Typecode * typecode , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 51, "complexity": 17, "token_count": 313, "parameters": [ "s", "typecode", "min_depth", "max_depth" ], "start_line": 4733, "end_line": 4790, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 58, "top_nesting_level": 0 }, { "name": "PyArray_ValidType", "long_name": "PyArray_ValidType( int type)", "filename": "arrayobject.c", "nloc": 7, "complexity": 2, "token_count": 30, "parameters": [ "type" ], "start_line": 4794, "end_line": 4801, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "_bufferedcast", "long_name": "_bufferedcast( PyArrayObject * out , PyArrayObject * in)", "filename": "arrayobject.c", "nloc": 75, "complexity": 16, "token_count": 477, "parameters": [ "out", "in" ], "start_line": 4807, "end_line": 4897, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 91, "top_nesting_level": 0 }, { "name": "PyArray_Cast", "long_name": "PyArray_Cast( PyArrayObject * mp , int type_num)", "filename": "arrayobject.c", "nloc": 10, "complexity": 1, "token_count": 56, "parameters": [ "mp", "type_num" ], "start_line": 4903, "end_line": 4914, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_CastToType", "long_name": "PyArray_CastToType( PyArrayObject * mp , PyArray_Typecode * at)", "filename": "arrayobject.c", "nloc": 31, "complexity": 13, "token_count": 233, "parameters": [ "mp", "at" ], "start_line": 4917, "end_line": 4952, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "PyArray_CastTo", "long_name": "PyArray_CastTo( PyArrayObject * out , PyArrayObject * mp)", "filename": "arrayobject.c", "nloc": 40, "complexity": 10, "token_count": 214, "parameters": [ "out", "mp" ], "start_line": 4959, "end_line": 5005, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "array_fromarray", "long_name": "array_fromarray( PyArrayObject * arr , PyArray_Typecode * typecode , int flags)", "filename": "arrayobject.c", "nloc": 116, "complexity": 35, "token_count": 721, "parameters": [ "arr", "typecode", "flags" ], "start_line": 5008, "end_line": 5139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 132, "top_nesting_level": 0 }, { "name": "_array_typecode_fromstr", "long_name": "_array_typecode_fromstr( char * str , int * swap , PyArray_Typecode * type)", "filename": "arrayobject.c", "nloc": 94, "complexity": 36, "token_count": 533, "parameters": [ "str", "swap", "type" ], "start_line": 5143, "end_line": 5248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 106, "top_nesting_level": 0 }, { "name": "array_frominterface", "long_name": "array_frominterface( PyObject * input , PyArray_Typecode * intype , int flags)", "filename": "arrayobject.c", "nloc": 113, "complexity": 26, "token_count": 715, "parameters": [ "input", "intype", "flags" ], "start_line": 5251, "end_line": 5374, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 124, "top_nesting_level": 0 }, { "name": "array_fromattr", "long_name": "array_fromattr( PyObject * op , PyArray_Typecode * typecode , int flags)", "filename": "arrayobject.c", "nloc": 30, "complexity": 5, "token_count": 181, "parameters": [ "op", "typecode", "flags" ], "start_line": 5377, "end_line": 5408, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "array_fromobject", "long_name": "array_fromobject( PyObject * op , PyArray_Typecode * typecode , int min_depth , int max_depth , int flags)", "filename": "arrayobject.c", "nloc": 49, "complexity": 14, "token_count": 291, "parameters": [ "op", "typecode", "min_depth", "max_depth", "flags" ], "start_line": 5412, "end_line": 5477, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 66, "top_nesting_level": 0 }, { "name": "PyArray_ArrayType", "long_name": "PyArray_ArrayType( PyObject * op , PyArray_Typecode * intype , PyArray_Typecode * outtype)", "filename": "arrayobject.c", "nloc": 6, "complexity": 1, "token_count": 29, "parameters": [ "op", "intype", "outtype" ], "start_line": 5480, "end_line": 5485, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "PyArray_ObjectType", "long_name": "PyArray_ObjectType( PyObject * op , int minimum_type)", "filename": "arrayobject.c", "nloc": 7, "complexity": 1, "token_count": 40, "parameters": [ "op", "minimum_type" ], "start_line": 5488, "end_line": 5494, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "PyArray_FromAny", "long_name": "PyArray_FromAny( PyObject * op , PyArray_Typecode * typecode , int min_depth , int max_depth , int requires)", "filename": "arrayobject.c", "nloc": 24, "complexity": 9, "token_count": 165, "parameters": [ "op", "typecode", "min_depth", "max_depth", "requires" ], "start_line": 5548, "end_line": 5578, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "PyArray_EnsureArray", "long_name": "PyArray_EnsureArray( PyObject * op)", "filename": "arrayobject.c", "nloc": 14, "complexity": 5, "token_count": 87, "parameters": [ "op" ], "start_line": 5589, "end_line": 5605, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "PyArray_FromObject", "long_name": "PyArray_FromObject( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 7, "complexity": 1, "token_count": 51, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5611, "end_line": 5617, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "PyArray_ContiguousFromObject", "long_name": "PyArray_ContiguousFromObject( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 8, "complexity": 1, "token_count": 51, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5620, "end_line": 5627, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_CopyFromObject", "long_name": "PyArray_CopyFromObject( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 8, "complexity": 1, "token_count": 51, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5630, "end_line": 5637, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_ContiguousFromAny", "long_name": "PyArray_ContiguousFromAny( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 8, "complexity": 1, "token_count": 49, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5642, "end_line": 5649, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_CanCastSafely", "long_name": "PyArray_CanCastSafely( int fromtype , int totype)", "filename": "arrayobject.c", "nloc": 81, "complexity": 39, "token_count": 476, "parameters": [ "fromtype", "totype" ], "start_line": 5652, "end_line": 5735, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 84, "top_nesting_level": 0 }, { "name": "PyArray_CanCastTo", "long_name": "PyArray_CanCastTo( PyArray_Typecode * from , PyArray_Typecode * to)", "filename": "arrayobject.c", "nloc": 24, "complexity": 7, "token_count": 134, "parameters": [ "from", "to" ], "start_line": 5738, "end_line": 5762, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 }, { "name": "PyArray_IterNew", "long_name": "PyArray_IterNew( PyObject * obj)", "filename": "arrayobject.c", "nloc": 34, "complexity": 6, "token_count": 258, "parameters": [ "obj" ], "start_line": 5772, "end_line": 5809, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "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": 5814, "end_line": 5824, "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": 6, "complexity": 1, "token_count": 25, "parameters": [ "it" ], "start_line": 5827, "end_line": 5832, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "arrayiter_traverse", "long_name": "arrayiter_traverse( PyArrayIterObject * it , visitproc visit , * arg)", "filename": "arrayobject.c", "nloc": 6, "complexity": 2, "token_count": 42, "parameters": [ "it", "visit", "arg" ], "start_line": 5835, "end_line": 5840, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "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": 5844, "end_line": 5847, "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": 42, "complexity": 7, "token_count": 272, "parameters": [ "self", "ind" ], "start_line": 5851, "end_line": 5899, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "iter_subscript_int", "long_name": "iter_subscript_int( PyArrayIterObject * self , PyArrayObject * ind)", "filename": "arrayobject.c", "nloc": 51, "complexity": 8, "token_count": 347, "parameters": [ "self", "ind" ], "start_line": 5902, "end_line": 5955, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 0 }, { "name": "iter_subscript", "long_name": "iter_subscript( PyArrayIterObject * self , PyObject * ind)", "filename": "arrayobject.c", "nloc": 97, "complexity": 20, "token_count": 593, "parameters": [ "self", "ind" ], "start_line": 5959, "end_line": 6078, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 120, "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": 176, "parameters": [ "self", "ind", "val", "swap" ], "start_line": 6082, "end_line": 6114, "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": 289, "parameters": [ "self", "ind", "val", "swap" ], "start_line": 6117, "end_line": 6159, "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": 103, "complexity": 24, "token_count": 636, "parameters": [ "self", "ind", "val" ], "start_line": 6163, "end_line": 6285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 123, "top_nesting_level": 0 }, { "name": "iter_array", "long_name": "iter_array( PyArrayIterObject * it , PyObject * op)", "filename": "arrayobject.c", "nloc": 30, "complexity": 5, "token_count": 221, "parameters": [ "it", "op" ], "start_line": 6298, "end_line": 6340, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "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": 6345, "end_line": 6349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "fancy_indexing_check", "long_name": "fancy_indexing_check( PyObject * args)", "filename": "arrayobject.c", "nloc": 55, "complexity": 22, "token_count": 293, "parameters": [ "args" ], "start_line": 6414, "end_line": 6475, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 62, "top_nesting_level": 0 }, { "name": "_convert_obj", "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", "filename": "arrayobject.c", "nloc": 15, "complexity": 5, "token_count": 105, "parameters": [ "obj", "iter" ], "start_line": 6483, "end_line": 6498, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "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": 6504, "end_line": 6573, "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": 261, "parameters": [ "mit" ], "start_line": 6577, "end_line": 6614, "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": 296, "parameters": [ "mit" ], "start_line": 6620, "end_line": 6664, "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": 102, "complexity": 22, "token_count": 690, "parameters": [ "mit", "arr" ], "start_line": 6682, "end_line": 6818, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 137, "top_nesting_level": 0 }, { "name": "_nonzero_indices", "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", "filename": "arrayobject.c", "nloc": 57, "complexity": 15, "token_count": 454, "parameters": [ "myBool", "iters" ], "start_line": 6824, "end_line": 6893, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 70, "top_nesting_level": 0 }, { "name": "PyArray_MapIterNew", "long_name": "PyArray_MapIterNew( PyObject * indexobj)", "filename": "arrayobject.c", "nloc": 111, "complexity": 24, "token_count": 745, "parameters": [ "indexobj" ], "start_line": 6896, "end_line": 7029, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 134, "top_nesting_level": 0 }, { "name": "arraymapiter_new", "long_name": "arraymapiter_new( PyTypeObject * type , PyObject * args , PyObject * kwds)", "filename": "arrayobject.c", "nloc": 26, "complexity": 5, "token_count": 130, "parameters": [ "type", "args", "kwds" ], "start_line": 7035, "end_line": 7065, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "arraymapiter_dealloc", "long_name": "arraymapiter_dealloc( PyArrayMapIterObject * mit)", "filename": "arrayobject.c", "nloc": 10, "complexity": 2, "token_count": 60, "parameters": [ "mit" ], "start_line": 7086, "end_line": 7095, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "arraymapiter_traverse", "long_name": "arraymapiter_traverse( PyArrayMapIterObject * mit , visitproc visit , * arg)", "filename": "arrayobject.c", "nloc": 16, "complexity": 9, "token_count": 146, "parameters": [ "mit", "visit", "arg" ], "start_line": 7098, "end_line": 7116, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 } ], "methods_before": [ { "name": "PyArray_PyIntAsIntp", "long_name": "PyArray_PyIntAsIntp( PyObject * o)", "filename": "arrayobject.c", "nloc": 59, "complexity": 19, "token_count": 385, "parameters": [ "o" ], "start_line": 40, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 64, "top_nesting_level": 0 }, { "name": "PyArray_PyIntAsInt", "long_name": "PyArray_PyIntAsInt( PyObject * o)", "filename": "arrayobject.c", "nloc": 57, "complexity": 19, "token_count": 389, "parameters": [ "o" ], "start_line": 109, "end_line": 169, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 61, "top_nesting_level": 0 }, { "name": "PyArray_GetPriority", "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", "filename": "arrayobject.c", "nloc": 17, "complexity": 5, "token_count": 86, "parameters": [ "obj", "default_" ], "start_line": 173, "end_line": 191, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "PyArray_Zero", "long_name": "PyArray_Zero( PyArrayObject * arr)", "filename": "arrayobject.c", "nloc": 34, "complexity": 6, "token_count": 190, "parameters": [ "arr" ], "start_line": 208, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "PyArray_One", "long_name": "PyArray_One( PyArrayObject * arr)", "filename": "arrayobject.c", "nloc": 40, "complexity": 7, "token_count": 222, "parameters": [ "arr" ], "start_line": 246, "end_line": 289, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "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": 295, "end_line": 345, "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": 368, "end_line": 399, "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": 213, "parameters": [ "src" ], "start_line": 402, "end_line": 436, "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": 449, "end_line": 471, "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": 474, "end_line": 495, "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": 499, "end_line": 537, "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": 542, "end_line": 562, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "index2ptr", "long_name": "index2ptr( PyArrayObject * mp , int i)", "filename": "arrayobject.c", "nloc": 10, "complexity": 7, "token_count": 86, "parameters": [ "mp", "i" ], "start_line": 570, "end_line": 580, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "PyArray_Size", "long_name": "PyArray_Size( PyObject * op)", "filename": "arrayobject.c", "nloc": 9, "complexity": 2, "token_count": 33, "parameters": [ "op" ], "start_line": 583, "end_line": 591, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "PyArray_CopyInto", "long_name": "PyArray_CopyInto( PyArrayObject * dest , PyArrayObject * src)", "filename": "arrayobject.c", "nloc": 71, "complexity": 16, "token_count": 427, "parameters": [ "dest", "src" ], "start_line": 604, "end_line": 684, "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": 16, "complexity": 2, "token_count": 98, "parameters": [ "dest", "src_object" ], "start_line": 688, "end_line": 707, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "PyArray_FromDimsAndDataAndDescr", "long_name": "PyArray_FromDimsAndDataAndDescr( int nd , int * d , PyArray_Descr * descr , char * data)", "filename": "arrayobject.c", "nloc": 15, "complexity": 3, "token_count": 121, "parameters": [ "nd", "d", "descr", "data" ], "start_line": 715, "end_line": 734, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "PyArray_FromDimsAndData", "long_name": "PyArray_FromDimsAndData( int nd , int * d , int type , char * data)", "filename": "arrayobject.c", "nloc": 14, "complexity": 3, "token_count": 112, "parameters": [ "nd", "d", "type", "data" ], "start_line": 738, "end_line": 755, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "PyArray_FromDims", "long_name": "PyArray_FromDims( int nd , int * d , int type)", "filename": "arrayobject.c", "nloc": 14, "complexity": 5, "token_count": 133, "parameters": [ "nd", "d", "type" ], "start_line": 759, "end_line": 776, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "PyArray_Copy", "long_name": "PyArray_Copy( PyArrayObject * m1)", "filename": "arrayobject.c", "nloc": 11, "complexity": 2, "token_count": 77, "parameters": [ "m1" ], "start_line": 782, "end_line": 794, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "PyArray_Scalar", "long_name": "PyArray_Scalar( char * data , int type_num , int itemsize , int swap)", "filename": "arrayobject.c", "nloc": 48, "complexity": 8, "token_count": 289, "parameters": [ "data", "type_num", "itemsize", "swap" ], "start_line": 800, "end_line": 849, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "top_nesting_level": 0 }, { "name": "PyArray_ToScalar", "long_name": "PyArray_ToScalar( char * data , PyArrayObject * arr)", "filename": "arrayobject.c", "nloc": 7, "complexity": 1, "token_count": 51, "parameters": [ "data", "arr" ], "start_line": 856, "end_line": 863, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_Return", "long_name": "PyArray_Return( PyArrayObject * mp)", "filename": "arrayobject.c", "nloc": 17, "complexity": 5, "token_count": 85, "parameters": [ "mp" ], "start_line": 869, "end_line": 888, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "PyArray_RegisterDataType", "long_name": "PyArray_RegisterDataType( PyTypeObject * type)", "filename": "arrayobject.c", "nloc": 31, "complexity": 6, "token_count": 177, "parameters": [ "type" ], "start_line": 899, "end_line": 931, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "PyArray_RegisterDescrForType", "long_name": "PyArray_RegisterDescrForType( int typenum , PyArray_Descr * descr)", "filename": "arrayobject.c", "nloc": 32, "complexity": 3, "token_count": 167, "parameters": [ "typenum", "descr" ], "start_line": 941, "end_line": 984, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "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": 16, "token_count": 577, "parameters": [ "self", "fp", "sep", "format" ], "start_line": 988, "end_line": 1079, "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": 24, "complexity": 5, "token_count": 151, "parameters": [ "self" ], "start_line": 1082, "end_line": 1110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "PyArray_ToString", "long_name": "PyArray_ToString( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 34, "complexity": 6, "token_count": 191, "parameters": [ "self" ], "start_line": 1113, "end_line": 1148, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "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": 1157, "end_line": 1194, "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": 1201, "end_line": 1209, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "array_item", "long_name": "array_item( PyArrayObject * self , int i)", "filename": "arrayobject.c", "nloc": 22, "complexity": 4, "token_count": 150, "parameters": [ "self", "i" ], "start_line": 1213, "end_line": 1237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "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": 26, "parameters": [ "self", "i" ], "start_line": 1240, "end_line": 1243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "array_ass_item", "long_name": "array_ass_item( PyArrayObject * self , int i , PyObject * v)", "filename": "arrayobject.c", "nloc": 27, "complexity": 8, "token_count": 177, "parameters": [ "self", "i", "v" ], "start_line": 1247, "end_line": 1277, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "slice_coerce_index", "long_name": "slice_coerce_index( PyObject * o , int * v)", "filename": "arrayobject.c", "nloc": 9, "complexity": 2, "token_count": 40, "parameters": [ "o", "v" ], "start_line": 1281, "end_line": 1289, "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 , int length , int * start , int * stop , int * step , intp * slicelength)", "filename": "arrayobject.c", "nloc": 45, "complexity": 24, "token_count": 376, "parameters": [ "r", "length", "start", "stop", "step", "slicelength" ], "start_line": 1295, "end_line": 1345, "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 , int * step_size , intp * n_steps , int max)", "filename": "arrayobject.c", "nloc": 45, "complexity": 11, "token_count": 223, "parameters": [ "op", "step_size", "n_steps", "max" ], "start_line": 1352, "end_line": 1397, "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": 89, "complexity": 20, "token_count": 540, "parameters": [ "self", "op", "dimensions", "strides", "offset_ptr" ], "start_line": 1401, "end_line": 1496, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 96, "top_nesting_level": 0 }, { "name": "_swap_axes", "long_name": "_swap_axes( PyArrayMapIterObject * mit , PyArrayObject ** ret)", "filename": "arrayobject.c", "nloc": 24, "complexity": 4, "token_count": 187, "parameters": [ "mit", "ret" ], "start_line": 1499, "end_line": 1533, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "PyArray_GetMap", "long_name": "PyArray_GetMap( PyArrayMapIterObject * mit)", "filename": "arrayobject.c", "nloc": 36, "complexity": 8, "token_count": 252, "parameters": [ "mit" ], "start_line": 1538, "end_line": 1587, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "top_nesting_level": 0 }, { "name": "PyArray_SetMap", "long_name": "PyArray_SetMap( PyArrayMapIterObject * mit , PyObject * op)", "filename": "arrayobject.c", "nloc": 50, "complexity": 12, "token_count": 392, "parameters": [ "mit", "op" ], "start_line": 1590, "end_line": 1649, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 60, "top_nesting_level": 0 }, { "name": "array_subscript", "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", "filename": "arrayobject.c", "nloc": 61, "complexity": 19, "token_count": 425, "parameters": [ "self", "op" ], "start_line": 1670, "end_line": 1745, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 76, "top_nesting_level": 0 }, { "name": "array_ass_sub", "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", "filename": "arrayobject.c", "nloc": 43, "complexity": 9, "token_count": 251, "parameters": [ "self", "index", "op" ], "start_line": 1758, "end_line": 1810, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "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": 1818, "end_line": 1821, "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": 1840, "end_line": 1852, "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": 1855, "end_line": 1870, "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": 1874, "end_line": 1883, "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": 1886, "end_line": 1897, "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": 1965, "end_line": 1998, "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": 2005, "end_line": 2044, "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": 23, "complexity": 5, "token_count": 136, "parameters": [ "m1", "op", "axis", "rtype" ], "start_line": 2047, "end_line": 2069, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "PyArray_GenericAccumulateFunction", "long_name": "PyArray_GenericAccumulateFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", "filename": "arrayobject.c", "nloc": 23, "complexity": 5, "token_count": 136, "parameters": [ "m1", "op", "axis", "rtype" ], "start_line": 2073, "end_line": 2095, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "PyArray_GenericBinaryFunction", "long_name": "PyArray_GenericBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", "filename": "arrayobject.c", "nloc": 12, "complexity": 2, "token_count": 69, "parameters": [ "m1", "m2", "op" ], "start_line": 2099, "end_line": 2110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_GenericUnaryFunction", "long_name": "PyArray_GenericUnaryFunction( PyArrayObject * m1 , PyObject * op)", "filename": "arrayobject.c", "nloc": 12, "complexity": 2, "token_count": 63, "parameters": [ "m1", "op" ], "start_line": 2113, "end_line": 2124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_GenericInplaceBinaryFunction", "long_name": "PyArray_GenericInplaceBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", "filename": "arrayobject.c", "nloc": 13, "complexity": 2, "token_count": 71, "parameters": [ "m1", "m2", "op" ], "start_line": 2127, "end_line": 2139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 2142, "end_line": 2145, "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": 2148, "end_line": 2151, "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": 2154, "end_line": 2157, "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": 2160, "end_line": 2163, "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": 2166, "end_line": 2169, "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": 2172, "end_line": 2175, "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": 2178, "end_line": 2181, "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": 2184, "end_line": 2187, "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": 2190, "end_line": 2193, "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": 2196, "end_line": 2199, "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": 2202, "end_line": 2205, "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": 2208, "end_line": 2211, "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": 2214, "end_line": 2217, "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": 2220, "end_line": 2223, "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": 2226, "end_line": 2229, "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": 2232, "end_line": 2235, "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": 2238, "end_line": 2241, "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": 2244, "end_line": 2247, "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": 2250, "end_line": 2253, "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": 2256, "end_line": 2259, "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": 2262, "end_line": 2265, "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": 2268, "end_line": 2271, "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": 2274, "end_line": 2277, "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": 2280, "end_line": 2283, "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": 2286, "end_line": 2289, "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": 2292, "end_line": 2295, "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": 2298, "end_line": 2301, "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": 2304, "end_line": 2308, "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": 2311, "end_line": 2315, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "array_all_nonzero", "long_name": "array_all_nonzero( PyArrayObject * mp)", "filename": "arrayobject.c", "nloc": 18, "complexity": 4, "token_count": 93, "parameters": [ "mp" ], "start_line": 2319, "end_line": 2337, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "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": 2340, "end_line": 2355, "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": 143, "parameters": [ "v" ], "start_line": 2359, "end_line": 2385, "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": 143, "parameters": [ "v" ], "start_line": 2388, "end_line": 2413, "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": 124, "parameters": [ "v" ], "start_line": 2416, "end_line": 2438, "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": 124, "parameters": [ "v" ], "start_line": 2441, "end_line": 2463, "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": 124, "parameters": [ "v" ], "start_line": 2466, "end_line": 2488, "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": 2491, "end_line": 2495, "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": 34, "complexity": 11, "token_count": 258, "parameters": [ "self", "ilow", "ihigh" ], "start_line": 2556, "end_line": 2594, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "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": 2598, "end_line": 2619, "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": 4, "complexity": 1, "token_count": 26, "parameters": [ "self", "el" ], "start_line": 2622, "end_line": 2627, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "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": 308, "parameters": [ "string", "n", "max_n", "data", "nd", "dimensions", "strides", "self" ], "start_line": 2648, "end_line": 2695, "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": 222, "parameters": [ "self" ], "start_line": 2698, "end_line": 2734, "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": 2740, "end_line": 2757, "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": 2760, "end_line": 2772, "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": 2775, "end_line": 2787, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "array_richcompare", "long_name": "array_richcompare( PyArrayObject * self , PyObject * other , int cmp_op)", "filename": "arrayobject.c", "nloc": 61, "complexity": 13, "token_count": 273, "parameters": [ "self", "other", "cmp_op" ], "start_line": 2791, "end_line": 2868, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 78, "top_nesting_level": 0 }, { "name": "_check_axis", "long_name": "_check_axis( PyArrayObject * arr , int * axis , int flags)", "filename": "arrayobject.c", "nloc": 29, "complexity": 8, "token_count": 164, "parameters": [ "arr", "axis", "flags" ], "start_line": 2871, "end_line": 2900, "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": 17, "complexity": 4, "token_count": 91, "parameters": [ "len", "vals" ], "start_line": 2906, "end_line": 2922, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "PyArray_IntpFromSequence", "long_name": "PyArray_IntpFromSequence( PyObject * seq , intp * vals , int maxvals)", "filename": "arrayobject.c", "nloc": 21, "complexity": 7, "token_count": 161, "parameters": [ "seq", "vals", "maxvals" ], "start_line": 2927, "end_line": 2950, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "_IsContiguous", "long_name": "_IsContiguous( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 14, "complexity": 6, "token_count": 109, "parameters": [ "ap" ], "start_line": 2956, "end_line": 2972, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_IsFortranContiguous", "long_name": "_IsFortranContiguous( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 14, "complexity": 6, "token_count": 107, "parameters": [ "ap" ], "start_line": 2976, "end_line": 2992, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_IsAligned", "long_name": "_IsAligned( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 14, "complexity": 4, "token_count": 110, "parameters": [ "ap" ], "start_line": 2995, "end_line": 3011, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_IsWriteable", "long_name": "_IsWriteable( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 16, "complexity": 8, "token_count": 109, "parameters": [ "ap" ], "start_line": 3014, "end_line": 3047, "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": 22, "complexity": 9, "token_count": 129, "parameters": [ "ret", "flagmask" ], "start_line": 3051, "end_line": 3073, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "PyArray_CheckStrides", "long_name": "PyArray_CheckStrides( int elsize , int nd , intp numbytes , intp * dims , intp * newstrides)", "filename": "arrayobject.c", "nloc": 13, "complexity": 4, "token_count": 84, "parameters": [ "elsize", "nd", "numbytes", "dims", "newstrides" ], "start_line": 3080, "end_line": 3095, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "_array_fill_strides", "long_name": "_array_fill_strides( intp * strides , intp * dims , int nd , intp itemsize , int inflag , int * objflags)", "filename": "arrayobject.c", "nloc": 24, "complexity": 9, "token_count": 171, "parameters": [ "strides", "dims", "nd", "itemsize", "inflag", "objflags" ], "start_line": 3115, "end_line": 3139, "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 , char * data , int itemsize , int flags , PyObject * obj)", "filename": "arrayobject.c", "nloc": 117, "complexity": 27, "token_count": 713, "parameters": [ "subtype", "nd", "dims", "type_num", "strides", "data", "itemsize", "flags", "obj" ], "start_line": 3143, "end_line": 3293, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 151, "top_nesting_level": 0 }, { "name": "PyArray_Resize", "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape)", "filename": "arrayobject.c", "nloc": 87, "complexity": 15, "token_count": 501, "parameters": [ "self", "newshape" ], "start_line": 3298, "end_line": 3403, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 106, "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": 3408, "end_line": 3425, "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": 47, "complexity": 7, "token_count": 261, "parameters": [ "arr", "obj" ], "start_line": 3428, "end_line": 3480, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "top_nesting_level": 0 }, { "name": "array_new", "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", "filename": "arrayobject.c", "nloc": 100, "complexity": 20, "token_count": 589, "parameters": [ "subtype", "args", "kwds" ], "start_line": 3483, "end_line": 3598, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 116, "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": 3605, "end_line": 3608, "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": 10, "complexity": 3, "token_count": 57, "parameters": [ "self" ], "start_line": 3611, "end_line": 3621, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "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": 3694, "end_line": 3697, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "array_shape_set", "long_name": "array_shape_set( PyArrayObject * self , PyObject * val)", "filename": "arrayobject.c", "nloc": 33, "complexity": 6, "token_count": 206, "parameters": [ "self", "val" ], "start_line": 3701, "end_line": 3735, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "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": 3739, "end_line": 3742, "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": 32, "complexity": 7, "token_count": 209, "parameters": [ "self", "obj" ], "start_line": 3745, "end_line": 3778, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "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": 3782, "end_line": 3789, "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": 3792, "end_line": 3800, "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": 3804, "end_line": 3810, "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": 3813, "end_line": 3827, "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": 3830, "end_line": 3874, "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": 19, "parameters": [ "self" ], "start_line": 3878, "end_line": 3881, "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": 8, "complexity": 3, "token_count": 45, "parameters": [ "self" ], "start_line": 3884, "end_line": 3891, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "array_typechar_get", "long_name": "array_typechar_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 8, "complexity": 2, "token_count": 47, "parameters": [ "self" ], "start_line": 3895, "end_line": 3902, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "array_typestr_get", "long_name": "array_typestr_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 19, "complexity": 7, "token_count": 141, "parameters": [ "self" ], "start_line": 3905, "end_line": 3925, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "array_descr_get", "long_name": "array_descr_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 19, "complexity": 5, "token_count": 128, "parameters": [ "self" ], "start_line": 3928, "end_line": 3950, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "array_type_get", "long_name": "array_type_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 4, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 3954, "end_line": 3957, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "array_type_set", "long_name": "array_type_set( PyArrayObject * self , PyObject * arg)", "filename": "arrayobject.c", "nloc": 41, "complexity": 10, "token_count": 294, "parameters": [ "self", "arg" ], "start_line": 3969, "end_line": 4027, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 59, "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": 4032, "end_line": 4042, "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": 4046, "end_line": 4071, "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": 31, "complexity": 4, "token_count": 177, "parameters": [ "self", "val" ], "start_line": 4075, "end_line": 4107, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "array_imag_get", "long_name": "array_imag_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 34, "complexity": 3, "token_count": 200, "parameters": [ "self" ], "start_line": 4110, "end_line": 4145, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "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": 203, "parameters": [ "self", "val" ], "start_line": 4148, "end_line": 4185, "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": 4188, "end_line": 4191, "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": 51, "complexity": 9, "token_count": 368, "parameters": [ "self", "val" ], "start_line": 4194, "end_line": 4248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 55, "top_nesting_level": 0 }, { "name": "discover_depth", "long_name": "discover_depth( PyObject * s , int max , int stop_at_string)", "filename": "arrayobject.c", "nloc": 23, "complexity": 14, "token_count": 169, "parameters": [ "s", "max", "stop_at_string" ], "start_line": 4423, "end_line": 4448, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "discover_itemsize", "long_name": "discover_itemsize( PyObject * s , int nd , int * itemsize)", "filename": "arrayobject.c", "nloc": 21, "complexity": 9, "token_count": 161, "parameters": [ "s", "nd", "itemsize" ], "start_line": 4451, "end_line": 4473, "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": 4480, "end_line": 4506, "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( int chktype , int mintype , int chksize , int minsize , PyArray_Typecode * outtype)", "filename": "arrayobject.c", "nloc": 19, "complexity": 5, "token_count": 100, "parameters": [ "chktype", "mintype", "chksize", "minsize", "outtype" ], "start_line": 4509, "end_line": 4529, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "_array_find_type", "long_name": "_array_find_type( PyObject * op , PyArray_Typecode * minitype , PyArray_Typecode * outtype , int max)", "filename": "arrayobject.c", "nloc": 126, "complexity": 28, "token_count": 671, "parameters": [ "op", "minitype", "outtype", "max" ], "start_line": 4532, "end_line": 4673, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 142, "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": 4676, "end_line": 4699, "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_Typecode * typecode)", "filename": "arrayobject.c", "nloc": 19, "complexity": 4, "token_count": 120, "parameters": [ "op", "typecode" ], "start_line": 4703, "end_line": 4726, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "Array_FromSequence", "long_name": "Array_FromSequence( PyObject * s , PyArray_Typecode * typecode , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 51, "complexity": 17, "token_count": 313, "parameters": [ "s", "typecode", "min_depth", "max_depth" ], "start_line": 4730, "end_line": 4787, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 58, "top_nesting_level": 0 }, { "name": "PyArray_ValidType", "long_name": "PyArray_ValidType( int type)", "filename": "arrayobject.c", "nloc": 7, "complexity": 2, "token_count": 30, "parameters": [ "type" ], "start_line": 4791, "end_line": 4798, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "_bufferedcast", "long_name": "_bufferedcast( PyArrayObject * out , PyArrayObject * in)", "filename": "arrayobject.c", "nloc": 75, "complexity": 16, "token_count": 477, "parameters": [ "out", "in" ], "start_line": 4804, "end_line": 4894, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 91, "top_nesting_level": 0 }, { "name": "PyArray_Cast", "long_name": "PyArray_Cast( PyArrayObject * mp , int type_num)", "filename": "arrayobject.c", "nloc": 10, "complexity": 1, "token_count": 56, "parameters": [ "mp", "type_num" ], "start_line": 4900, "end_line": 4911, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_CastToType", "long_name": "PyArray_CastToType( PyArrayObject * mp , PyArray_Typecode * at)", "filename": "arrayobject.c", "nloc": 31, "complexity": 13, "token_count": 233, "parameters": [ "mp", "at" ], "start_line": 4914, "end_line": 4949, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "PyArray_CastTo", "long_name": "PyArray_CastTo( PyArrayObject * out , PyArrayObject * mp)", "filename": "arrayobject.c", "nloc": 40, "complexity": 10, "token_count": 214, "parameters": [ "out", "mp" ], "start_line": 4956, "end_line": 5002, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "array_fromarray", "long_name": "array_fromarray( PyArrayObject * arr , PyArray_Typecode * typecode , int flags)", "filename": "arrayobject.c", "nloc": 116, "complexity": 35, "token_count": 721, "parameters": [ "arr", "typecode", "flags" ], "start_line": 5005, "end_line": 5136, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 132, "top_nesting_level": 0 }, { "name": "_array_typecode_fromstr", "long_name": "_array_typecode_fromstr( char * str , int * swap , PyArray_Typecode * type)", "filename": "arrayobject.c", "nloc": 94, "complexity": 36, "token_count": 533, "parameters": [ "str", "swap", "type" ], "start_line": 5140, "end_line": 5245, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 106, "top_nesting_level": 0 }, { "name": "array_frominterface", "long_name": "array_frominterface( PyObject * input , PyArray_Typecode * intype , int flags)", "filename": "arrayobject.c", "nloc": 113, "complexity": 26, "token_count": 715, "parameters": [ "input", "intype", "flags" ], "start_line": 5248, "end_line": 5371, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 124, "top_nesting_level": 0 }, { "name": "array_fromattr", "long_name": "array_fromattr( PyObject * op , PyArray_Typecode * typecode , int flags)", "filename": "arrayobject.c", "nloc": 30, "complexity": 5, "token_count": 181, "parameters": [ "op", "typecode", "flags" ], "start_line": 5374, "end_line": 5405, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "array_fromobject", "long_name": "array_fromobject( PyObject * op , PyArray_Typecode * typecode , int min_depth , int max_depth , int flags)", "filename": "arrayobject.c", "nloc": 49, "complexity": 14, "token_count": 291, "parameters": [ "op", "typecode", "min_depth", "max_depth", "flags" ], "start_line": 5409, "end_line": 5474, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 66, "top_nesting_level": 0 }, { "name": "PyArray_ArrayType", "long_name": "PyArray_ArrayType( PyObject * op , PyArray_Typecode * intype , PyArray_Typecode * outtype)", "filename": "arrayobject.c", "nloc": 6, "complexity": 1, "token_count": 29, "parameters": [ "op", "intype", "outtype" ], "start_line": 5477, "end_line": 5482, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "PyArray_ObjectType", "long_name": "PyArray_ObjectType( PyObject * op , int minimum_type)", "filename": "arrayobject.c", "nloc": 7, "complexity": 1, "token_count": 40, "parameters": [ "op", "minimum_type" ], "start_line": 5485, "end_line": 5491, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "PyArray_FromAny", "long_name": "PyArray_FromAny( PyObject * op , PyArray_Typecode * typecode , int min_depth , int max_depth , int requires)", "filename": "arrayobject.c", "nloc": 24, "complexity": 9, "token_count": 165, "parameters": [ "op", "typecode", "min_depth", "max_depth", "requires" ], "start_line": 5545, "end_line": 5575, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "PyArray_EnsureArray", "long_name": "PyArray_EnsureArray( PyObject * op)", "filename": "arrayobject.c", "nloc": 14, "complexity": 5, "token_count": 87, "parameters": [ "op" ], "start_line": 5586, "end_line": 5602, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "PyArray_FromObject", "long_name": "PyArray_FromObject( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 7, "complexity": 1, "token_count": 51, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5608, "end_line": 5614, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "PyArray_ContiguousFromObject", "long_name": "PyArray_ContiguousFromObject( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 8, "complexity": 1, "token_count": 51, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5617, "end_line": 5624, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_CopyFromObject", "long_name": "PyArray_CopyFromObject( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 8, "complexity": 1, "token_count": 51, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5627, "end_line": 5634, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_ContiguousFromAny", "long_name": "PyArray_ContiguousFromAny( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 8, "complexity": 1, "token_count": 49, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5639, "end_line": 5646, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_CanCastSafely", "long_name": "PyArray_CanCastSafely( int fromtype , int totype)", "filename": "arrayobject.c", "nloc": 81, "complexity": 39, "token_count": 476, "parameters": [ "fromtype", "totype" ], "start_line": 5649, "end_line": 5732, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 84, "top_nesting_level": 0 }, { "name": "PyArray_CanCastTo", "long_name": "PyArray_CanCastTo( PyArray_Typecode * from , PyArray_Typecode * to)", "filename": "arrayobject.c", "nloc": 24, "complexity": 7, "token_count": 134, "parameters": [ "from", "to" ], "start_line": 5735, "end_line": 5759, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 }, { "name": "PyArray_IterNew", "long_name": "PyArray_IterNew( PyObject * obj)", "filename": "arrayobject.c", "nloc": 34, "complexity": 6, "token_count": 258, "parameters": [ "obj" ], "start_line": 5769, "end_line": 5806, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "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": 5811, "end_line": 5821, "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": 6, "complexity": 1, "token_count": 25, "parameters": [ "it" ], "start_line": 5824, "end_line": 5829, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "arrayiter_traverse", "long_name": "arrayiter_traverse( PyArrayIterObject * it , visitproc visit , * arg)", "filename": "arrayobject.c", "nloc": 6, "complexity": 2, "token_count": 42, "parameters": [ "it", "visit", "arg" ], "start_line": 5832, "end_line": 5837, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "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": 5841, "end_line": 5844, "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": 42, "complexity": 7, "token_count": 272, "parameters": [ "self", "ind" ], "start_line": 5848, "end_line": 5896, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "iter_subscript_int", "long_name": "iter_subscript_int( PyArrayIterObject * self , PyArrayObject * ind)", "filename": "arrayobject.c", "nloc": 51, "complexity": 8, "token_count": 347, "parameters": [ "self", "ind" ], "start_line": 5899, "end_line": 5952, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 0 }, { "name": "iter_subscript", "long_name": "iter_subscript( PyArrayIterObject * self , PyObject * ind)", "filename": "arrayobject.c", "nloc": 97, "complexity": 20, "token_count": 593, "parameters": [ "self", "ind" ], "start_line": 5956, "end_line": 6075, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 120, "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": 176, "parameters": [ "self", "ind", "val", "swap" ], "start_line": 6079, "end_line": 6111, "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": 289, "parameters": [ "self", "ind", "val", "swap" ], "start_line": 6114, "end_line": 6156, "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": 103, "complexity": 24, "token_count": 636, "parameters": [ "self", "ind", "val" ], "start_line": 6160, "end_line": 6282, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 123, "top_nesting_level": 0 }, { "name": "iter_array", "long_name": "iter_array( PyArrayIterObject * it , PyObject * op)", "filename": "arrayobject.c", "nloc": 30, "complexity": 5, "token_count": 221, "parameters": [ "it", "op" ], "start_line": 6295, "end_line": 6337, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "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": 6342, "end_line": 6346, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "fancy_indexing_check", "long_name": "fancy_indexing_check( PyObject * args)", "filename": "arrayobject.c", "nloc": 55, "complexity": 22, "token_count": 293, "parameters": [ "args" ], "start_line": 6411, "end_line": 6472, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 62, "top_nesting_level": 0 }, { "name": "_convert_obj", "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", "filename": "arrayobject.c", "nloc": 15, "complexity": 5, "token_count": 105, "parameters": [ "obj", "iter" ], "start_line": 6480, "end_line": 6495, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "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": 6501, "end_line": 6570, "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": 261, "parameters": [ "mit" ], "start_line": 6574, "end_line": 6611, "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": 296, "parameters": [ "mit" ], "start_line": 6617, "end_line": 6661, "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": 102, "complexity": 22, "token_count": 690, "parameters": [ "mit", "arr" ], "start_line": 6679, "end_line": 6815, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 137, "top_nesting_level": 0 }, { "name": "_nonzero_indices", "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", "filename": "arrayobject.c", "nloc": 57, "complexity": 15, "token_count": 454, "parameters": [ "myBool", "iters" ], "start_line": 6821, "end_line": 6890, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 70, "top_nesting_level": 0 }, { "name": "PyArray_MapIterNew", "long_name": "PyArray_MapIterNew( PyObject * indexobj)", "filename": "arrayobject.c", "nloc": 111, "complexity": 24, "token_count": 745, "parameters": [ "indexobj" ], "start_line": 6893, "end_line": 7026, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 134, "top_nesting_level": 0 }, { "name": "arraymapiter_new", "long_name": "arraymapiter_new( PyTypeObject * type , PyObject * args , PyObject * kwds)", "filename": "arrayobject.c", "nloc": 26, "complexity": 5, "token_count": 130, "parameters": [ "type", "args", "kwds" ], "start_line": 7032, "end_line": 7062, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "arraymapiter_dealloc", "long_name": "arraymapiter_dealloc( PyArrayMapIterObject * mit)", "filename": "arrayobject.c", "nloc": 10, "complexity": 2, "token_count": 60, "parameters": [ "mit" ], "start_line": 7083, "end_line": 7092, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "arraymapiter_traverse", "long_name": "arraymapiter_traverse( PyArrayMapIterObject * mit , visitproc visit , * arg)", "filename": "arrayobject.c", "nloc": 16, "complexity": 9, "token_count": 146, "parameters": [ "mit", "visit", "arg" ], "start_line": 7095, "end_line": 7113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "Array_FromScalar", "long_name": "Array_FromScalar( PyObject * op , PyArray_Typecode * typecode)", "filename": "arrayobject.c", "nloc": 21, "complexity": 5, "token_count": 132, "parameters": [ "op", "typecode" ], "start_line": 4703, "end_line": 4729, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 0 } ], "nloc": 5643, "complexity": 1233, "token_count": 33725, "diff_parsed": { "added": [ "\tint itemsize;", "\tint type;", "", "\titemsize = typecode->itemsize;", "\ttype = typecode->type_num;", "\tif (itemsize == 0 && PyTypeNum_ISFLEXIBLE(type)) {" ], "deleted": [ "\tint itemsize = 0;", "\tint type = typecode->type_num;", "\tif PyTypeNum_ISFLEXIBLE(type) {" ] } } ] }, { "hash": "98830f76c36d104d8bd18d2c794500f51ba645b2", "msg": "Fixed string_from_pyobj to handle multi-length string conversion.", "author": { "name": "Travis Oliphant", "email": "oliphant@enthought.com" }, "committer": { "name": "Travis Oliphant", "email": "oliphant@enthought.com" }, "author_date": "2005-10-26T04:21:53+00:00", "author_timezone": 0, "committer_date": "2005-10-26T04:21:53+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "9e2b9a429169902426dc07156f0414d2ec63a8c6" ], "project_name": "repo_copy", "project_path": "/tmp/tmpn4cqam_6/repo_copy", "deletions": 9, "insertions": 5, "lines": 14, "files": 1, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "scipy/f2py2e/cfuncs.py", "new_path": "scipy/f2py2e/cfuncs.py", "filename": "cfuncs.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -704,15 +704,11 @@\n \\t\\t\\tPyErr_SetString(PyExc_ValueError,\\\"array object is non-contiguous.\\\");\n \\t\\t\\tgoto capi_fail;\n \\t\\t}\n-\\t\\tif (arr->descr->elsize==sizeof(char)) {\n-\\t\\t\\tif (*len == -1)\n-\\t\\t\\t\\t*len = (arr->descr->elsize)*PyArray_SIZE(arr);\n-\\t\\t\\tSTRINGMALLOC(*str,*len);\n-\\t\\t\\tSTRINGCOPYN(*str,arr->data,*len);\n-\\t\\t\\treturn 1;\n-\\t\\t}\n-\\t\\tPyErr_SetString(PyExc_ValueError,\\\"array object element size is not 1.\\\");\n-\\t\\tgoto capi_fail;\n+\\t\\tif (*len == -1)\n+\\t\\t\\t*len = (arr->itemsize)*PyArray_SIZE(arr);\n+\\t\\tSTRINGMALLOC(*str,*len);\n+\\t\\tSTRINGCOPYN(*str,arr->data,*len);\n+\\t\\treturn 1;\n \\t}\n \\tif (PyString_Check(obj)) {\n \\t\\ttmp = obj;\n", "added_lines": 5, "deleted_lines": 9, "source_code": "#!/usr/bin/env python\n\"\"\"\n\nC declarations, CPP macros, and C functions for f2py2e.\nOnly required declarations/macros/functions will be used.\n\nCopyright 1999,2000 Pearu Peterson all rights reserved,\nPearu Peterson \nPermission to use, modify, and distribute this software is given under the\nterms of the LGPL. See http://www.fsf.org\n\nNO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n$Date: 2005/05/06 11:42:34 $\nPearu Peterson\n\"\"\"\n\n__version__ = \"$Revision: 1.75 $\"[10:-1]\n\nimport __version__\nf2py_version = __version__.version\n\nimport types,sys,copy,os\nerrmess=sys.stderr.write\n\n##################### Definitions ##################\n\noutneeds={'includes0':[],'includes':[],'typedefs':[],'typedefs_generated':[],\n 'userincludes':[],\n 'cppmacros':[],'cfuncs':[],'callbacks':[],'f90modhooks':[],\n 'commonhooks':[]}\nneeds={}\nincludes0={'includes0':'/*need_includes0*/'}\nincludes={'includes':'/*need_includes*/'}\nuserincludes={'userincludes':'/*need_userincludes*/'}\ntypedefs={'typedefs':'/*need_typedefs*/'}\ntypedefs_generated={'typedefs_generated':'/*need_typedefs_generated*/'}\ncppmacros={'cppmacros':'/*need_cppmacros*/'}\ncfuncs={'cfuncs':'/*need_cfuncs*/'}\ncallbacks={'callbacks':'/*need_callbacks*/'}\nf90modhooks={'f90modhooks':'/*need_f90modhooks*/',\n 'initf90modhooksstatic':'/*initf90modhooksstatic*/',\n 'initf90modhooksdynamic':'/*initf90modhooksdynamic*/',\n }\ncommonhooks={'commonhooks':'/*need_commonhooks*/',\n 'initcommonhooks':'/*need_initcommonhooks*/',\n }\n\n############ Includes ###################\n\nincludes0['math.h']='#include '\nincludes0['string.h']='#include '\nincludes0['setjmp.h']='#include '\n\nincludes['Python.h']='#include \"Python.h\"'\nneeds['arrayobject.h']=['Python.h']\nincludes['arrayobject.h']='''#define PY_ARRAY_UNIQUE_SYMBOL PyArray_API\n#include \"arrayobject.h\"'''\n\nincludes['arrayobject.h']='#include \"fortranobject.h\"'\n\n############# Type definitions ###############\n\ntypedefs['unsigned_char']='typedef unsigned char unsigned_char;'\ntypedefs['unsigned_short']='typedef unsigned short unsigned_short;'\ntypedefs['unsigned_long']='typedef unsigned long unsigned_long;'\ntypedefs['signed_char']='typedef signed char signed_char;'\ntypedefs['long_long']=\"\"\"\\\n#ifdef _WIN32\ntypedef __int64 long_long;\n#else\ntypedef long long long_long;\ntypedef unsigned long long unsigned_long_long;\n#endif\n\"\"\"\ntypedefs['insinged_long_long']=\"\"\"\\\n#ifdef _WIN32\ntypedef __uint64 long_long;\n#else\ntypedef unsigned long long unsigned_long_long;\n#endif\n\"\"\"\ntypedefs['long_double']=\"\"\"\\\n#ifndef _LONG_DOUBLE\ntypedef long double long_double;\n#endif\n\"\"\"\ntypedefs['complex_long_double']='typedef struct {long double r,i;} complex_long_double;'\ntypedefs['complex_float']='typedef struct {float r,i;} complex_float;'\ntypedefs['complex_double']='typedef struct {double r,i;} complex_double;'\ntypedefs['string']=\"\"\"typedef char * string;\"\"\"\n\n\n############### CPP macros ####################\ncppmacros['CFUNCSMESS']=\"\"\"\\\n#ifdef DEBUGCFUNCS\n#define CFUNCSMESS(mess) fprintf(stderr,\\\"debug-capi:\\\"mess);\n#define CFUNCSMESSPY(mess,obj) CFUNCSMESS(mess) \\\\\n\\tPyObject_Print((PyObject *)obj,stderr,Py_PRINT_RAW);\\\\\n\\tfprintf(stderr,\\\"\\\\n\\\");\n#else\n#define CFUNCSMESS(mess)\n#define CFUNCSMESSPY(mess,obj)\n#endif\n\"\"\"\ncppmacros['F_FUNC']=\"\"\"\\\n#if defined(PREPEND_FORTRAN)\n#if defined(NO_APPEND_FORTRAN)\n#if defined(UPPERCASE_FORTRAN)\n#define F_FUNC(f,F) _##F\n#else\n#define F_FUNC(f,F) _##f\n#endif\n#else\n#if defined(UPPERCASE_FORTRAN)\n#define F_FUNC(f,F) _##F##_\n#else\n#define F_FUNC(f,F) _##f##_\n#endif\n#endif\n#else\n#if defined(NO_APPEND_FORTRAN)\n#if defined(UPPERCASE_FORTRAN)\n#define F_FUNC(f,F) F\n#else\n#define F_FUNC(f,F) f\n#endif\n#else\n#if defined(UPPERCASE_FORTRAN)\n#define F_FUNC(f,F) F##_\n#else\n#define F_FUNC(f,F) f##_\n#endif\n#endif\n#endif\n#if defined(UNDERSCORE_G77)\n#define F_FUNC_US(f,F) F_FUNC(f##_,F##_)\n#else\n#define F_FUNC_US(f,F) F_FUNC(f,F)\n#endif\n\"\"\"\ncppmacros['F_WRAPPEDFUNC']=\"\"\"\\\n#if defined(PREPEND_FORTRAN)\n#if defined(NO_APPEND_FORTRAN)\n#if defined(UPPERCASE_FORTRAN)\n#define F_WRAPPEDFUNC(f,F) _F2PYWRAP##F\n#else\n#define F_WRAPPEDFUNC(f,F) _f2pywrap##f\n#endif\n#else\n#if defined(UPPERCASE_FORTRAN)\n#define F_WRAPPEDFUNC(f,F) _F2PYWRAP##F##_\n#else\n#define F_WRAPPEDFUNC(f,F) _f2pywrap##f##_\n#endif\n#endif\n#else\n#if defined(NO_APPEND_FORTRAN)\n#if defined(UPPERCASE_FORTRAN)\n#define F_WRAPPEDFUNC(f,F) F2PYWRAP##F\n#else\n#define F_WRAPPEDFUNC(f,F) f2pywrap##f\n#endif\n#else\n#if defined(UPPERCASE_FORTRAN)\n#define F_WRAPPEDFUNC(f,F) F2PYWRAP##F##_\n#else\n#define F_WRAPPEDFUNC(f,F) f2pywrap##f##_\n#endif\n#endif\n#endif\n#if defined(UNDERSCORE_G77)\n#define F_WRAPPEDFUNC_US(f,F) F_WRAPPEDFUNC(f##_,F##_)\n#else\n#define F_WRAPPEDFUNC_US(f,F) F_WRAPPEDFUNC(f,F)\n#endif\n\"\"\"\ncppmacros['F_MODFUNC']=\"\"\"\\\n#if defined(F90MOD2CCONV1) /*E.g. Compaq Fortran */\n#if defined(NO_APPEND_FORTRAN)\n#define F_MODFUNCNAME(m,f) $ ## m ## $ ## f\n#else\n#define F_MODFUNCNAME(m,f) $ ## m ## $ ## f ## _\n#endif\n#endif\n\n#if defined(F90MOD2CCONV2) /*E.g. IBM XL Fortran, not tested though */\n#if defined(NO_APPEND_FORTRAN)\n#define F_MODFUNCNAME(m,f) __ ## m ## _MOD_ ## f\n#else\n#define F_MODFUNCNAME(m,f) __ ## m ## _MOD_ ## f ## _\n#endif\n#endif\n\n#if defined(F90MOD2CCONV3) /*E.g. MIPSPro Compilers */\n#if defined(NO_APPEND_FORTRAN)\n#define F_MODFUNCNAME(m,f) f ## .in. ## m\n#else\n#define F_MODFUNCNAME(m,f) f ## .in. ## m ## _\n#endif\n#endif\n/*\n#if defined(UPPERCASE_FORTRAN)\n#define F_MODFUNC(m,M,f,F) F_MODFUNCNAME(M,F)\n#else\n#define F_MODFUNC(m,M,f,F) F_MODFUNCNAME(m,f)\n#endif\n*/\n\n#define F_MODFUNC(m,f) (*(f2pymodstruct##m##.##f))\n\"\"\"\ncppmacros['SWAPUNSAFE']=\"\"\"\\\n#define SWAP(a,b) (size_t)(a) = ((size_t)(a) ^ (size_t)(b));\\\\\n (size_t)(b) = ((size_t)(a) ^ (size_t)(b));\\\\\n (size_t)(a) = ((size_t)(a) ^ (size_t)(b))\n\"\"\"\ncppmacros['SWAP']=\"\"\"\\\n#define SWAP(a,b,t) {\\\\\n\\tt *c;\\\\\n\\tc = a;\\\\\n\\ta = b;\\\\\n\\tb = c;}\n\"\"\"\n#cppmacros['ISCONTIGUOUS']='#define ISCONTIGUOUS(m) ((m)->flags & CONTIGUOUS)'\ncppmacros['PRINTPYOBJERR']=\"\"\"\\\n#define PRINTPYOBJERR(obj)\\\\\n\\tfprintf(stderr,\\\"#modulename#.error is related to \\\");\\\\\n\\tPyObject_Print((PyObject *)obj,stderr,Py_PRINT_RAW);\\\\\n\\tfprintf(stderr,\\\"\\\\n\\\");\n\"\"\"\ncppmacros['MINMAX']=\"\"\"\\\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\"\"\"\ncppmacros['len..']=\"\"\"\\\n#define rank(var) var ## _Rank\n#define shape(var,dim) var ## _Dims[dim]\n#define old_rank(var) (((PyArrayObject *)(capi_ ## var ## _tmp))->nd)\n#define old_shape(var,dim) (((PyArrayObject *)(capi_ ## var ## _tmp))->dimensions[dim])\n#define fshape(var,dim) shape(var,rank(var)-dim-1)\n#define len(var) shape(var,0)\n#define flen(var) fshape(var,0)\n#define size(var) PyArray_SIZE((PyArrayObject *)(capi_ ## var ## _tmp))\n/* #define index(i) capi_i ## i */\n#define slen(var) capi_ ## var ## _len\n\"\"\"\n\ncppmacros['pyobj_from_char1']='#define pyobj_from_char1(v) (PyInt_FromLong(v))'\ncppmacros['pyobj_from_short1']='#define pyobj_from_short1(v) (PyInt_FromLong(v))'\nneeds['pyobj_from_int1']=['signed_char']\ncppmacros['pyobj_from_int1']='#define pyobj_from_int1(v) (PyInt_FromLong(v))'\ncppmacros['pyobj_from_long1']='#define pyobj_from_long1(v) (PyLong_FromLong(v))'\nneeds['pyobj_from_long_long1']=['long_long']\ncppmacros['pyobj_from_long_long1']=\"\"\"\\\n#ifdef HAVE_LONG_LONG\n#define pyobj_from_long_long1(v) (PyLong_FromLongLong(v))\n#else\n#warning HAVE_LONG_LONG is not available. Redefining pyobj_from_long_long.\n#define pyobj_from_long_long1(v) (PyLong_FromLong(v))\n#endif\n\"\"\"\nneeds['pyobj_from_long_double1']=['long_double']\ncppmacros['pyobj_from_long_double1']='#define pyobj_from_long_double1(v) (PyFloat_FromDouble(v))'\ncppmacros['pyobj_from_double1']='#define pyobj_from_double1(v) (PyFloat_FromDouble(v))'\ncppmacros['pyobj_from_float1']='#define pyobj_from_float1(v) (PyFloat_FromDouble(v))'\nneeds['pyobj_from_complex_long_double1']=['complex_long_double']\ncppmacros['pyobj_from_complex_long_double1']='#define pyobj_from_complex_long_double1(v) (PyComplex_FromDoubles(v.r,v.i))'\nneeds['pyobj_from_complex_double1']=['complex_double']\ncppmacros['pyobj_from_complex_double1']='#define pyobj_from_complex_double1(v) (PyComplex_FromDoubles(v.r,v.i))'\nneeds['pyobj_from_complex_float1']=['complex_float']\ncppmacros['pyobj_from_complex_float1']='#define pyobj_from_complex_float1(v) (PyComplex_FromDoubles(v.r,v.i))'\nneeds['pyobj_from_string1']=['string']\ncppmacros['pyobj_from_string1']='#define pyobj_from_string1(v) (PyString_FromString((char *)v))'\nneeds['TRYPYARRAYTEMPLATE']=['PRINTPYOBJERR']\ncppmacros['TRYPYARRAYTEMPLATE']=\"\"\"\\\n#ifdef NUMARRAY\n/* Numarray */\n\n#if defined(USE_SIGNED_CHAR)\n#define TRYPYARRAYTEMPLATECHAR case PyArray_CHAR: *(char *)(arr->data)=*v; break;\n#else\n#define TRYPYARRAYTEMPLATECHAR\n#endif\n#if LP64\n#define TRYPYARRAYTEMPLATELONG case PyArray_LONG: *(long *)(arr->data)=*v; break;\n#else\n#define TRYPYARRAYTEMPLATELONG\n#endif\n\n/* XXX: need the corresponding numarray code here */\n#define TRYPYARRAYTEMPLATEOBJECT\n\n#elif defined(NDARRAY_VERSION)\n/* New SciPy */\n#define TRYPYARRAYTEMPLATECHAR case PyArray_STRING: *(char *)(arr->data)=*v; break;\n#define TRYPYARRAYTEMPLATELONG case PyArray_LONG: *(long *)(arr->data)=*v; break;\n#define TRYPYARRAYTEMPLATEOBJECT case PyArray_OBJECT: (arr->descr->setitem)(pyobj_from_ ## ctype ## 1(*v),arr->data); break;\n#else\n/* Numeric */\n\n#define TRYPYARRAYTEMPLATECHAR case PyArray_CHAR: *(char *)(arr->data)=*v; break;\n#define TRYPYARRAYTEMPLATELONG case PyArray_LONG: *(long *)(arr->data)=*v; break;\n#define TRYPYARRAYTEMPLATEOBJECT case PyArray_OBJECT: (arr->descr->setitem)(pyobj_from_ ## ctype ## 1(*v),arr->data); break;\n\n#endif\n\n#ifdef NUMARRAY\n#define TRYPYARRAYTEMPLATE(ctype,typecode) \\\\\n\tPyArrayObject *arr = NULL;\\\\\n\tif (!obj) return -2;\\\\\n\tif (!PyArray_Check(obj)) return -1;\\\\\n\tif (!(arr=(PyArrayObject *)obj)) {fprintf(stderr,\\\"TRYPYARRAYTEMPLATE:\\\");PRINTPYOBJERR(obj);return 0;}\\\\\n\tif (arr->descr->type==typecode) {*(ctype *)(arr->data)=*v; return 1;}\\\\\n\tswitch (arr->descr->type_num) {\\\\\n TRYPYARRAYTEMPLATELONG\\\\\n\t\tcase PyArray_DOUBLE: *(double *)(arr->data)=*v; break;\\\\\n\t\tcase PyArray_INT: *(int *)(arr->data)=*v; break;\\\\\n\t\tcase PyArray_FLOAT: *(float *)(arr->data)=*v; break;\\\\\n\t\tcase PyArray_CDOUBLE: *(double *)(arr->data)=*v; break;\\\\\n\t\tcase PyArray_CFLOAT: *(float *)(arr->data)=*v; break;\\\\\n TRYPYARRAYTEMPLATECHAR\\\\\n\t\tcase PyArray_UBYTE: *(unsigned char *)(arr->data)=*v; break;\\\\\n\t\tcase PyArray_SBYTE: *(signed char *)(arr->data)=*v; break;\\\\\n\t\tcase PyArray_SHORT: *(short *)(arr->data)=*v; break;\\\\\n TRYPYARRAYTEMPLATEOBJECT\\\\\n\tdefault: return -2;\\\\\n\t};\\\\\n\treturn 1;\n#elif defined(NDARRAY_VERSION)\n#define TRYPYARRAYTEMPLATE(ctype,typecode) \\\\\n\tPyArrayObject *arr = NULL;\\\\\n\tif (!obj) return -2;\\\\\n\tif (!PyArray_Check(obj)) return -1;\\\\\n\tif (!(arr=(PyArrayObject *)obj)) {fprintf(stderr,\\\"TRYPYARRAYTEMPLATE:\\\");PRINTPYOBJERR(obj);return 0;}\\\\\n\tif (arr->descr->type==typecode) {*(ctype *)(arr->data)=*v; return 1;}\\\\\n\tswitch (arr->descr->type_num) {\\\\\n TRYPYARRAYTEMPLATELONG\\\\\n\t\tcase PyArray_DOUBLE: *(double *)(arr->data)=*v; break;\\\\\n\t\tcase PyArray_INT: *(int *)(arr->data)=*v; break;\\\\\n\t\tcase PyArray_FLOAT: *(float *)(arr->data)=*v; break;\\\\\n\t\tcase PyArray_CDOUBLE: *(double *)(arr->data)=*v; break;\\\\\n\t\tcase PyArray_CFLOAT: *(float *)(arr->data)=*v; break;\\\\\n TRYPYARRAYTEMPLATECHAR\\\\\n\t\tcase PyArray_UBYTE: *(unsigned char *)(arr->data)=*v; break;\\\\\n\t\tcase PyArray_SBYTE: *(signed char *)(arr->data)=*v; break;\\\\\n\t\tcase PyArray_SHORT: *(short *)(arr->data)=*v; break;\\\\\n case PyArray_OBJECT: (arr->descr->setitem)(pyobj_from_ ## ctype ## 1(*v),arr->data, arr); break;\\\\\n\tdefault: return -2;\\\\\n\t};\\\\\n\treturn 1;\n#else\n#define TRYPYARRAYTEMPLATE(ctype,typecode) \\\\\n\tPyArrayObject *arr = NULL;\\\\\n\tif (!obj) return -2;\\\\\n\tif (!PyArray_Check(obj)) return -1;\\\\\n\tif (!(arr=(PyArrayObject *)obj)) {fprintf(stderr,\\\"TRYPYARRAYTEMPLATE:\\\");PRINTPYOBJERR(obj);return 0;}\\\\\n\tif (arr->descr->type==typecode) {*(ctype *)(arr->data)=*v; return 1;}\\\\\n\tswitch (arr->descr->type_num) {\\\\\n TRYPYARRAYTEMPLATELONG\\\\\n\t\tcase PyArray_DOUBLE: *(double *)(arr->data)=*v; break;\\\\\n\t\tcase PyArray_INT: *(int *)(arr->data)=*v; break;\\\\\n\t\tcase PyArray_FLOAT: *(float *)(arr->data)=*v; break;\\\\\n\t\tcase PyArray_CDOUBLE: *(double *)(arr->data)=*v; break;\\\\\n\t\tcase PyArray_CFLOAT: *(float *)(arr->data)=*v; break;\\\\\n TRYPYARRAYTEMPLATECHAR\\\\\n\t\tcase PyArray_UBYTE: *(unsigned char *)(arr->data)=*v; break;\\\\\n\t\tcase PyArray_SBYTE: *(signed char *)(arr->data)=*v; break;\\\\\n\t\tcase PyArray_SHORT: *(short *)(arr->data)=*v; break;\\\\\n case PyArray_OBJECT: (arr->descr->setitem)(pyobj_from_ ## ctype ## 1(*v),arr->data); break;\\\\\n\tdefault: return -2;\\\\\n\t};\\\\\n\treturn 1;\n#endif\n\"\"\"\n\nneeds['TRYCOMPLEXPYARRAYTEMPLATE']=['PRINTPYOBJERR']\ncppmacros['TRYCOMPLEXPYARRAYTEMPLATE']=\"\"\"\\\n#if PyArray_LONG != PyArray_INT\n#define TRYCOMPLEXPYARRAYTEMPLATELONG case PyArray_LONG: *(long *)(arr->data)=(*v).r; break;\n#else\n#define TRYCOMPLEXPYARRAYTEMPLATELONG\n#endif\n#if (PyArray_UBYTE != PyArray_CHAR)\n#define TRYCOMPLEXPYARRAYTEMPLATECHAR case PyArray_CHAR: *(char *)(arr->data)=(*v).r; break;\n#else\n#define TRYCOMPLEXPYARRAYTEMPLATECHAR\n#endif\n#ifdef NUMARRAY\n/* XXX: need the corresponding numarray code here */\n#define TRYCOMPLEXPYARRAYTEMPLATEOBJECT\n#elif defined(NDARRAY_VERSION)\n#define TRYCOMPLEXPYARRAYTEMPLATEOBJECT case PyArray_OBJECT: (arr->descr->setitem)(pyobj_from_complex_ ## ctype ## 1((*v)),arr->data, arr); break;\n#else\n#define TRYCOMPLEXPYARRAYTEMPLATEOBJECT case PyArray_OBJECT: (arr->descr->setitem)(pyobj_from_complex_ ## ctype ## 1((*v)),arr->data); break;\n#endif\n\n#ifdef NUMARRAY\n#define TRYCOMPLEXPYARRAYTEMPLATE(ctype,typecode)\\\\\n\tPyArrayObject *arr = NULL;\\\\\n\tif (!obj) return -2;\\\\\n\tif (!PyArray_Check(obj)) return -1;\\\\\n if (!(arr=(PyArrayObject *)obj)) {fprintf(stderr,\\\"TRYCOMPLEXPYARRAYTEMPLATE:\\\");PRINTPYOBJERR(obj);return 0;}\\\\\n\tif (arr->descr->type==typecode) {\\\\\n *(ctype *)(arr->data)=(*v).r;\\\\\n *(ctype *)(arr->data+sizeof(ctype))=(*v).i;\\\\\n return 1;\\\\\n }\\\\\n\tswitch (arr->descr->type_num) {\\\\\n\t\tcase PyArray_CDOUBLE: *(double *)(arr->data)=(*v).r;*(double *)(arr->data+sizeof(double))=(*v).i;break;\\\\\n\t\tcase PyArray_CFLOAT: *(float *)(arr->data)=(*v).r;*(float *)(arr->data+sizeof(float))=(*v).i;break;\\\\\n\t\tcase PyArray_DOUBLE: *(double *)(arr->data)=(*v).r; break;\\\\\n TRYCOMPLEXPYARRAYTEMPLATELONG\\\\\n\t\tcase PyArray_FLOAT: *(float *)(arr->data)=(*v).r; break;\\\\\n\t\tcase PyArray_INT: *(int *)(arr->data)=(*v).r; break;\\\\\n\t\tcase PyArray_SHORT: *(short *)(arr->data)=(*v).r; break;\\\\\n TRYCOMPLEXPYARRAYTEMPLATECHAR\\\\\n\t\tcase PyArray_UBYTE: *(unsigned char *)(arr->data)=(*v).r; break;\\\\\n\t\tcase PyArray_SBYTE: *(signed char *)(arr->data)=(*v).r; break;\\\\\n TRYCOMPLEXPYARRAYTEMPLATEOBJECT\\\\\n\t\tdefault: return -2;\\\\\n\t};\\\\\n\treturn -1;\n#elif defined(NDARRAY_VERSION)\n#define TRYCOMPLEXPYARRAYTEMPLATE(ctype,typecode)\\\\\n\tPyArrayObject *arr = NULL;\\\\\n\tif (!obj) return -2;\\\\\n\tif (!PyArray_Check(obj)) return -1;\\\\\n if (!(arr=(PyArrayObject *)obj)) {fprintf(stderr,\\\"TRYCOMPLEXPYARRAYTEMPLATE:\\\");PRINTPYOBJERR(obj);return 0;}\\\\\n\tif (arr->descr->type==typecode) {\\\\\n *(ctype *)(arr->data)=(*v).r;\\\\\n *(ctype *)(arr->data+sizeof(ctype))=(*v).i;\\\\\n return 1;\\\\\n }\\\\\n\tswitch (arr->descr->type_num) {\\\\\n\t\tcase PyArray_CDOUBLE: *(double *)(arr->data)=(*v).r;*(double *)(arr->data+sizeof(double))=(*v).i;break;\\\\\n\t\tcase PyArray_CFLOAT: *(float *)(arr->data)=(*v).r;*(float *)(arr->data+sizeof(float))=(*v).i;break;\\\\\n\t\tcase PyArray_DOUBLE: *(double *)(arr->data)=(*v).r; break;\\\\\n TRYCOMPLEXPYARRAYTEMPLATELONG\\\\\n\t\tcase PyArray_FLOAT: *(float *)(arr->data)=(*v).r; break;\\\\\n\t\tcase PyArray_INT: *(int *)(arr->data)=(*v).r; break;\\\\\n\t\tcase PyArray_SHORT: *(short *)(arr->data)=(*v).r; break;\\\\\n TRYCOMPLEXPYARRAYTEMPLATECHAR\\\\\n\t\tcase PyArray_UBYTE: *(unsigned char *)(arr->data)=(*v).r; break;\\\\\n\t\tcase PyArray_SBYTE: *(signed char *)(arr->data)=(*v).r; break;\\\\\n case PyArray_OBJECT: (arr->descr->setitem)(pyobj_from_complex_ ## ctype ## 1((*v)),arr->data, arr); break;\\\\\n\t\tdefault: return -2;\\\\\n\t};\\\\\n\treturn -1; \n#else \n#define TRYCOMPLEXPYARRAYTEMPLATE(ctype,typecode)\\\\\n\tPyArrayObject *arr = NULL;\\\\\n\tif (!obj) return -2;\\\\\n\tif (!PyArray_Check(obj)) return -1;\\\\\n if (!(arr=(PyArrayObject *)obj)) {fprintf(stderr,\\\"TRYCOMPLEXPYARRAYTEMPLATE:\\\");PRINTPYOBJERR(obj);return 0;}\\\\\n\tif (arr->descr->type==typecode) {\\\\\n *(ctype *)(arr->data)=(*v).r;\\\\\n *(ctype *)(arr->data+sizeof(ctype))=(*v).i;\\\\\n return 1;\\\\\n }\\\\\n\tswitch (arr->descr->type_num) {\\\\\n\t\tcase PyArray_CDOUBLE: *(double *)(arr->data)=(*v).r;*(double *)(arr->data+sizeof(double))=(*v).i;break;\\\\\n\t\tcase PyArray_CFLOAT: *(float *)(arr->data)=(*v).r;*(float *)(arr->data+sizeof(float))=(*v).i;break;\\\\\n\t\tcase PyArray_DOUBLE: *(double *)(arr->data)=(*v).r; break;\\\\\n TRYCOMPLEXPYARRAYTEMPLATELONG\\\\\n\t\tcase PyArray_FLOAT: *(float *)(arr->data)=(*v).r; break;\\\\\n\t\tcase PyArray_INT: *(int *)(arr->data)=(*v).r; break;\\\\\n\t\tcase PyArray_SHORT: *(short *)(arr->data)=(*v).r; break;\\\\\n TRYCOMPLEXPYARRAYTEMPLATECHAR\\\\\n\t\tcase PyArray_UBYTE: *(unsigned char *)(arr->data)=(*v).r; break;\\\\\n\t\tcase PyArray_SBYTE: *(signed char *)(arr->data)=(*v).r; break;\\\\\n case PyArray_OBJECT: (arr->descr->setitem)(pyobj_from_complex_ ## ctype ## 1((*v)),arr->data); break;\\\\\n\t\tdefault: return -2;\\\\\n\t};\\\\\n\treturn -1;\n#endif\n\"\"\"\n## cppmacros['NUMFROMARROBJ']=\"\"\"\\\n## #define NUMFROMARROBJ(typenum,ctype) \\\\\n## \\tif (PyArray_Check(obj)) arr = (PyArrayObject *)obj;\\\\\n## \\telse arr = (PyArrayObject *)PyArray_ContiguousFromObject(obj,typenum,0,0);\\\\\n## \\tif (arr) {\\\\\n## \\t\\tif (arr->descr->type_num==PyArray_OBJECT) {\\\\\n## \\t\\t\\tif (!ctype ## _from_pyobj(v,(arr->descr->getitem)(arr->data),\\\"\\\"))\\\\\n## \\t\\t\\tgoto capi_fail;\\\\\n## \\t\\t} else {\\\\\n## \\t\\t\\t(arr->descr->cast[typenum])(arr->data,1,(char*)v,1,1);\\\\\n## \\t\\t}\\\\\n## \\t\\tif ((PyObject *)arr != obj) { Py_DECREF(arr); }\\\\\n## \\t\\treturn 1;\\\\\n## \\t}\n## \"\"\"\n## #XXX: Note that CNUMFROMARROBJ is identical with NUMFROMARROBJ\n## cppmacros['CNUMFROMARROBJ']=\"\"\"\\\n## #define CNUMFROMARROBJ(typenum,ctype) \\\\\n## \\tif (PyArray_Check(obj)) arr = (PyArrayObject *)obj;\\\\\n## \\telse arr = (PyArrayObject *)PyArray_ContiguousFromObject(obj,typenum,0,0);\\\\\n## \\tif (arr) {\\\\\n## \\t\\tif (arr->descr->type_num==PyArray_OBJECT) {\\\\\n## \\t\\t\\tif (!ctype ## _from_pyobj(v,(arr->descr->getitem)(arr->data),\\\"\\\"))\\\\\n## \\t\\t\\tgoto capi_fail;\\\\\n## \\t\\t} else {\\\\\n## \\t\\t\\t(arr->descr->cast[typenum])((void *)(arr->data),1,(void *)(v),1,1);\\\\\n## \\t\\t}\\\\\n## \\t\\tif ((PyObject *)arr != obj) { Py_DECREF(arr); }\\\\\n## \\t\\treturn 1;\\\\\n## \\t}\n## \"\"\"\n\n\nneeds['GETSTRFROMPYTUPLE']=['STRINGCOPYN','PRINTPYOBJERR']\ncppmacros['GETSTRFROMPYTUPLE']=\"\"\"\\\n#define GETSTRFROMPYTUPLE(tuple,index,str,len) {\\\\\n\\t\\tPyObject *rv_cb_str = PyTuple_GetItem((tuple),(index));\\\\\n\\t\\tif (rv_cb_str == NULL)\\\\\n\\t\\t\\tgoto capi_fail;\\\\\n\\t\\tif (PyString_Check(rv_cb_str)) {\\\\\n\\t\\t\\tstr[len-1]='\\\\0';\\\\\n\\t\\t\\tSTRINGCOPYN((str),PyString_AS_STRING((PyStringObject*)rv_cb_str),(len));\\\\\n\\t\\t} else {\\\\\n\\t\\t\\tPRINTPYOBJERR(rv_cb_str);\\\\\n\\t\\t\\tPyErr_SetString(#modulename#_error,\\\"string object expected\\\");\\\\\n\\t\\t\\tgoto capi_fail;\\\\\n\\t\\t}\\\\\n\\t}\n\"\"\"\ncppmacros['GETSCALARFROMPYTUPLE']=\"\"\"\\\n#define GETSCALARFROMPYTUPLE(tuple,index,var,ctype,mess) {\\\\\n\\t\\tif ((capi_tmp = PyTuple_GetItem((tuple),(index)))==NULL) goto capi_fail;\\\\\n\\t\\tif (!(ctype ## _from_pyobj((var),capi_tmp,mess)))\\\\\n\\t\\t\\tgoto capi_fail;\\\\\n\\t}\n\"\"\"\n\nneeds['MEMCOPY']=['string.h']\ncppmacros['MEMCOPY']=\"\"\"\\\n#define MEMCOPY(to,from,n)\\\\\n\\tif ((memcpy(to,from,n)) == NULL) {\\\\\n\\t\\tPyErr_SetString(PyExc_MemoryError, \\\"memcpy failed\\\");\\\\\n\\t\\tgoto capi_fail;\\\\\n\\t}\n\"\"\"\ncppmacros['STRINGMALLOC']=\"\"\"\\\n#define STRINGMALLOC(str,len)\\\\\n\\tif ((str = (string)malloc(sizeof(char)*(len+1))) == NULL) {\\\\\n\\t\\tPyErr_SetString(PyExc_MemoryError, \\\"out of memory\\\");\\\\\n\\t\\tgoto capi_fail;\\\\\n\\t} else {\\\\\n\\t\\t(str)[len] = '\\\\0';\\\\\n\\t}\n\"\"\"\ncppmacros['STRINGFREE']=\"\"\"\\\n#define STRINGFREE(str)\\\\\n\\tif (!(str == NULL)) free(str);\n\"\"\"\nneeds['STRINGCOPYN']=['string.h']\ncppmacros['STRINGCOPYN']=\"\"\"\\\n#define STRINGCOPYN(to,from,n)\\\\\n\\tif ((strncpy(to,from,sizeof(char)*(n))) == NULL) {\\\\\n\\t\\tPyErr_SetString(PyExc_MemoryError, \\\"strncpy failed\\\");\\\\\n\\t\\tgoto capi_fail;\\\\\n\\t} else if (strlen(to)<(n)) {\\\\\n\\t\\tmemset((to)+strlen(to), ' ', (n)-strlen(to));\\\\\n\\t} /* Padding with spaces instead of nulls. */\n\"\"\"\nneeds['STRINGCOPY']=['string.h']\ncppmacros['STRINGCOPY']=\"\"\"\\\n#define STRINGCOPY(to,from)\\\\\n\\tif ((strcpy(to,from)) == NULL) {\\\\\n\\t\\tPyErr_SetString(PyExc_MemoryError, \\\"strcpy failed\\\");\\\\\n\\t\\tgoto capi_fail;\\\\\n\\t}\n\"\"\"\ncppmacros['CHECKGENERIC']=\"\"\"\\\n#define CHECKGENERIC(check,tcheck,name) \\\\\n\\tif (!(check)) {\\\\\n\\t\\tPyErr_SetString(#modulename#_error,\\\"(\\\"tcheck\\\") failed for \\\"name);\\\\\n\\t\\t/*goto capi_fail;*/\\\\\n\\t} else \"\"\"\ncppmacros['CHECKARRAY']=\"\"\"\\\n#define CHECKARRAY(check,tcheck,name) \\\\\n\\tif (!(check)) {\\\\\n\\t\\tPyErr_SetString(#modulename#_error,\\\"(\\\"tcheck\\\") failed for \\\"name);\\\\\n\\t\\t/*goto capi_fail;*/\\\\\n\\t} else \"\"\"\ncppmacros['CHECKSTRING']=\"\"\"\\\n#define CHECKSTRING(check,tcheck,name,show,var)\\\\\n\\tif (!(check)) {\\\\\n\\t\\tPyErr_SetString(#modulename#_error,\\\"(\\\"tcheck\\\") failed for \\\"name);\\\\\n\\t\\tfprintf(stderr,show\\\"\\\\n\\\",slen(var),var);\\\\\n\\t\\t/*goto capi_fail;*/\\\\\n\\t} else \"\"\"\ncppmacros['CHECKSCALAR']=\"\"\"\\\n#define CHECKSCALAR(check,tcheck,name,show,var)\\\\\n\\tif (!(check)) {\\\\\n\\t\\tPyErr_SetString(#modulename#_error,\\\"(\\\"tcheck\\\") failed for \\\"name);\\\\\n\\t\\tfprintf(stderr,show\\\"\\\\n\\\",var);\\\\\n\\t\\t/*goto capi_fail;*/\\\\\n\\t} else \"\"\"\n## cppmacros['CHECKDIMS']=\"\"\"\\\n## #define CHECKDIMS(dims,rank) \\\\\n## \\tfor (int i=0;i<(rank);i++)\\\\\n## \\t\\tif (dims[i]<0) {\\\\\n## \\t\\t\\tfprintf(stderr,\\\"Unspecified array argument requires a complete dimension specification.\\\\n\\\");\\\\\n## \\t\\t\\tgoto capi_fail;\\\\\n## \\t\\t}\n## \"\"\"\ncppmacros['ARRSIZE']='#define ARRSIZE(dims,rank) (_PyArray_multiply_list(dims,rank))'\ncppmacros['OLDPYNUM']=\"\"\"\\\n#ifdef OLDPYNUM\n#error You need to intall Numeric Python version 13 or higher. Get it from http:/sourceforge.net/project/?group_id=1369\n#endif\n\"\"\"\n################# C functions ###############\n\ncfuncs['calcarrindex']=\"\"\"\\\nstatic int calcarrindex(int *i,PyArrayObject *arr) {\n\\tint k,ii = i[0];\n\\tfor (k=1; k < arr->nd; k++)\n\\t\\tii += (ii*(arr->dimensions[k] - 1)+i[k]); /* assuming contiguous arr */\n\\treturn ii;\n}\"\"\"\ncfuncs['calcarrindextr']=\"\"\"\\\nstatic int calcarrindextr(int *i,PyArrayObject *arr) {\n\\tint k,ii = i[arr->nd-1];\n\\tfor (k=1; k < arr->nd; k++)\n\\t\\tii += (ii*(arr->dimensions[arr->nd-k-1] - 1)+i[arr->nd-k-1]); /* assuming contiguous arr */\n\\treturn ii;\n}\"\"\"\ncfuncs['forcomb']=\"\"\"\\\nstatic struct { int nd;intp *d;int *i,*i_tr,tr; } forcombcache;\nstatic int initforcomb(intp *dims,int nd,int tr) {\n int k;\n if (dims==NULL) return 0;\n if (nd<0) return 0;\n forcombcache.nd = nd;\n forcombcache.d = dims;\n forcombcache.tr = tr;\n if ((forcombcache.i = (int *)malloc(sizeof(int)*nd))==NULL) return 0;\n if ((forcombcache.i_tr = (int *)malloc(sizeof(int)*nd))==NULL) return 0;\n for (k=1;kdata,str,PyArray_SIZE(arr)); }\n\\treturn 1;\ncapi_fail:\n\\tPRINTPYOBJERR(obj);\n\\tPyErr_SetString(#modulename#_error,\\\"try_pyarr_from_string failed\\\");\n\\treturn 0;\n}\n\"\"\"\nneeds['string_from_pyobj']=['string','STRINGMALLOC','STRINGCOPYN']\ncfuncs['string_from_pyobj']=\"\"\"\\\nstatic int string_from_pyobj(string *str,int *len,const string inistr,PyObject *obj,const char *errmess) {\n\\tPyArrayObject *arr = NULL;\n\\tPyObject *tmp = NULL;\n#ifdef DEBUGCFUNCS\nfprintf(stderr,\\\"string_from_pyobj(str='%s',len=%d,inistr='%s',obj=%p)\\\\n\\\",(char*)str,*len,(char *)inistr,obj);\n#endif\n\\tif (obj == Py_None) {\n\\t\\tif (*len == -1)\n\\t\\t\\t*len = strlen(inistr); /* Will this cause problems? */\n\\t\\tSTRINGMALLOC(*str,*len);\n\\t\\tSTRINGCOPYN(*str,inistr,*len);\n\\t\\treturn 1;\n\\t}\n\\tif (PyArray_Check(obj)) {\n\\t\\tif ((arr = (PyArrayObject *)obj) == NULL)\n\\t\\t\\tgoto capi_fail;\n\\t\\tif (!ISCONTIGUOUS(arr)) {\n\\t\\t\\tPyErr_SetString(PyExc_ValueError,\\\"array object is non-contiguous.\\\");\n\\t\\t\\tgoto capi_fail;\n\\t\\t}\n\\t\\tif (*len == -1)\n\\t\\t\\t*len = (arr->itemsize)*PyArray_SIZE(arr);\n\\t\\tSTRINGMALLOC(*str,*len);\n\\t\\tSTRINGCOPYN(*str,arr->data,*len);\n\\t\\treturn 1;\n\\t}\n\\tif (PyString_Check(obj)) {\n\\t\\ttmp = obj;\n\\t\\tPy_INCREF(tmp);\n\\t}\n\\telse\n\\t\\ttmp = PyObject_Str(obj);\n\\tif (tmp == NULL) goto capi_fail;\n\\tif (*len == -1)\n\\t\\t*len = PyString_GET_SIZE(tmp);\n\\tSTRINGMALLOC(*str,*len);\n\\tSTRINGCOPYN(*str,PyString_AS_STRING(tmp),*len);\n\\tPy_DECREF(tmp);\n\\treturn 1;\ncapi_fail:\n\\tPy_XDECREF(tmp);\n\\t{\n\\t\\tPyObject* err = PyErr_Occurred();\n\\t\\tif (err==NULL) err = #modulename#_error;\n\\t\\tPyErr_SetString(err,errmess);\n\\t}\n\\treturn 0;\n}\n\"\"\"\nneeds['char_from_pyobj']=['int_from_pyobj']\ncfuncs['char_from_pyobj']=\"\"\"\\\nstatic int char_from_pyobj(char* v,PyObject *obj,const char *errmess) {\n\\tint i=0;\n\\tif (int_from_pyobj(&i,obj,errmess)) {\n\\t\\t*v = (char)i;\n\\t\\treturn 1;\n\\t}\n\\treturn 0;\n}\n\"\"\"\nneeds['signed_char_from_pyobj']=['int_from_pyobj','signed_char']\ncfuncs['signed_char_from_pyobj']=\"\"\"\\\nstatic int signed_char_from_pyobj(signed_char* v,PyObject *obj,const char *errmess) {\n\\tint i=0;\n\\tif (int_from_pyobj(&i,obj,errmess)) {\n\\t\\t*v = (signed_char)i;\n\\t\\treturn 1;\n\\t}\n\\treturn 0;\n}\n\"\"\"\nneeds['short_from_pyobj']=['int_from_pyobj']\ncfuncs['short_from_pyobj']=\"\"\"\\\nstatic int short_from_pyobj(short* v,PyObject *obj,const char *errmess) {\n\\tint i=0;\n\\tif (int_from_pyobj(&i,obj,errmess)) {\n\\t\\t*v = (short)i;\n\\t\\treturn 1;\n\\t}\n\\treturn 0;\n}\n\"\"\"\ncfuncs['int_from_pyobj']=\"\"\"\\\nstatic int int_from_pyobj(int* v,PyObject *obj,const char *errmess) {\n\\tPyObject* tmp = NULL;\n\\tif (PyInt_Check(obj)) {\n\\t\\t*v = (int)PyInt_AS_LONG(obj);\n\\t\\treturn 1;\n\\t}\n\\ttmp = PyNumber_Int(obj);\n\\tif (tmp) {\n\\t\\t*v = PyInt_AS_LONG(tmp);\n\\t\\tPy_DECREF(tmp);\n\\t\\treturn 1;\n\\t}\n\\tif (PyComplex_Check(obj))\n\\t\\ttmp = PyObject_GetAttrString(obj,\\\"real\\\");\n\\telse if (PyString_Check(obj))\n\\t\\t/*pass*/;\n\\telse if (PySequence_Check(obj))\n\\t\\ttmp = PySequence_GetItem(obj,0);\n\\tif (tmp) {\n\\t\\tPyErr_Clear();\n\\t\\tif (int_from_pyobj(v,tmp,errmess)) {Py_DECREF(tmp); return 1;}\n\\t\\tPy_DECREF(tmp);\n\\t}\n\\t{\n\\t\\tPyObject* err = PyErr_Occurred();\n\\t\\tif (err==NULL) err = #modulename#_error;\n\\t\\tPyErr_SetString(err,errmess);\n\\t}\n\\treturn 0;\n}\n\"\"\"\ncfuncs['long_from_pyobj']=\"\"\"\\\nstatic int long_from_pyobj(long* v,PyObject *obj,const char *errmess) {\n\\tPyObject* tmp = NULL;\n\\tif (PyInt_Check(obj)) {\n\\t\\t*v = PyInt_AS_LONG(obj);\n\\t\\treturn 1;\n\\t}\n\\ttmp = PyNumber_Int(obj);\n\\tif (tmp) {\n\\t\\t*v = PyInt_AS_LONG(tmp);\n\\t\\tPy_DECREF(tmp);\n\\t\\treturn 1;\n\\t}\n\\tif (PyComplex_Check(obj))\n\\t\\ttmp = PyObject_GetAttrString(obj,\\\"real\\\");\n\\telse if (PyString_Check(obj))\n\\t\\t/*pass*/;\n\\telse if (PySequence_Check(obj))\n\\t\\ttmp = PySequence_GetItem(obj,0);\n\\tif (tmp) {\n\\t\\tPyErr_Clear();\n\\t\\tif (long_from_pyobj(v,tmp,errmess)) {Py_DECREF(tmp); return 1;}\n\\t\\tPy_DECREF(tmp);\n\\t}\n\\t{\n\\t\\tPyObject* err = PyErr_Occurred();\n\\t\\tif (err==NULL) err = #modulename#_error;\n\\t\\tPyErr_SetString(err,errmess);\n\\t}\n\\treturn 0;\n}\n\"\"\"\nneeds['long_long_from_pyobj']=['long_long']\ncfuncs['long_long_from_pyobj']=\"\"\"\\\nstatic int long_long_from_pyobj(long_long* v,PyObject *obj,const char *errmess) {\n\\tPyObject* tmp = NULL;\n\\tif (PyLong_Check(obj)) {\n\\t\\t*v = PyLong_AsLongLong(obj);\n\\t\\treturn (!PyErr_Occurred());\n\\t}\n\\tif (PyInt_Check(obj)) {\n\\t\\t*v = (long_long)PyInt_AS_LONG(obj);\n\\t\\treturn 1;\n\\t}\n\\ttmp = PyNumber_Long(obj);\n\\tif (tmp) {\n\\t\\t*v = PyLong_AsLongLong(tmp);\n\\t\\tPy_DECREF(tmp);\n\\t\\treturn (!PyErr_Occurred());\n\\t}\n\\tif (PyComplex_Check(obj))\n\\t\\ttmp = PyObject_GetAttrString(obj,\\\"real\\\");\n\\telse if (PyString_Check(obj))\n\\t\\t/*pass*/;\n\\telse if (PySequence_Check(obj))\n\\t\\ttmp = PySequence_GetItem(obj,0);\n\\tif (tmp) {\n\\t\\tPyErr_Clear();\n\\t\\tif (long_long_from_pyobj(v,tmp,errmess)) {Py_DECREF(tmp); return 1;}\n\\t\\tPy_DECREF(tmp);\n\\t}\n\\t{\n\\t\\tPyObject* err = PyErr_Occurred();\n\\t\\tif (err==NULL) err = #modulename#_error;\n\\t\\tPyErr_SetString(err,errmess);\n\\t}\n\\treturn 0;\n}\n\"\"\"\nneeds['long_double_from_pyobj']=['double_from_pyobj','long_double']\ncfuncs['long_double_from_pyobj']=\"\"\"\\\nstatic int long_double_from_pyobj(long_double* v,PyObject *obj,const char *errmess) {\n\\tdouble d=0;\n\\tif (PyArray_CheckScalar(obj)){\n\\t\\tif PyArray_IsScalar(obj, LongDouble) {\n\\t\\t\\tPyArray_ScalarAsCtype(obj, v);\n\\t\\t\\treturn 1;\n\\t\\t}\n\\t\\telse if (PyArray_Check(obj) && PyArray_TYPE(obj)==PyArray_LONGDOUBLE) {\n\\t\\t\\t(*v) = *((longdouble *)PyArray_DATA(obj))\n\\t\\t\\treturn 1;\n\\t\\t}\n\\t}\n\\tif (double_from_pyobj(&d,obj,errmess)) {\n\\t\\t*v = (long_double)d;\n\\t\\treturn 1;\n\\t}\n\\treturn 0;\n}\n\"\"\"\ncfuncs['double_from_pyobj']=\"\"\"\\\nstatic int double_from_pyobj(double* v,PyObject *obj,const char *errmess) {\n\\tPyObject* tmp = NULL;\n\\tif (PyFloat_Check(obj)) {\n#ifdef __sgi\n\\t\\t*v = PyFloat_AsDouble(obj);\n#else\n\\t\\t*v = PyFloat_AS_DOUBLE(obj);\n#endif\n\\t\\treturn 1;\n\\t}\n\\ttmp = PyNumber_Float(obj);\n\\tif (tmp) {\n#ifdef __sgi\n\\t\\t*v = PyFloat_AsDouble(tmp);\n#else\n\\t\\t*v = PyFloat_AS_DOUBLE(tmp);\n#endif\n\\t\\tPy_DECREF(tmp);\n\\t\\treturn 1;\n\\t}\n\\tif (PyComplex_Check(obj))\n\\t\\ttmp = PyObject_GetAttrString(obj,\\\"real\\\");\n\\telse if (PyString_Check(obj))\n\\t\\t/*pass*/;\n\\telse if (PySequence_Check(obj))\n\\t\\ttmp = PySequence_GetItem(obj,0);\n\\tif (tmp) {\n\\t\\tPyErr_Clear();\n\\t\\tif (double_from_pyobj(v,tmp,errmess)) {Py_DECREF(tmp); return 1;}\n\\t\\tPy_DECREF(tmp);\n\\t}\n\\t{\n\\t\\tPyObject* err = PyErr_Occurred();\n\\t\\tif (err==NULL) err = #modulename#_error;\n\\t\\tPyErr_SetString(err,errmess);\n\\t}\n\\treturn 0;\n}\n\"\"\"\nneeds['float_from_pyobj']=['double_from_pyobj']\ncfuncs['float_from_pyobj']=\"\"\"\\\nstatic int float_from_pyobj(float* v,PyObject *obj,const char *errmess) {\n\\tdouble d=0.0;\n\\tif (double_from_pyobj(&d,obj,errmess)) {\n\\t\\t*v = (float)d;\n\\t\\treturn 1;\n\\t}\n\\treturn 0;\n}\n\"\"\"\nneeds['complex_long_double_from_pyobj']=['complex_long_double','long_double',\n 'complex_double_from_pyobj']\ncfuncs['complex_long_double_from_pyobj']=\"\"\"\\\nstatic int complex_long_double_from_pyobj(complex_long_double* v,PyObject *obj,const char *errmess) {\n\\tcomplex_double cd={0.0,0.0};\n\\tif (PyArray_CheckScalar(obj)){\n\\t\\tif PyArray_IsScalar(obj, CLongDouble) {\n\\t\\t\\tPyArray_ScalarAsCtype(obj, v);\n\\t\\t\\treturn 1;\n\\t\\t}\n\\t\\telse if (PyArray_Check(obj) && PyArray_TYPE(obj)==PyArray_CLONGDOUBLE) {\n\\t\\t\\t(*v).r = ((clongdouble *)PyArray_DATA(obj))->real;\n\\t\\t\\t(*v).i = ((clongdouble *)PyArray_DATA(obj))->imag;\n\\t\\t\\treturn 1;\n\\t\\t}\n\\t}\n\\tif (complex_double_from_pyobj(&cd,obj,errmess)) {\n\\t\\t(*v).r = (long_double)cd.r;\n\\t\\t(*v).i = (long_double)cd.i;\n\\t\\treturn 1;\n\\t}\n\\treturn 0;\n}\n\"\"\"\nneeds['complex_double_from_pyobj']=['complex_double']\ncfuncs['complex_double_from_pyobj']=\"\"\"\\\nstatic int complex_double_from_pyobj(complex_double* v,PyObject *obj,const char *errmess) {\n\\tPy_complex c;\n\\tif (PyComplex_Check(obj)) {\n\\t\\tc=PyComplex_AsCComplex(obj);\n\\t\\t(*v).r=c.real, (*v).i=c.imag;\n\\t\\treturn 1;\n\\t}\n\\tif (PyArray_IsScalar(obj, ComplexFloating)) {\n\\t\\tif (PyArray_IsScalar(obj, CFloat)) {\n\\t\\t\\tcfloat new;\n\\t\\t\\tPyArray_ScalarAsCtype(obj, &new);\n\\t\\t\\t(*v).r = (double)new.real;\n\\t\\t\\t(*v).i = (double)new.imag;\n\\t\\t}\n\\t\\telse if (PyArray_IsScalar(obj, CLongDouble)) {\n\\t\\t\\tclongdouble new;\n\\t\\t\\tPyArray_ScalarAsCtype(obj, &new);\n\\t\\t\\t(*v).r = (double)new.real;\n\\t\\t\\t(*v).i = (double)new.imag;\n\\t\\t}\n\\t\\telse { /* if (PyArray_IsScalar(obj, CDouble)) */\n\\t\\t\\tPyArray_ScalarAsCtype(obj, v);\n\\t\\t}\n\\t\\treturn 1;\n\\t}\n\\tif (PyArray_CheckScalar(obj)) { /* 0-dim array or still array scalar */\n\\t\\tPyObject *arr;\n\\t\\tPyArray_Typecode otype = {PyArray_CDOUBLE, sizeof(cdouble), 0};\n\\t\\tif (PyArray_Check(obj)) {\n\\t\\t\\tarr = PyArray_CastToType((PyArrayObject *)obj, &otype);\n\\t\\t}\n\\t\\telse {\n\\t\\t\\tarr = PyArray_FromScalar(obj, &otype);\n\\t\\t}\n\\t\\tif (arr==NULL) return 0;\n\\t\\t(*v).r = ((cdouble *)PyArray_DATA(arr))->real;\n\\t\\t(*v).i = ((cdouble *)PyArray_DATA(arr))->imag;\n\\t\\treturn 1;\n\\t}\n\\t/* Python does not provide PyNumber_Complex function :-( */\n\\t(*v).i=0.0;\n\\tif (PyFloat_Check(obj)) {\n#ifdef __sgi\n\\t\\t(*v).r = PyFloat_AsDouble(obj);\n#else\n\\t\\t(*v).r = PyFloat_AS_DOUBLE(obj);\n#endif\n\\t\\treturn 1;\n\\t}\n\\tif (PyInt_Check(obj)) {\n\\t\\t(*v).r = (double)PyInt_AS_LONG(obj);\n\\t\\treturn 1;\n\\t}\n\\tif (PyLong_Check(obj)) {\n\\t\\t(*v).r = PyLong_AsDouble(obj);\n\\t\\treturn (!PyErr_Occurred());\n\\t}\n\\tif (PySequence_Check(obj) && (!PyString_Check(obj))) {\n\\t\\tPyObject *tmp = PySequence_GetItem(obj,0);\n\\t\\tif (tmp) {\n\\t\\t\\tif (complex_double_from_pyobj(v,tmp,errmess)) {\n\\t\\t\\t\\tPy_DECREF(tmp);\n\\t\\t\\t\\treturn 1;\n\\t\\t\\t}\n\\t\\t\\tPy_DECREF(tmp);\n\\t\\t}\n\\t}\n\\t{\n\\t\\tPyObject* err = PyErr_Occurred();\n\\t\\tif (err==NULL)\n\\t\\t\\terr = PyExc_TypeError;\n\\t\\tPyErr_SetString(err,errmess);\n\\t}\n\\treturn 0;\n}\n\"\"\"\nneeds['complex_float_from_pyobj']=['complex_float','complex_double_from_pyobj']\ncfuncs['complex_float_from_pyobj']=\"\"\"\\\nstatic int complex_float_from_pyobj(complex_float* v,PyObject *obj,const char *errmess) {\n\\tcomplex_double cd={0.0,0.0};\n\\tif (complex_double_from_pyobj(&cd,obj,errmess)) {\n\\t\\t(*v).r = (float)cd.r;\n\\t\\t(*v).i = (float)cd.i;\n\\t\\treturn 1;\n\\t}\n\\treturn 0;\n}\n\"\"\"\nneeds['try_pyarr_from_char']=['pyobj_from_char1','TRYPYARRAYTEMPLATE']\ncfuncs['try_pyarr_from_char']='static int try_pyarr_from_char(PyObject* obj,char* v) {\\n\\tTRYPYARRAYTEMPLATE(char,\\'c\\');\\n}\\n'\nneeds['try_pyarr_from_signed_char']=['TRYPYARRAYTEMPLATE','unsigned_char']\ncfuncs['try_pyarr_from_unsigned_char']='static int try_pyarr_from_unsigned_char(PyObject* obj,unsigned_char* v) {\\n\\tTRYPYARRAYTEMPLATE(unsigned_char,\\'b\\');\\n}\\n'\nneeds['try_pyarr_from_signed_char']=['TRYPYARRAYTEMPLATE','signed_char']\ncfuncs['try_pyarr_from_signed_char']='static int try_pyarr_from_signed_char(PyObject* obj,signed_char* v) {\\n\\tTRYPYARRAYTEMPLATE(signed_char,\\'1\\');\\n}\\n'\nneeds['try_pyarr_from_short']=['pyobj_from_short1','TRYPYARRAYTEMPLATE']\ncfuncs['try_pyarr_from_short']='static int try_pyarr_from_short(PyObject* obj,short* v) {\\n\\tTRYPYARRAYTEMPLATE(short,\\'s\\');\\n}\\n'\nneeds['try_pyarr_from_int']=['pyobj_from_int1','TRYPYARRAYTEMPLATE']\ncfuncs['try_pyarr_from_int']='static int try_pyarr_from_int(PyObject* obj,int* v) {\\n\\tTRYPYARRAYTEMPLATE(int,\\'i\\');\\n}\\n'\nneeds['try_pyarr_from_long']=['pyobj_from_long1','TRYPYARRAYTEMPLATE']\ncfuncs['try_pyarr_from_long']='static int try_pyarr_from_long(PyObject* obj,long* v) {\\n\\tTRYPYARRAYTEMPLATE(long,\\'l\\');\\n}\\n'\nneeds['try_pyarr_from_long_long']=['pyobj_from_long_long1','TRYPYARRAYTEMPLATE','long_long']\ncfuncs['try_pyarr_from_long_long']='static int try_pyarr_from_long_long(PyObject* obj,long_long* v) {\\n\\tTRYPYARRAYTEMPLATE(long_long,\\'L\\');\\n}\\n'\nneeds['try_pyarr_from_float']=['pyobj_from_float1','TRYPYARRAYTEMPLATE']\ncfuncs['try_pyarr_from_float']='static int try_pyarr_from_float(PyObject* obj,float* v) {\\n\\tTRYPYARRAYTEMPLATE(float,\\'f\\');\\n}\\n'\nneeds['try_pyarr_from_double']=['pyobj_from_double1','TRYPYARRAYTEMPLATE']\ncfuncs['try_pyarr_from_double']='static int try_pyarr_from_double(PyObject* obj,double* v) {\\n\\tTRYPYARRAYTEMPLATE(double,\\'d\\');\\n}\\n'\nneeds['try_pyarr_from_complex_float']=['pyobj_from_complex_float1','TRYCOMPLEXPYARRAYTEMPLATE','complex_float']\ncfuncs['try_pyarr_from_complex_float']='static int try_pyarr_from_complex_float(PyObject* obj,complex_float* v) {\\n\\tTRYCOMPLEXPYARRAYTEMPLATE(float,\\'F\\');\\n}\\n'\nneeds['try_pyarr_from_complex_double']=['pyobj_from_complex_double1','TRYCOMPLEXPYARRAYTEMPLATE','complex_double']\ncfuncs['try_pyarr_from_complex_double']='static int try_pyarr_from_complex_double(PyObject* obj,complex_double* v) {\\n\\tTRYCOMPLEXPYARRAYTEMPLATE(double,\\'D\\');\\n}\\n'\n\nneeds['create_cb_arglist']=['CFUNCSMESS','PRINTPYOBJERR','MINMAX']\ncfuncs['create_cb_arglist']=\"\"\"\\\nstatic int create_cb_arglist(PyObject* fun,PyTupleObject* xa,const int maxnofargs,const int nofoptargs,int *nofargs,PyTupleObject **args,const char *errmess) {\n\\tPyObject *tmp = NULL;\n\\tPyObject *tmp_fun = NULL;\n\\tint tot,opt,ext,siz,i,di=0;\n\\tCFUNCSMESS(\\\"create_cb_arglist\\\\n\\\");\n\\ttot=opt=ext=siz=0;\n\\t/* Get the total number of arguments */\n\\tif (PyFunction_Check(fun))\n\\t\\ttmp_fun = fun;\n\\telse {\n\\t\\tdi = 1;\n\\t\\tif (PyObject_HasAttrString(fun,\\\"im_func\\\")) {\n\\t\\t\\ttmp_fun = PyObject_GetAttrString(fun,\\\"im_func\\\");\n\\t\\t}\n\\t\\telse if (PyObject_HasAttrString(fun,\\\"__call__\\\")) {\n\\t\\t\\ttmp = PyObject_GetAttrString(fun,\\\"__call__\\\");\n\\t\\t\\tif (PyObject_HasAttrString(tmp,\\\"im_func\\\"))\n\\t\\t\\t\\ttmp_fun = PyObject_GetAttrString(tmp,\\\"im_func\\\");\n\\t\\t\\telse {\n\\t\\t\\t\\ttmp_fun = fun; /* built-in function */\n\\t\\t\\t\\ttot = maxnofargs;\n\\t\\t\\t\\tif (xa != NULL)\n\\t\\t\\t\\t\\ttot += PyTuple_Size((PyObject *)xa);\n\\t\\t\\t}\n\\t\\t\\tPy_XDECREF(tmp);\n\\t\\t}\n\\t\\telse if (PyFortran_Check(fun) || PyFortran_Check1(fun)) {\n\\t\\t\\ttot = maxnofargs;\n\\t\\t\\tif (xa != NULL)\n\\t\\t\\t\\ttot += PyTuple_Size((PyObject *)xa);\n\\t\\t\\ttmp_fun = fun;\n\\t\\t}\n\\t\\telse if (PyCObject_Check(fun)) {\n\\t\\t\\ttot = maxnofargs;\n\\t\\t\\tif (xa != NULL)\n\\t\\t\\t\\text = PyTuple_Size((PyObject *)xa);\n\\t\\t\\tif(ext>0) {\n\\t\\t\\t\\tfprintf(stderr,\\\"extra arguments tuple cannot be used with CObject call-back\\\\n\\\");\n\\t\\t\\t\\tgoto capi_fail;\n\\t\\t\\t}\n\\t\\t\\ttmp_fun = fun;\n\\t\\t}\n\\t}\nif (tmp_fun==NULL) {\nfprintf(stderr,\\\"Call-back argument must be function|instance|instance.__call__|f2py-function but got %s.\\\\n\\\",(fun==NULL?\\\"NULL\\\":fun->ob_type->tp_name));\ngoto capi_fail;\n}\n\\tif (PyObject_HasAttrString(tmp_fun,\\\"func_code\\\")) {\n\\t\\tif (PyObject_HasAttrString(tmp = PyObject_GetAttrString(tmp_fun,\\\"func_code\\\"),\\\"co_argcount\\\"))\n\\t\\t\\ttot = PyInt_AsLong(PyObject_GetAttrString(tmp,\\\"co_argcount\\\")) - di;\n\\t\\tPy_XDECREF(tmp);\n\\t}\n\\t/* Get the number of optional arguments */\n\\tif (PyObject_HasAttrString(tmp_fun,\\\"func_defaults\\\"))\n\\t\\tif (PyTuple_Check(tmp = PyObject_GetAttrString(tmp_fun,\\\"func_defaults\\\")))\n\\t\\t\\topt = PyTuple_Size(tmp);\n\\t\\tPy_XDECREF(tmp);\n\\t/* Get the number of extra arguments */\n\\tif (xa != NULL)\n\\t\\text = PyTuple_Size((PyObject *)xa);\n\\t/* Calculate the size of call-backs argument list */\n\\tsiz = MIN(maxnofargs+ext,tot);\n\\t*nofargs = MAX(0,siz-ext);\n#ifdef DEBUGCFUNCS\n\\tfprintf(stderr,\\\"debug-capi:create_cb_arglist:maxnofargs(-nofoptargs),tot,opt,ext,siz,nofargs=%d(-%d),%d,%d,%d,%d,%d\\\\n\\\",maxnofargs,nofoptargs,tot,opt,ext,siz,*nofargs);\n#endif\n\\tif (siz0:\n if not needs.has_key(outneeds[n][0]):\n out.append(outneeds[n][0])\n del outneeds[n][0]\n else:\n flag=0\n for k in outneeds[n][1:]:\n if k in needs[outneeds[n][0]]:\n flag=1\n break\n if flag:\n outneeds[n]=outneeds[n][1:]+[outneeds[n][0]]\n else:\n out.append(outneeds[n][0])\n del outneeds[n][0]\n if saveout and (0 not in map(lambda x,y:x==y,saveout,outneeds[n])):\n print n,saveout\n errmess('get_needs: no progress in sorting needs, probably circular dependence, skipping.\\n')\n out=out+saveout\n break\n saveout=copy.copy(outneeds[n])\n if out==[]: out=[n]\n res[n]=out\n return res\n", "source_code_before": "#!/usr/bin/env python\n\"\"\"\n\nC declarations, CPP macros, and C functions for f2py2e.\nOnly required declarations/macros/functions will be used.\n\nCopyright 1999,2000 Pearu Peterson all rights reserved,\nPearu Peterson \nPermission to use, modify, and distribute this software is given under the\nterms of the LGPL. See http://www.fsf.org\n\nNO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n$Date: 2005/05/06 11:42:34 $\nPearu Peterson\n\"\"\"\n\n__version__ = \"$Revision: 1.75 $\"[10:-1]\n\nimport __version__\nf2py_version = __version__.version\n\nimport types,sys,copy,os\nerrmess=sys.stderr.write\n\n##################### Definitions ##################\n\noutneeds={'includes0':[],'includes':[],'typedefs':[],'typedefs_generated':[],\n 'userincludes':[],\n 'cppmacros':[],'cfuncs':[],'callbacks':[],'f90modhooks':[],\n 'commonhooks':[]}\nneeds={}\nincludes0={'includes0':'/*need_includes0*/'}\nincludes={'includes':'/*need_includes*/'}\nuserincludes={'userincludes':'/*need_userincludes*/'}\ntypedefs={'typedefs':'/*need_typedefs*/'}\ntypedefs_generated={'typedefs_generated':'/*need_typedefs_generated*/'}\ncppmacros={'cppmacros':'/*need_cppmacros*/'}\ncfuncs={'cfuncs':'/*need_cfuncs*/'}\ncallbacks={'callbacks':'/*need_callbacks*/'}\nf90modhooks={'f90modhooks':'/*need_f90modhooks*/',\n 'initf90modhooksstatic':'/*initf90modhooksstatic*/',\n 'initf90modhooksdynamic':'/*initf90modhooksdynamic*/',\n }\ncommonhooks={'commonhooks':'/*need_commonhooks*/',\n 'initcommonhooks':'/*need_initcommonhooks*/',\n }\n\n############ Includes ###################\n\nincludes0['math.h']='#include '\nincludes0['string.h']='#include '\nincludes0['setjmp.h']='#include '\n\nincludes['Python.h']='#include \"Python.h\"'\nneeds['arrayobject.h']=['Python.h']\nincludes['arrayobject.h']='''#define PY_ARRAY_UNIQUE_SYMBOL PyArray_API\n#include \"arrayobject.h\"'''\n\nincludes['arrayobject.h']='#include \"fortranobject.h\"'\n\n############# Type definitions ###############\n\ntypedefs['unsigned_char']='typedef unsigned char unsigned_char;'\ntypedefs['unsigned_short']='typedef unsigned short unsigned_short;'\ntypedefs['unsigned_long']='typedef unsigned long unsigned_long;'\ntypedefs['signed_char']='typedef signed char signed_char;'\ntypedefs['long_long']=\"\"\"\\\n#ifdef _WIN32\ntypedef __int64 long_long;\n#else\ntypedef long long long_long;\ntypedef unsigned long long unsigned_long_long;\n#endif\n\"\"\"\ntypedefs['insinged_long_long']=\"\"\"\\\n#ifdef _WIN32\ntypedef __uint64 long_long;\n#else\ntypedef unsigned long long unsigned_long_long;\n#endif\n\"\"\"\ntypedefs['long_double']=\"\"\"\\\n#ifndef _LONG_DOUBLE\ntypedef long double long_double;\n#endif\n\"\"\"\ntypedefs['complex_long_double']='typedef struct {long double r,i;} complex_long_double;'\ntypedefs['complex_float']='typedef struct {float r,i;} complex_float;'\ntypedefs['complex_double']='typedef struct {double r,i;} complex_double;'\ntypedefs['string']=\"\"\"typedef char * string;\"\"\"\n\n\n############### CPP macros ####################\ncppmacros['CFUNCSMESS']=\"\"\"\\\n#ifdef DEBUGCFUNCS\n#define CFUNCSMESS(mess) fprintf(stderr,\\\"debug-capi:\\\"mess);\n#define CFUNCSMESSPY(mess,obj) CFUNCSMESS(mess) \\\\\n\\tPyObject_Print((PyObject *)obj,stderr,Py_PRINT_RAW);\\\\\n\\tfprintf(stderr,\\\"\\\\n\\\");\n#else\n#define CFUNCSMESS(mess)\n#define CFUNCSMESSPY(mess,obj)\n#endif\n\"\"\"\ncppmacros['F_FUNC']=\"\"\"\\\n#if defined(PREPEND_FORTRAN)\n#if defined(NO_APPEND_FORTRAN)\n#if defined(UPPERCASE_FORTRAN)\n#define F_FUNC(f,F) _##F\n#else\n#define F_FUNC(f,F) _##f\n#endif\n#else\n#if defined(UPPERCASE_FORTRAN)\n#define F_FUNC(f,F) _##F##_\n#else\n#define F_FUNC(f,F) _##f##_\n#endif\n#endif\n#else\n#if defined(NO_APPEND_FORTRAN)\n#if defined(UPPERCASE_FORTRAN)\n#define F_FUNC(f,F) F\n#else\n#define F_FUNC(f,F) f\n#endif\n#else\n#if defined(UPPERCASE_FORTRAN)\n#define F_FUNC(f,F) F##_\n#else\n#define F_FUNC(f,F) f##_\n#endif\n#endif\n#endif\n#if defined(UNDERSCORE_G77)\n#define F_FUNC_US(f,F) F_FUNC(f##_,F##_)\n#else\n#define F_FUNC_US(f,F) F_FUNC(f,F)\n#endif\n\"\"\"\ncppmacros['F_WRAPPEDFUNC']=\"\"\"\\\n#if defined(PREPEND_FORTRAN)\n#if defined(NO_APPEND_FORTRAN)\n#if defined(UPPERCASE_FORTRAN)\n#define F_WRAPPEDFUNC(f,F) _F2PYWRAP##F\n#else\n#define F_WRAPPEDFUNC(f,F) _f2pywrap##f\n#endif\n#else\n#if defined(UPPERCASE_FORTRAN)\n#define F_WRAPPEDFUNC(f,F) _F2PYWRAP##F##_\n#else\n#define F_WRAPPEDFUNC(f,F) _f2pywrap##f##_\n#endif\n#endif\n#else\n#if defined(NO_APPEND_FORTRAN)\n#if defined(UPPERCASE_FORTRAN)\n#define F_WRAPPEDFUNC(f,F) F2PYWRAP##F\n#else\n#define F_WRAPPEDFUNC(f,F) f2pywrap##f\n#endif\n#else\n#if defined(UPPERCASE_FORTRAN)\n#define F_WRAPPEDFUNC(f,F) F2PYWRAP##F##_\n#else\n#define F_WRAPPEDFUNC(f,F) f2pywrap##f##_\n#endif\n#endif\n#endif\n#if defined(UNDERSCORE_G77)\n#define F_WRAPPEDFUNC_US(f,F) F_WRAPPEDFUNC(f##_,F##_)\n#else\n#define F_WRAPPEDFUNC_US(f,F) F_WRAPPEDFUNC(f,F)\n#endif\n\"\"\"\ncppmacros['F_MODFUNC']=\"\"\"\\\n#if defined(F90MOD2CCONV1) /*E.g. Compaq Fortran */\n#if defined(NO_APPEND_FORTRAN)\n#define F_MODFUNCNAME(m,f) $ ## m ## $ ## f\n#else\n#define F_MODFUNCNAME(m,f) $ ## m ## $ ## f ## _\n#endif\n#endif\n\n#if defined(F90MOD2CCONV2) /*E.g. IBM XL Fortran, not tested though */\n#if defined(NO_APPEND_FORTRAN)\n#define F_MODFUNCNAME(m,f) __ ## m ## _MOD_ ## f\n#else\n#define F_MODFUNCNAME(m,f) __ ## m ## _MOD_ ## f ## _\n#endif\n#endif\n\n#if defined(F90MOD2CCONV3) /*E.g. MIPSPro Compilers */\n#if defined(NO_APPEND_FORTRAN)\n#define F_MODFUNCNAME(m,f) f ## .in. ## m\n#else\n#define F_MODFUNCNAME(m,f) f ## .in. ## m ## _\n#endif\n#endif\n/*\n#if defined(UPPERCASE_FORTRAN)\n#define F_MODFUNC(m,M,f,F) F_MODFUNCNAME(M,F)\n#else\n#define F_MODFUNC(m,M,f,F) F_MODFUNCNAME(m,f)\n#endif\n*/\n\n#define F_MODFUNC(m,f) (*(f2pymodstruct##m##.##f))\n\"\"\"\ncppmacros['SWAPUNSAFE']=\"\"\"\\\n#define SWAP(a,b) (size_t)(a) = ((size_t)(a) ^ (size_t)(b));\\\\\n (size_t)(b) = ((size_t)(a) ^ (size_t)(b));\\\\\n (size_t)(a) = ((size_t)(a) ^ (size_t)(b))\n\"\"\"\ncppmacros['SWAP']=\"\"\"\\\n#define SWAP(a,b,t) {\\\\\n\\tt *c;\\\\\n\\tc = a;\\\\\n\\ta = b;\\\\\n\\tb = c;}\n\"\"\"\n#cppmacros['ISCONTIGUOUS']='#define ISCONTIGUOUS(m) ((m)->flags & CONTIGUOUS)'\ncppmacros['PRINTPYOBJERR']=\"\"\"\\\n#define PRINTPYOBJERR(obj)\\\\\n\\tfprintf(stderr,\\\"#modulename#.error is related to \\\");\\\\\n\\tPyObject_Print((PyObject *)obj,stderr,Py_PRINT_RAW);\\\\\n\\tfprintf(stderr,\\\"\\\\n\\\");\n\"\"\"\ncppmacros['MINMAX']=\"\"\"\\\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\"\"\"\ncppmacros['len..']=\"\"\"\\\n#define rank(var) var ## _Rank\n#define shape(var,dim) var ## _Dims[dim]\n#define old_rank(var) (((PyArrayObject *)(capi_ ## var ## _tmp))->nd)\n#define old_shape(var,dim) (((PyArrayObject *)(capi_ ## var ## _tmp))->dimensions[dim])\n#define fshape(var,dim) shape(var,rank(var)-dim-1)\n#define len(var) shape(var,0)\n#define flen(var) fshape(var,0)\n#define size(var) PyArray_SIZE((PyArrayObject *)(capi_ ## var ## _tmp))\n/* #define index(i) capi_i ## i */\n#define slen(var) capi_ ## var ## _len\n\"\"\"\n\ncppmacros['pyobj_from_char1']='#define pyobj_from_char1(v) (PyInt_FromLong(v))'\ncppmacros['pyobj_from_short1']='#define pyobj_from_short1(v) (PyInt_FromLong(v))'\nneeds['pyobj_from_int1']=['signed_char']\ncppmacros['pyobj_from_int1']='#define pyobj_from_int1(v) (PyInt_FromLong(v))'\ncppmacros['pyobj_from_long1']='#define pyobj_from_long1(v) (PyLong_FromLong(v))'\nneeds['pyobj_from_long_long1']=['long_long']\ncppmacros['pyobj_from_long_long1']=\"\"\"\\\n#ifdef HAVE_LONG_LONG\n#define pyobj_from_long_long1(v) (PyLong_FromLongLong(v))\n#else\n#warning HAVE_LONG_LONG is not available. Redefining pyobj_from_long_long.\n#define pyobj_from_long_long1(v) (PyLong_FromLong(v))\n#endif\n\"\"\"\nneeds['pyobj_from_long_double1']=['long_double']\ncppmacros['pyobj_from_long_double1']='#define pyobj_from_long_double1(v) (PyFloat_FromDouble(v))'\ncppmacros['pyobj_from_double1']='#define pyobj_from_double1(v) (PyFloat_FromDouble(v))'\ncppmacros['pyobj_from_float1']='#define pyobj_from_float1(v) (PyFloat_FromDouble(v))'\nneeds['pyobj_from_complex_long_double1']=['complex_long_double']\ncppmacros['pyobj_from_complex_long_double1']='#define pyobj_from_complex_long_double1(v) (PyComplex_FromDoubles(v.r,v.i))'\nneeds['pyobj_from_complex_double1']=['complex_double']\ncppmacros['pyobj_from_complex_double1']='#define pyobj_from_complex_double1(v) (PyComplex_FromDoubles(v.r,v.i))'\nneeds['pyobj_from_complex_float1']=['complex_float']\ncppmacros['pyobj_from_complex_float1']='#define pyobj_from_complex_float1(v) (PyComplex_FromDoubles(v.r,v.i))'\nneeds['pyobj_from_string1']=['string']\ncppmacros['pyobj_from_string1']='#define pyobj_from_string1(v) (PyString_FromString((char *)v))'\nneeds['TRYPYARRAYTEMPLATE']=['PRINTPYOBJERR']\ncppmacros['TRYPYARRAYTEMPLATE']=\"\"\"\\\n#ifdef NUMARRAY\n/* Numarray */\n\n#if defined(USE_SIGNED_CHAR)\n#define TRYPYARRAYTEMPLATECHAR case PyArray_CHAR: *(char *)(arr->data)=*v; break;\n#else\n#define TRYPYARRAYTEMPLATECHAR\n#endif\n#if LP64\n#define TRYPYARRAYTEMPLATELONG case PyArray_LONG: *(long *)(arr->data)=*v; break;\n#else\n#define TRYPYARRAYTEMPLATELONG\n#endif\n\n/* XXX: need the corresponding numarray code here */\n#define TRYPYARRAYTEMPLATEOBJECT\n\n#elif defined(NDARRAY_VERSION)\n/* New SciPy */\n#define TRYPYARRAYTEMPLATECHAR case PyArray_STRING: *(char *)(arr->data)=*v; break;\n#define TRYPYARRAYTEMPLATELONG case PyArray_LONG: *(long *)(arr->data)=*v; break;\n#define TRYPYARRAYTEMPLATEOBJECT case PyArray_OBJECT: (arr->descr->setitem)(pyobj_from_ ## ctype ## 1(*v),arr->data); break;\n#else\n/* Numeric */\n\n#define TRYPYARRAYTEMPLATECHAR case PyArray_CHAR: *(char *)(arr->data)=*v; break;\n#define TRYPYARRAYTEMPLATELONG case PyArray_LONG: *(long *)(arr->data)=*v; break;\n#define TRYPYARRAYTEMPLATEOBJECT case PyArray_OBJECT: (arr->descr->setitem)(pyobj_from_ ## ctype ## 1(*v),arr->data); break;\n\n#endif\n\n#ifdef NUMARRAY\n#define TRYPYARRAYTEMPLATE(ctype,typecode) \\\\\n\tPyArrayObject *arr = NULL;\\\\\n\tif (!obj) return -2;\\\\\n\tif (!PyArray_Check(obj)) return -1;\\\\\n\tif (!(arr=(PyArrayObject *)obj)) {fprintf(stderr,\\\"TRYPYARRAYTEMPLATE:\\\");PRINTPYOBJERR(obj);return 0;}\\\\\n\tif (arr->descr->type==typecode) {*(ctype *)(arr->data)=*v; return 1;}\\\\\n\tswitch (arr->descr->type_num) {\\\\\n TRYPYARRAYTEMPLATELONG\\\\\n\t\tcase PyArray_DOUBLE: *(double *)(arr->data)=*v; break;\\\\\n\t\tcase PyArray_INT: *(int *)(arr->data)=*v; break;\\\\\n\t\tcase PyArray_FLOAT: *(float *)(arr->data)=*v; break;\\\\\n\t\tcase PyArray_CDOUBLE: *(double *)(arr->data)=*v; break;\\\\\n\t\tcase PyArray_CFLOAT: *(float *)(arr->data)=*v; break;\\\\\n TRYPYARRAYTEMPLATECHAR\\\\\n\t\tcase PyArray_UBYTE: *(unsigned char *)(arr->data)=*v; break;\\\\\n\t\tcase PyArray_SBYTE: *(signed char *)(arr->data)=*v; break;\\\\\n\t\tcase PyArray_SHORT: *(short *)(arr->data)=*v; break;\\\\\n TRYPYARRAYTEMPLATEOBJECT\\\\\n\tdefault: return -2;\\\\\n\t};\\\\\n\treturn 1;\n#elif defined(NDARRAY_VERSION)\n#define TRYPYARRAYTEMPLATE(ctype,typecode) \\\\\n\tPyArrayObject *arr = NULL;\\\\\n\tif (!obj) return -2;\\\\\n\tif (!PyArray_Check(obj)) return -1;\\\\\n\tif (!(arr=(PyArrayObject *)obj)) {fprintf(stderr,\\\"TRYPYARRAYTEMPLATE:\\\");PRINTPYOBJERR(obj);return 0;}\\\\\n\tif (arr->descr->type==typecode) {*(ctype *)(arr->data)=*v; return 1;}\\\\\n\tswitch (arr->descr->type_num) {\\\\\n TRYPYARRAYTEMPLATELONG\\\\\n\t\tcase PyArray_DOUBLE: *(double *)(arr->data)=*v; break;\\\\\n\t\tcase PyArray_INT: *(int *)(arr->data)=*v; break;\\\\\n\t\tcase PyArray_FLOAT: *(float *)(arr->data)=*v; break;\\\\\n\t\tcase PyArray_CDOUBLE: *(double *)(arr->data)=*v; break;\\\\\n\t\tcase PyArray_CFLOAT: *(float *)(arr->data)=*v; break;\\\\\n TRYPYARRAYTEMPLATECHAR\\\\\n\t\tcase PyArray_UBYTE: *(unsigned char *)(arr->data)=*v; break;\\\\\n\t\tcase PyArray_SBYTE: *(signed char *)(arr->data)=*v; break;\\\\\n\t\tcase PyArray_SHORT: *(short *)(arr->data)=*v; break;\\\\\n case PyArray_OBJECT: (arr->descr->setitem)(pyobj_from_ ## ctype ## 1(*v),arr->data, arr); break;\\\\\n\tdefault: return -2;\\\\\n\t};\\\\\n\treturn 1;\n#else\n#define TRYPYARRAYTEMPLATE(ctype,typecode) \\\\\n\tPyArrayObject *arr = NULL;\\\\\n\tif (!obj) return -2;\\\\\n\tif (!PyArray_Check(obj)) return -1;\\\\\n\tif (!(arr=(PyArrayObject *)obj)) {fprintf(stderr,\\\"TRYPYARRAYTEMPLATE:\\\");PRINTPYOBJERR(obj);return 0;}\\\\\n\tif (arr->descr->type==typecode) {*(ctype *)(arr->data)=*v; return 1;}\\\\\n\tswitch (arr->descr->type_num) {\\\\\n TRYPYARRAYTEMPLATELONG\\\\\n\t\tcase PyArray_DOUBLE: *(double *)(arr->data)=*v; break;\\\\\n\t\tcase PyArray_INT: *(int *)(arr->data)=*v; break;\\\\\n\t\tcase PyArray_FLOAT: *(float *)(arr->data)=*v; break;\\\\\n\t\tcase PyArray_CDOUBLE: *(double *)(arr->data)=*v; break;\\\\\n\t\tcase PyArray_CFLOAT: *(float *)(arr->data)=*v; break;\\\\\n TRYPYARRAYTEMPLATECHAR\\\\\n\t\tcase PyArray_UBYTE: *(unsigned char *)(arr->data)=*v; break;\\\\\n\t\tcase PyArray_SBYTE: *(signed char *)(arr->data)=*v; break;\\\\\n\t\tcase PyArray_SHORT: *(short *)(arr->data)=*v; break;\\\\\n case PyArray_OBJECT: (arr->descr->setitem)(pyobj_from_ ## ctype ## 1(*v),arr->data); break;\\\\\n\tdefault: return -2;\\\\\n\t};\\\\\n\treturn 1;\n#endif\n\"\"\"\n\nneeds['TRYCOMPLEXPYARRAYTEMPLATE']=['PRINTPYOBJERR']\ncppmacros['TRYCOMPLEXPYARRAYTEMPLATE']=\"\"\"\\\n#if PyArray_LONG != PyArray_INT\n#define TRYCOMPLEXPYARRAYTEMPLATELONG case PyArray_LONG: *(long *)(arr->data)=(*v).r; break;\n#else\n#define TRYCOMPLEXPYARRAYTEMPLATELONG\n#endif\n#if (PyArray_UBYTE != PyArray_CHAR)\n#define TRYCOMPLEXPYARRAYTEMPLATECHAR case PyArray_CHAR: *(char *)(arr->data)=(*v).r; break;\n#else\n#define TRYCOMPLEXPYARRAYTEMPLATECHAR\n#endif\n#ifdef NUMARRAY\n/* XXX: need the corresponding numarray code here */\n#define TRYCOMPLEXPYARRAYTEMPLATEOBJECT\n#elif defined(NDARRAY_VERSION)\n#define TRYCOMPLEXPYARRAYTEMPLATEOBJECT case PyArray_OBJECT: (arr->descr->setitem)(pyobj_from_complex_ ## ctype ## 1((*v)),arr->data, arr); break;\n#else\n#define TRYCOMPLEXPYARRAYTEMPLATEOBJECT case PyArray_OBJECT: (arr->descr->setitem)(pyobj_from_complex_ ## ctype ## 1((*v)),arr->data); break;\n#endif\n\n#ifdef NUMARRAY\n#define TRYCOMPLEXPYARRAYTEMPLATE(ctype,typecode)\\\\\n\tPyArrayObject *arr = NULL;\\\\\n\tif (!obj) return -2;\\\\\n\tif (!PyArray_Check(obj)) return -1;\\\\\n if (!(arr=(PyArrayObject *)obj)) {fprintf(stderr,\\\"TRYCOMPLEXPYARRAYTEMPLATE:\\\");PRINTPYOBJERR(obj);return 0;}\\\\\n\tif (arr->descr->type==typecode) {\\\\\n *(ctype *)(arr->data)=(*v).r;\\\\\n *(ctype *)(arr->data+sizeof(ctype))=(*v).i;\\\\\n return 1;\\\\\n }\\\\\n\tswitch (arr->descr->type_num) {\\\\\n\t\tcase PyArray_CDOUBLE: *(double *)(arr->data)=(*v).r;*(double *)(arr->data+sizeof(double))=(*v).i;break;\\\\\n\t\tcase PyArray_CFLOAT: *(float *)(arr->data)=(*v).r;*(float *)(arr->data+sizeof(float))=(*v).i;break;\\\\\n\t\tcase PyArray_DOUBLE: *(double *)(arr->data)=(*v).r; break;\\\\\n TRYCOMPLEXPYARRAYTEMPLATELONG\\\\\n\t\tcase PyArray_FLOAT: *(float *)(arr->data)=(*v).r; break;\\\\\n\t\tcase PyArray_INT: *(int *)(arr->data)=(*v).r; break;\\\\\n\t\tcase PyArray_SHORT: *(short *)(arr->data)=(*v).r; break;\\\\\n TRYCOMPLEXPYARRAYTEMPLATECHAR\\\\\n\t\tcase PyArray_UBYTE: *(unsigned char *)(arr->data)=(*v).r; break;\\\\\n\t\tcase PyArray_SBYTE: *(signed char *)(arr->data)=(*v).r; break;\\\\\n TRYCOMPLEXPYARRAYTEMPLATEOBJECT\\\\\n\t\tdefault: return -2;\\\\\n\t};\\\\\n\treturn -1;\n#elif defined(NDARRAY_VERSION)\n#define TRYCOMPLEXPYARRAYTEMPLATE(ctype,typecode)\\\\\n\tPyArrayObject *arr = NULL;\\\\\n\tif (!obj) return -2;\\\\\n\tif (!PyArray_Check(obj)) return -1;\\\\\n if (!(arr=(PyArrayObject *)obj)) {fprintf(stderr,\\\"TRYCOMPLEXPYARRAYTEMPLATE:\\\");PRINTPYOBJERR(obj);return 0;}\\\\\n\tif (arr->descr->type==typecode) {\\\\\n *(ctype *)(arr->data)=(*v).r;\\\\\n *(ctype *)(arr->data+sizeof(ctype))=(*v).i;\\\\\n return 1;\\\\\n }\\\\\n\tswitch (arr->descr->type_num) {\\\\\n\t\tcase PyArray_CDOUBLE: *(double *)(arr->data)=(*v).r;*(double *)(arr->data+sizeof(double))=(*v).i;break;\\\\\n\t\tcase PyArray_CFLOAT: *(float *)(arr->data)=(*v).r;*(float *)(arr->data+sizeof(float))=(*v).i;break;\\\\\n\t\tcase PyArray_DOUBLE: *(double *)(arr->data)=(*v).r; break;\\\\\n TRYCOMPLEXPYARRAYTEMPLATELONG\\\\\n\t\tcase PyArray_FLOAT: *(float *)(arr->data)=(*v).r; break;\\\\\n\t\tcase PyArray_INT: *(int *)(arr->data)=(*v).r; break;\\\\\n\t\tcase PyArray_SHORT: *(short *)(arr->data)=(*v).r; break;\\\\\n TRYCOMPLEXPYARRAYTEMPLATECHAR\\\\\n\t\tcase PyArray_UBYTE: *(unsigned char *)(arr->data)=(*v).r; break;\\\\\n\t\tcase PyArray_SBYTE: *(signed char *)(arr->data)=(*v).r; break;\\\\\n case PyArray_OBJECT: (arr->descr->setitem)(pyobj_from_complex_ ## ctype ## 1((*v)),arr->data, arr); break;\\\\\n\t\tdefault: return -2;\\\\\n\t};\\\\\n\treturn -1; \n#else \n#define TRYCOMPLEXPYARRAYTEMPLATE(ctype,typecode)\\\\\n\tPyArrayObject *arr = NULL;\\\\\n\tif (!obj) return -2;\\\\\n\tif (!PyArray_Check(obj)) return -1;\\\\\n if (!(arr=(PyArrayObject *)obj)) {fprintf(stderr,\\\"TRYCOMPLEXPYARRAYTEMPLATE:\\\");PRINTPYOBJERR(obj);return 0;}\\\\\n\tif (arr->descr->type==typecode) {\\\\\n *(ctype *)(arr->data)=(*v).r;\\\\\n *(ctype *)(arr->data+sizeof(ctype))=(*v).i;\\\\\n return 1;\\\\\n }\\\\\n\tswitch (arr->descr->type_num) {\\\\\n\t\tcase PyArray_CDOUBLE: *(double *)(arr->data)=(*v).r;*(double *)(arr->data+sizeof(double))=(*v).i;break;\\\\\n\t\tcase PyArray_CFLOAT: *(float *)(arr->data)=(*v).r;*(float *)(arr->data+sizeof(float))=(*v).i;break;\\\\\n\t\tcase PyArray_DOUBLE: *(double *)(arr->data)=(*v).r; break;\\\\\n TRYCOMPLEXPYARRAYTEMPLATELONG\\\\\n\t\tcase PyArray_FLOAT: *(float *)(arr->data)=(*v).r; break;\\\\\n\t\tcase PyArray_INT: *(int *)(arr->data)=(*v).r; break;\\\\\n\t\tcase PyArray_SHORT: *(short *)(arr->data)=(*v).r; break;\\\\\n TRYCOMPLEXPYARRAYTEMPLATECHAR\\\\\n\t\tcase PyArray_UBYTE: *(unsigned char *)(arr->data)=(*v).r; break;\\\\\n\t\tcase PyArray_SBYTE: *(signed char *)(arr->data)=(*v).r; break;\\\\\n case PyArray_OBJECT: (arr->descr->setitem)(pyobj_from_complex_ ## ctype ## 1((*v)),arr->data); break;\\\\\n\t\tdefault: return -2;\\\\\n\t};\\\\\n\treturn -1;\n#endif\n\"\"\"\n## cppmacros['NUMFROMARROBJ']=\"\"\"\\\n## #define NUMFROMARROBJ(typenum,ctype) \\\\\n## \\tif (PyArray_Check(obj)) arr = (PyArrayObject *)obj;\\\\\n## \\telse arr = (PyArrayObject *)PyArray_ContiguousFromObject(obj,typenum,0,0);\\\\\n## \\tif (arr) {\\\\\n## \\t\\tif (arr->descr->type_num==PyArray_OBJECT) {\\\\\n## \\t\\t\\tif (!ctype ## _from_pyobj(v,(arr->descr->getitem)(arr->data),\\\"\\\"))\\\\\n## \\t\\t\\tgoto capi_fail;\\\\\n## \\t\\t} else {\\\\\n## \\t\\t\\t(arr->descr->cast[typenum])(arr->data,1,(char*)v,1,1);\\\\\n## \\t\\t}\\\\\n## \\t\\tif ((PyObject *)arr != obj) { Py_DECREF(arr); }\\\\\n## \\t\\treturn 1;\\\\\n## \\t}\n## \"\"\"\n## #XXX: Note that CNUMFROMARROBJ is identical with NUMFROMARROBJ\n## cppmacros['CNUMFROMARROBJ']=\"\"\"\\\n## #define CNUMFROMARROBJ(typenum,ctype) \\\\\n## \\tif (PyArray_Check(obj)) arr = (PyArrayObject *)obj;\\\\\n## \\telse arr = (PyArrayObject *)PyArray_ContiguousFromObject(obj,typenum,0,0);\\\\\n## \\tif (arr) {\\\\\n## \\t\\tif (arr->descr->type_num==PyArray_OBJECT) {\\\\\n## \\t\\t\\tif (!ctype ## _from_pyobj(v,(arr->descr->getitem)(arr->data),\\\"\\\"))\\\\\n## \\t\\t\\tgoto capi_fail;\\\\\n## \\t\\t} else {\\\\\n## \\t\\t\\t(arr->descr->cast[typenum])((void *)(arr->data),1,(void *)(v),1,1);\\\\\n## \\t\\t}\\\\\n## \\t\\tif ((PyObject *)arr != obj) { Py_DECREF(arr); }\\\\\n## \\t\\treturn 1;\\\\\n## \\t}\n## \"\"\"\n\n\nneeds['GETSTRFROMPYTUPLE']=['STRINGCOPYN','PRINTPYOBJERR']\ncppmacros['GETSTRFROMPYTUPLE']=\"\"\"\\\n#define GETSTRFROMPYTUPLE(tuple,index,str,len) {\\\\\n\\t\\tPyObject *rv_cb_str = PyTuple_GetItem((tuple),(index));\\\\\n\\t\\tif (rv_cb_str == NULL)\\\\\n\\t\\t\\tgoto capi_fail;\\\\\n\\t\\tif (PyString_Check(rv_cb_str)) {\\\\\n\\t\\t\\tstr[len-1]='\\\\0';\\\\\n\\t\\t\\tSTRINGCOPYN((str),PyString_AS_STRING((PyStringObject*)rv_cb_str),(len));\\\\\n\\t\\t} else {\\\\\n\\t\\t\\tPRINTPYOBJERR(rv_cb_str);\\\\\n\\t\\t\\tPyErr_SetString(#modulename#_error,\\\"string object expected\\\");\\\\\n\\t\\t\\tgoto capi_fail;\\\\\n\\t\\t}\\\\\n\\t}\n\"\"\"\ncppmacros['GETSCALARFROMPYTUPLE']=\"\"\"\\\n#define GETSCALARFROMPYTUPLE(tuple,index,var,ctype,mess) {\\\\\n\\t\\tif ((capi_tmp = PyTuple_GetItem((tuple),(index)))==NULL) goto capi_fail;\\\\\n\\t\\tif (!(ctype ## _from_pyobj((var),capi_tmp,mess)))\\\\\n\\t\\t\\tgoto capi_fail;\\\\\n\\t}\n\"\"\"\n\nneeds['MEMCOPY']=['string.h']\ncppmacros['MEMCOPY']=\"\"\"\\\n#define MEMCOPY(to,from,n)\\\\\n\\tif ((memcpy(to,from,n)) == NULL) {\\\\\n\\t\\tPyErr_SetString(PyExc_MemoryError, \\\"memcpy failed\\\");\\\\\n\\t\\tgoto capi_fail;\\\\\n\\t}\n\"\"\"\ncppmacros['STRINGMALLOC']=\"\"\"\\\n#define STRINGMALLOC(str,len)\\\\\n\\tif ((str = (string)malloc(sizeof(char)*(len+1))) == NULL) {\\\\\n\\t\\tPyErr_SetString(PyExc_MemoryError, \\\"out of memory\\\");\\\\\n\\t\\tgoto capi_fail;\\\\\n\\t} else {\\\\\n\\t\\t(str)[len] = '\\\\0';\\\\\n\\t}\n\"\"\"\ncppmacros['STRINGFREE']=\"\"\"\\\n#define STRINGFREE(str)\\\\\n\\tif (!(str == NULL)) free(str);\n\"\"\"\nneeds['STRINGCOPYN']=['string.h']\ncppmacros['STRINGCOPYN']=\"\"\"\\\n#define STRINGCOPYN(to,from,n)\\\\\n\\tif ((strncpy(to,from,sizeof(char)*(n))) == NULL) {\\\\\n\\t\\tPyErr_SetString(PyExc_MemoryError, \\\"strncpy failed\\\");\\\\\n\\t\\tgoto capi_fail;\\\\\n\\t} else if (strlen(to)<(n)) {\\\\\n\\t\\tmemset((to)+strlen(to), ' ', (n)-strlen(to));\\\\\n\\t} /* Padding with spaces instead of nulls. */\n\"\"\"\nneeds['STRINGCOPY']=['string.h']\ncppmacros['STRINGCOPY']=\"\"\"\\\n#define STRINGCOPY(to,from)\\\\\n\\tif ((strcpy(to,from)) == NULL) {\\\\\n\\t\\tPyErr_SetString(PyExc_MemoryError, \\\"strcpy failed\\\");\\\\\n\\t\\tgoto capi_fail;\\\\\n\\t}\n\"\"\"\ncppmacros['CHECKGENERIC']=\"\"\"\\\n#define CHECKGENERIC(check,tcheck,name) \\\\\n\\tif (!(check)) {\\\\\n\\t\\tPyErr_SetString(#modulename#_error,\\\"(\\\"tcheck\\\") failed for \\\"name);\\\\\n\\t\\t/*goto capi_fail;*/\\\\\n\\t} else \"\"\"\ncppmacros['CHECKARRAY']=\"\"\"\\\n#define CHECKARRAY(check,tcheck,name) \\\\\n\\tif (!(check)) {\\\\\n\\t\\tPyErr_SetString(#modulename#_error,\\\"(\\\"tcheck\\\") failed for \\\"name);\\\\\n\\t\\t/*goto capi_fail;*/\\\\\n\\t} else \"\"\"\ncppmacros['CHECKSTRING']=\"\"\"\\\n#define CHECKSTRING(check,tcheck,name,show,var)\\\\\n\\tif (!(check)) {\\\\\n\\t\\tPyErr_SetString(#modulename#_error,\\\"(\\\"tcheck\\\") failed for \\\"name);\\\\\n\\t\\tfprintf(stderr,show\\\"\\\\n\\\",slen(var),var);\\\\\n\\t\\t/*goto capi_fail;*/\\\\\n\\t} else \"\"\"\ncppmacros['CHECKSCALAR']=\"\"\"\\\n#define CHECKSCALAR(check,tcheck,name,show,var)\\\\\n\\tif (!(check)) {\\\\\n\\t\\tPyErr_SetString(#modulename#_error,\\\"(\\\"tcheck\\\") failed for \\\"name);\\\\\n\\t\\tfprintf(stderr,show\\\"\\\\n\\\",var);\\\\\n\\t\\t/*goto capi_fail;*/\\\\\n\\t} else \"\"\"\n## cppmacros['CHECKDIMS']=\"\"\"\\\n## #define CHECKDIMS(dims,rank) \\\\\n## \\tfor (int i=0;i<(rank);i++)\\\\\n## \\t\\tif (dims[i]<0) {\\\\\n## \\t\\t\\tfprintf(stderr,\\\"Unspecified array argument requires a complete dimension specification.\\\\n\\\");\\\\\n## \\t\\t\\tgoto capi_fail;\\\\\n## \\t\\t}\n## \"\"\"\ncppmacros['ARRSIZE']='#define ARRSIZE(dims,rank) (_PyArray_multiply_list(dims,rank))'\ncppmacros['OLDPYNUM']=\"\"\"\\\n#ifdef OLDPYNUM\n#error You need to intall Numeric Python version 13 or higher. Get it from http:/sourceforge.net/project/?group_id=1369\n#endif\n\"\"\"\n################# C functions ###############\n\ncfuncs['calcarrindex']=\"\"\"\\\nstatic int calcarrindex(int *i,PyArrayObject *arr) {\n\\tint k,ii = i[0];\n\\tfor (k=1; k < arr->nd; k++)\n\\t\\tii += (ii*(arr->dimensions[k] - 1)+i[k]); /* assuming contiguous arr */\n\\treturn ii;\n}\"\"\"\ncfuncs['calcarrindextr']=\"\"\"\\\nstatic int calcarrindextr(int *i,PyArrayObject *arr) {\n\\tint k,ii = i[arr->nd-1];\n\\tfor (k=1; k < arr->nd; k++)\n\\t\\tii += (ii*(arr->dimensions[arr->nd-k-1] - 1)+i[arr->nd-k-1]); /* assuming contiguous arr */\n\\treturn ii;\n}\"\"\"\ncfuncs['forcomb']=\"\"\"\\\nstatic struct { int nd;intp *d;int *i,*i_tr,tr; } forcombcache;\nstatic int initforcomb(intp *dims,int nd,int tr) {\n int k;\n if (dims==NULL) return 0;\n if (nd<0) return 0;\n forcombcache.nd = nd;\n forcombcache.d = dims;\n forcombcache.tr = tr;\n if ((forcombcache.i = (int *)malloc(sizeof(int)*nd))==NULL) return 0;\n if ((forcombcache.i_tr = (int *)malloc(sizeof(int)*nd))==NULL) return 0;\n for (k=1;kdata,str,PyArray_SIZE(arr)); }\n\\treturn 1;\ncapi_fail:\n\\tPRINTPYOBJERR(obj);\n\\tPyErr_SetString(#modulename#_error,\\\"try_pyarr_from_string failed\\\");\n\\treturn 0;\n}\n\"\"\"\nneeds['string_from_pyobj']=['string','STRINGMALLOC','STRINGCOPYN']\ncfuncs['string_from_pyobj']=\"\"\"\\\nstatic int string_from_pyobj(string *str,int *len,const string inistr,PyObject *obj,const char *errmess) {\n\\tPyArrayObject *arr = NULL;\n\\tPyObject *tmp = NULL;\n#ifdef DEBUGCFUNCS\nfprintf(stderr,\\\"string_from_pyobj(str='%s',len=%d,inistr='%s',obj=%p)\\\\n\\\",(char*)str,*len,(char *)inistr,obj);\n#endif\n\\tif (obj == Py_None) {\n\\t\\tif (*len == -1)\n\\t\\t\\t*len = strlen(inistr); /* Will this cause problems? */\n\\t\\tSTRINGMALLOC(*str,*len);\n\\t\\tSTRINGCOPYN(*str,inistr,*len);\n\\t\\treturn 1;\n\\t}\n\\tif (PyArray_Check(obj)) {\n\\t\\tif ((arr = (PyArrayObject *)obj) == NULL)\n\\t\\t\\tgoto capi_fail;\n\\t\\tif (!ISCONTIGUOUS(arr)) {\n\\t\\t\\tPyErr_SetString(PyExc_ValueError,\\\"array object is non-contiguous.\\\");\n\\t\\t\\tgoto capi_fail;\n\\t\\t}\n\\t\\tif (arr->descr->elsize==sizeof(char)) {\n\\t\\t\\tif (*len == -1)\n\\t\\t\\t\\t*len = (arr->descr->elsize)*PyArray_SIZE(arr);\n\\t\\t\\tSTRINGMALLOC(*str,*len);\n\\t\\t\\tSTRINGCOPYN(*str,arr->data,*len);\n\\t\\t\\treturn 1;\n\\t\\t}\n\\t\\tPyErr_SetString(PyExc_ValueError,\\\"array object element size is not 1.\\\");\n\\t\\tgoto capi_fail;\n\\t}\n\\tif (PyString_Check(obj)) {\n\\t\\ttmp = obj;\n\\t\\tPy_INCREF(tmp);\n\\t}\n\\telse\n\\t\\ttmp = PyObject_Str(obj);\n\\tif (tmp == NULL) goto capi_fail;\n\\tif (*len == -1)\n\\t\\t*len = PyString_GET_SIZE(tmp);\n\\tSTRINGMALLOC(*str,*len);\n\\tSTRINGCOPYN(*str,PyString_AS_STRING(tmp),*len);\n\\tPy_DECREF(tmp);\n\\treturn 1;\ncapi_fail:\n\\tPy_XDECREF(tmp);\n\\t{\n\\t\\tPyObject* err = PyErr_Occurred();\n\\t\\tif (err==NULL) err = #modulename#_error;\n\\t\\tPyErr_SetString(err,errmess);\n\\t}\n\\treturn 0;\n}\n\"\"\"\nneeds['char_from_pyobj']=['int_from_pyobj']\ncfuncs['char_from_pyobj']=\"\"\"\\\nstatic int char_from_pyobj(char* v,PyObject *obj,const char *errmess) {\n\\tint i=0;\n\\tif (int_from_pyobj(&i,obj,errmess)) {\n\\t\\t*v = (char)i;\n\\t\\treturn 1;\n\\t}\n\\treturn 0;\n}\n\"\"\"\nneeds['signed_char_from_pyobj']=['int_from_pyobj','signed_char']\ncfuncs['signed_char_from_pyobj']=\"\"\"\\\nstatic int signed_char_from_pyobj(signed_char* v,PyObject *obj,const char *errmess) {\n\\tint i=0;\n\\tif (int_from_pyobj(&i,obj,errmess)) {\n\\t\\t*v = (signed_char)i;\n\\t\\treturn 1;\n\\t}\n\\treturn 0;\n}\n\"\"\"\nneeds['short_from_pyobj']=['int_from_pyobj']\ncfuncs['short_from_pyobj']=\"\"\"\\\nstatic int short_from_pyobj(short* v,PyObject *obj,const char *errmess) {\n\\tint i=0;\n\\tif (int_from_pyobj(&i,obj,errmess)) {\n\\t\\t*v = (short)i;\n\\t\\treturn 1;\n\\t}\n\\treturn 0;\n}\n\"\"\"\ncfuncs['int_from_pyobj']=\"\"\"\\\nstatic int int_from_pyobj(int* v,PyObject *obj,const char *errmess) {\n\\tPyObject* tmp = NULL;\n\\tif (PyInt_Check(obj)) {\n\\t\\t*v = (int)PyInt_AS_LONG(obj);\n\\t\\treturn 1;\n\\t}\n\\ttmp = PyNumber_Int(obj);\n\\tif (tmp) {\n\\t\\t*v = PyInt_AS_LONG(tmp);\n\\t\\tPy_DECREF(tmp);\n\\t\\treturn 1;\n\\t}\n\\tif (PyComplex_Check(obj))\n\\t\\ttmp = PyObject_GetAttrString(obj,\\\"real\\\");\n\\telse if (PyString_Check(obj))\n\\t\\t/*pass*/;\n\\telse if (PySequence_Check(obj))\n\\t\\ttmp = PySequence_GetItem(obj,0);\n\\tif (tmp) {\n\\t\\tPyErr_Clear();\n\\t\\tif (int_from_pyobj(v,tmp,errmess)) {Py_DECREF(tmp); return 1;}\n\\t\\tPy_DECREF(tmp);\n\\t}\n\\t{\n\\t\\tPyObject* err = PyErr_Occurred();\n\\t\\tif (err==NULL) err = #modulename#_error;\n\\t\\tPyErr_SetString(err,errmess);\n\\t}\n\\treturn 0;\n}\n\"\"\"\ncfuncs['long_from_pyobj']=\"\"\"\\\nstatic int long_from_pyobj(long* v,PyObject *obj,const char *errmess) {\n\\tPyObject* tmp = NULL;\n\\tif (PyInt_Check(obj)) {\n\\t\\t*v = PyInt_AS_LONG(obj);\n\\t\\treturn 1;\n\\t}\n\\ttmp = PyNumber_Int(obj);\n\\tif (tmp) {\n\\t\\t*v = PyInt_AS_LONG(tmp);\n\\t\\tPy_DECREF(tmp);\n\\t\\treturn 1;\n\\t}\n\\tif (PyComplex_Check(obj))\n\\t\\ttmp = PyObject_GetAttrString(obj,\\\"real\\\");\n\\telse if (PyString_Check(obj))\n\\t\\t/*pass*/;\n\\telse if (PySequence_Check(obj))\n\\t\\ttmp = PySequence_GetItem(obj,0);\n\\tif (tmp) {\n\\t\\tPyErr_Clear();\n\\t\\tif (long_from_pyobj(v,tmp,errmess)) {Py_DECREF(tmp); return 1;}\n\\t\\tPy_DECREF(tmp);\n\\t}\n\\t{\n\\t\\tPyObject* err = PyErr_Occurred();\n\\t\\tif (err==NULL) err = #modulename#_error;\n\\t\\tPyErr_SetString(err,errmess);\n\\t}\n\\treturn 0;\n}\n\"\"\"\nneeds['long_long_from_pyobj']=['long_long']\ncfuncs['long_long_from_pyobj']=\"\"\"\\\nstatic int long_long_from_pyobj(long_long* v,PyObject *obj,const char *errmess) {\n\\tPyObject* tmp = NULL;\n\\tif (PyLong_Check(obj)) {\n\\t\\t*v = PyLong_AsLongLong(obj);\n\\t\\treturn (!PyErr_Occurred());\n\\t}\n\\tif (PyInt_Check(obj)) {\n\\t\\t*v = (long_long)PyInt_AS_LONG(obj);\n\\t\\treturn 1;\n\\t}\n\\ttmp = PyNumber_Long(obj);\n\\tif (tmp) {\n\\t\\t*v = PyLong_AsLongLong(tmp);\n\\t\\tPy_DECREF(tmp);\n\\t\\treturn (!PyErr_Occurred());\n\\t}\n\\tif (PyComplex_Check(obj))\n\\t\\ttmp = PyObject_GetAttrString(obj,\\\"real\\\");\n\\telse if (PyString_Check(obj))\n\\t\\t/*pass*/;\n\\telse if (PySequence_Check(obj))\n\\t\\ttmp = PySequence_GetItem(obj,0);\n\\tif (tmp) {\n\\t\\tPyErr_Clear();\n\\t\\tif (long_long_from_pyobj(v,tmp,errmess)) {Py_DECREF(tmp); return 1;}\n\\t\\tPy_DECREF(tmp);\n\\t}\n\\t{\n\\t\\tPyObject* err = PyErr_Occurred();\n\\t\\tif (err==NULL) err = #modulename#_error;\n\\t\\tPyErr_SetString(err,errmess);\n\\t}\n\\treturn 0;\n}\n\"\"\"\nneeds['long_double_from_pyobj']=['double_from_pyobj','long_double']\ncfuncs['long_double_from_pyobj']=\"\"\"\\\nstatic int long_double_from_pyobj(long_double* v,PyObject *obj,const char *errmess) {\n\\tdouble d=0;\n\\tif (PyArray_CheckScalar(obj)){\n\\t\\tif PyArray_IsScalar(obj, LongDouble) {\n\\t\\t\\tPyArray_ScalarAsCtype(obj, v);\n\\t\\t\\treturn 1;\n\\t\\t}\n\\t\\telse if (PyArray_Check(obj) && PyArray_TYPE(obj)==PyArray_LONGDOUBLE) {\n\\t\\t\\t(*v) = *((longdouble *)PyArray_DATA(obj))\n\\t\\t\\treturn 1;\n\\t\\t}\n\\t}\n\\tif (double_from_pyobj(&d,obj,errmess)) {\n\\t\\t*v = (long_double)d;\n\\t\\treturn 1;\n\\t}\n\\treturn 0;\n}\n\"\"\"\ncfuncs['double_from_pyobj']=\"\"\"\\\nstatic int double_from_pyobj(double* v,PyObject *obj,const char *errmess) {\n\\tPyObject* tmp = NULL;\n\\tif (PyFloat_Check(obj)) {\n#ifdef __sgi\n\\t\\t*v = PyFloat_AsDouble(obj);\n#else\n\\t\\t*v = PyFloat_AS_DOUBLE(obj);\n#endif\n\\t\\treturn 1;\n\\t}\n\\ttmp = PyNumber_Float(obj);\n\\tif (tmp) {\n#ifdef __sgi\n\\t\\t*v = PyFloat_AsDouble(tmp);\n#else\n\\t\\t*v = PyFloat_AS_DOUBLE(tmp);\n#endif\n\\t\\tPy_DECREF(tmp);\n\\t\\treturn 1;\n\\t}\n\\tif (PyComplex_Check(obj))\n\\t\\ttmp = PyObject_GetAttrString(obj,\\\"real\\\");\n\\telse if (PyString_Check(obj))\n\\t\\t/*pass*/;\n\\telse if (PySequence_Check(obj))\n\\t\\ttmp = PySequence_GetItem(obj,0);\n\\tif (tmp) {\n\\t\\tPyErr_Clear();\n\\t\\tif (double_from_pyobj(v,tmp,errmess)) {Py_DECREF(tmp); return 1;}\n\\t\\tPy_DECREF(tmp);\n\\t}\n\\t{\n\\t\\tPyObject* err = PyErr_Occurred();\n\\t\\tif (err==NULL) err = #modulename#_error;\n\\t\\tPyErr_SetString(err,errmess);\n\\t}\n\\treturn 0;\n}\n\"\"\"\nneeds['float_from_pyobj']=['double_from_pyobj']\ncfuncs['float_from_pyobj']=\"\"\"\\\nstatic int float_from_pyobj(float* v,PyObject *obj,const char *errmess) {\n\\tdouble d=0.0;\n\\tif (double_from_pyobj(&d,obj,errmess)) {\n\\t\\t*v = (float)d;\n\\t\\treturn 1;\n\\t}\n\\treturn 0;\n}\n\"\"\"\nneeds['complex_long_double_from_pyobj']=['complex_long_double','long_double',\n 'complex_double_from_pyobj']\ncfuncs['complex_long_double_from_pyobj']=\"\"\"\\\nstatic int complex_long_double_from_pyobj(complex_long_double* v,PyObject *obj,const char *errmess) {\n\\tcomplex_double cd={0.0,0.0};\n\\tif (PyArray_CheckScalar(obj)){\n\\t\\tif PyArray_IsScalar(obj, CLongDouble) {\n\\t\\t\\tPyArray_ScalarAsCtype(obj, v);\n\\t\\t\\treturn 1;\n\\t\\t}\n\\t\\telse if (PyArray_Check(obj) && PyArray_TYPE(obj)==PyArray_CLONGDOUBLE) {\n\\t\\t\\t(*v).r = ((clongdouble *)PyArray_DATA(obj))->real;\n\\t\\t\\t(*v).i = ((clongdouble *)PyArray_DATA(obj))->imag;\n\\t\\t\\treturn 1;\n\\t\\t}\n\\t}\n\\tif (complex_double_from_pyobj(&cd,obj,errmess)) {\n\\t\\t(*v).r = (long_double)cd.r;\n\\t\\t(*v).i = (long_double)cd.i;\n\\t\\treturn 1;\n\\t}\n\\treturn 0;\n}\n\"\"\"\nneeds['complex_double_from_pyobj']=['complex_double']\ncfuncs['complex_double_from_pyobj']=\"\"\"\\\nstatic int complex_double_from_pyobj(complex_double* v,PyObject *obj,const char *errmess) {\n\\tPy_complex c;\n\\tif (PyComplex_Check(obj)) {\n\\t\\tc=PyComplex_AsCComplex(obj);\n\\t\\t(*v).r=c.real, (*v).i=c.imag;\n\\t\\treturn 1;\n\\t}\n\\tif (PyArray_IsScalar(obj, ComplexFloating)) {\n\\t\\tif (PyArray_IsScalar(obj, CFloat)) {\n\\t\\t\\tcfloat new;\n\\t\\t\\tPyArray_ScalarAsCtype(obj, &new);\n\\t\\t\\t(*v).r = (double)new.real;\n\\t\\t\\t(*v).i = (double)new.imag;\n\\t\\t}\n\\t\\telse if (PyArray_IsScalar(obj, CLongDouble)) {\n\\t\\t\\tclongdouble new;\n\\t\\t\\tPyArray_ScalarAsCtype(obj, &new);\n\\t\\t\\t(*v).r = (double)new.real;\n\\t\\t\\t(*v).i = (double)new.imag;\n\\t\\t}\n\\t\\telse { /* if (PyArray_IsScalar(obj, CDouble)) */\n\\t\\t\\tPyArray_ScalarAsCtype(obj, v);\n\\t\\t}\n\\t\\treturn 1;\n\\t}\n\\tif (PyArray_CheckScalar(obj)) { /* 0-dim array or still array scalar */\n\\t\\tPyObject *arr;\n\\t\\tPyArray_Typecode otype = {PyArray_CDOUBLE, sizeof(cdouble), 0};\n\\t\\tif (PyArray_Check(obj)) {\n\\t\\t\\tarr = PyArray_CastToType((PyArrayObject *)obj, &otype);\n\\t\\t}\n\\t\\telse {\n\\t\\t\\tarr = PyArray_FromScalar(obj, &otype);\n\\t\\t}\n\\t\\tif (arr==NULL) return 0;\n\\t\\t(*v).r = ((cdouble *)PyArray_DATA(arr))->real;\n\\t\\t(*v).i = ((cdouble *)PyArray_DATA(arr))->imag;\n\\t\\treturn 1;\n\\t}\n\\t/* Python does not provide PyNumber_Complex function :-( */\n\\t(*v).i=0.0;\n\\tif (PyFloat_Check(obj)) {\n#ifdef __sgi\n\\t\\t(*v).r = PyFloat_AsDouble(obj);\n#else\n\\t\\t(*v).r = PyFloat_AS_DOUBLE(obj);\n#endif\n\\t\\treturn 1;\n\\t}\n\\tif (PyInt_Check(obj)) {\n\\t\\t(*v).r = (double)PyInt_AS_LONG(obj);\n\\t\\treturn 1;\n\\t}\n\\tif (PyLong_Check(obj)) {\n\\t\\t(*v).r = PyLong_AsDouble(obj);\n\\t\\treturn (!PyErr_Occurred());\n\\t}\n\\tif (PySequence_Check(obj) && (!PyString_Check(obj))) {\n\\t\\tPyObject *tmp = PySequence_GetItem(obj,0);\n\\t\\tif (tmp) {\n\\t\\t\\tif (complex_double_from_pyobj(v,tmp,errmess)) {\n\\t\\t\\t\\tPy_DECREF(tmp);\n\\t\\t\\t\\treturn 1;\n\\t\\t\\t}\n\\t\\t\\tPy_DECREF(tmp);\n\\t\\t}\n\\t}\n\\t{\n\\t\\tPyObject* err = PyErr_Occurred();\n\\t\\tif (err==NULL)\n\\t\\t\\terr = PyExc_TypeError;\n\\t\\tPyErr_SetString(err,errmess);\n\\t}\n\\treturn 0;\n}\n\"\"\"\nneeds['complex_float_from_pyobj']=['complex_float','complex_double_from_pyobj']\ncfuncs['complex_float_from_pyobj']=\"\"\"\\\nstatic int complex_float_from_pyobj(complex_float* v,PyObject *obj,const char *errmess) {\n\\tcomplex_double cd={0.0,0.0};\n\\tif (complex_double_from_pyobj(&cd,obj,errmess)) {\n\\t\\t(*v).r = (float)cd.r;\n\\t\\t(*v).i = (float)cd.i;\n\\t\\treturn 1;\n\\t}\n\\treturn 0;\n}\n\"\"\"\nneeds['try_pyarr_from_char']=['pyobj_from_char1','TRYPYARRAYTEMPLATE']\ncfuncs['try_pyarr_from_char']='static int try_pyarr_from_char(PyObject* obj,char* v) {\\n\\tTRYPYARRAYTEMPLATE(char,\\'c\\');\\n}\\n'\nneeds['try_pyarr_from_signed_char']=['TRYPYARRAYTEMPLATE','unsigned_char']\ncfuncs['try_pyarr_from_unsigned_char']='static int try_pyarr_from_unsigned_char(PyObject* obj,unsigned_char* v) {\\n\\tTRYPYARRAYTEMPLATE(unsigned_char,\\'b\\');\\n}\\n'\nneeds['try_pyarr_from_signed_char']=['TRYPYARRAYTEMPLATE','signed_char']\ncfuncs['try_pyarr_from_signed_char']='static int try_pyarr_from_signed_char(PyObject* obj,signed_char* v) {\\n\\tTRYPYARRAYTEMPLATE(signed_char,\\'1\\');\\n}\\n'\nneeds['try_pyarr_from_short']=['pyobj_from_short1','TRYPYARRAYTEMPLATE']\ncfuncs['try_pyarr_from_short']='static int try_pyarr_from_short(PyObject* obj,short* v) {\\n\\tTRYPYARRAYTEMPLATE(short,\\'s\\');\\n}\\n'\nneeds['try_pyarr_from_int']=['pyobj_from_int1','TRYPYARRAYTEMPLATE']\ncfuncs['try_pyarr_from_int']='static int try_pyarr_from_int(PyObject* obj,int* v) {\\n\\tTRYPYARRAYTEMPLATE(int,\\'i\\');\\n}\\n'\nneeds['try_pyarr_from_long']=['pyobj_from_long1','TRYPYARRAYTEMPLATE']\ncfuncs['try_pyarr_from_long']='static int try_pyarr_from_long(PyObject* obj,long* v) {\\n\\tTRYPYARRAYTEMPLATE(long,\\'l\\');\\n}\\n'\nneeds['try_pyarr_from_long_long']=['pyobj_from_long_long1','TRYPYARRAYTEMPLATE','long_long']\ncfuncs['try_pyarr_from_long_long']='static int try_pyarr_from_long_long(PyObject* obj,long_long* v) {\\n\\tTRYPYARRAYTEMPLATE(long_long,\\'L\\');\\n}\\n'\nneeds['try_pyarr_from_float']=['pyobj_from_float1','TRYPYARRAYTEMPLATE']\ncfuncs['try_pyarr_from_float']='static int try_pyarr_from_float(PyObject* obj,float* v) {\\n\\tTRYPYARRAYTEMPLATE(float,\\'f\\');\\n}\\n'\nneeds['try_pyarr_from_double']=['pyobj_from_double1','TRYPYARRAYTEMPLATE']\ncfuncs['try_pyarr_from_double']='static int try_pyarr_from_double(PyObject* obj,double* v) {\\n\\tTRYPYARRAYTEMPLATE(double,\\'d\\');\\n}\\n'\nneeds['try_pyarr_from_complex_float']=['pyobj_from_complex_float1','TRYCOMPLEXPYARRAYTEMPLATE','complex_float']\ncfuncs['try_pyarr_from_complex_float']='static int try_pyarr_from_complex_float(PyObject* obj,complex_float* v) {\\n\\tTRYCOMPLEXPYARRAYTEMPLATE(float,\\'F\\');\\n}\\n'\nneeds['try_pyarr_from_complex_double']=['pyobj_from_complex_double1','TRYCOMPLEXPYARRAYTEMPLATE','complex_double']\ncfuncs['try_pyarr_from_complex_double']='static int try_pyarr_from_complex_double(PyObject* obj,complex_double* v) {\\n\\tTRYCOMPLEXPYARRAYTEMPLATE(double,\\'D\\');\\n}\\n'\n\nneeds['create_cb_arglist']=['CFUNCSMESS','PRINTPYOBJERR','MINMAX']\ncfuncs['create_cb_arglist']=\"\"\"\\\nstatic int create_cb_arglist(PyObject* fun,PyTupleObject* xa,const int maxnofargs,const int nofoptargs,int *nofargs,PyTupleObject **args,const char *errmess) {\n\\tPyObject *tmp = NULL;\n\\tPyObject *tmp_fun = NULL;\n\\tint tot,opt,ext,siz,i,di=0;\n\\tCFUNCSMESS(\\\"create_cb_arglist\\\\n\\\");\n\\ttot=opt=ext=siz=0;\n\\t/* Get the total number of arguments */\n\\tif (PyFunction_Check(fun))\n\\t\\ttmp_fun = fun;\n\\telse {\n\\t\\tdi = 1;\n\\t\\tif (PyObject_HasAttrString(fun,\\\"im_func\\\")) {\n\\t\\t\\ttmp_fun = PyObject_GetAttrString(fun,\\\"im_func\\\");\n\\t\\t}\n\\t\\telse if (PyObject_HasAttrString(fun,\\\"__call__\\\")) {\n\\t\\t\\ttmp = PyObject_GetAttrString(fun,\\\"__call__\\\");\n\\t\\t\\tif (PyObject_HasAttrString(tmp,\\\"im_func\\\"))\n\\t\\t\\t\\ttmp_fun = PyObject_GetAttrString(tmp,\\\"im_func\\\");\n\\t\\t\\telse {\n\\t\\t\\t\\ttmp_fun = fun; /* built-in function */\n\\t\\t\\t\\ttot = maxnofargs;\n\\t\\t\\t\\tif (xa != NULL)\n\\t\\t\\t\\t\\ttot += PyTuple_Size((PyObject *)xa);\n\\t\\t\\t}\n\\t\\t\\tPy_XDECREF(tmp);\n\\t\\t}\n\\t\\telse if (PyFortran_Check(fun) || PyFortran_Check1(fun)) {\n\\t\\t\\ttot = maxnofargs;\n\\t\\t\\tif (xa != NULL)\n\\t\\t\\t\\ttot += PyTuple_Size((PyObject *)xa);\n\\t\\t\\ttmp_fun = fun;\n\\t\\t}\n\\t\\telse if (PyCObject_Check(fun)) {\n\\t\\t\\ttot = maxnofargs;\n\\t\\t\\tif (xa != NULL)\n\\t\\t\\t\\text = PyTuple_Size((PyObject *)xa);\n\\t\\t\\tif(ext>0) {\n\\t\\t\\t\\tfprintf(stderr,\\\"extra arguments tuple cannot be used with CObject call-back\\\\n\\\");\n\\t\\t\\t\\tgoto capi_fail;\n\\t\\t\\t}\n\\t\\t\\ttmp_fun = fun;\n\\t\\t}\n\\t}\nif (tmp_fun==NULL) {\nfprintf(stderr,\\\"Call-back argument must be function|instance|instance.__call__|f2py-function but got %s.\\\\n\\\",(fun==NULL?\\\"NULL\\\":fun->ob_type->tp_name));\ngoto capi_fail;\n}\n\\tif (PyObject_HasAttrString(tmp_fun,\\\"func_code\\\")) {\n\\t\\tif (PyObject_HasAttrString(tmp = PyObject_GetAttrString(tmp_fun,\\\"func_code\\\"),\\\"co_argcount\\\"))\n\\t\\t\\ttot = PyInt_AsLong(PyObject_GetAttrString(tmp,\\\"co_argcount\\\")) - di;\n\\t\\tPy_XDECREF(tmp);\n\\t}\n\\t/* Get the number of optional arguments */\n\\tif (PyObject_HasAttrString(tmp_fun,\\\"func_defaults\\\"))\n\\t\\tif (PyTuple_Check(tmp = PyObject_GetAttrString(tmp_fun,\\\"func_defaults\\\")))\n\\t\\t\\topt = PyTuple_Size(tmp);\n\\t\\tPy_XDECREF(tmp);\n\\t/* Get the number of extra arguments */\n\\tif (xa != NULL)\n\\t\\text = PyTuple_Size((PyObject *)xa);\n\\t/* Calculate the size of call-backs argument list */\n\\tsiz = MIN(maxnofargs+ext,tot);\n\\t*nofargs = MAX(0,siz-ext);\n#ifdef DEBUGCFUNCS\n\\tfprintf(stderr,\\\"debug-capi:create_cb_arglist:maxnofargs(-nofoptargs),tot,opt,ext,siz,nofargs=%d(-%d),%d,%d,%d,%d,%d\\\\n\\\",maxnofargs,nofoptargs,tot,opt,ext,siz,*nofargs);\n#endif\n\\tif (siz0:\n if not needs.has_key(outneeds[n][0]):\n out.append(outneeds[n][0])\n del outneeds[n][0]\n else:\n flag=0\n for k in outneeds[n][1:]:\n if k in needs[outneeds[n][0]]:\n flag=1\n break\n if flag:\n outneeds[n]=outneeds[n][1:]+[outneeds[n][0]]\n else:\n out.append(outneeds[n][0])\n del outneeds[n][0]\n if saveout and (0 not in map(lambda x,y:x==y,saveout,outneeds[n])):\n print n,saveout\n errmess('get_needs: no progress in sorting needs, probably circular dependence, skipping.\\n')\n out=out+saveout\n break\n saveout=copy.copy(outneeds[n])\n if out==[]: out=[n]\n res[n]=out\n return res\n", "methods": [ { "name": "buildcfuncs", "long_name": "buildcfuncs( )", "filename": "cfuncs.py", "nloc": 8, "complexity": 2, "token_count": 55, "parameters": [], "start_line": 1172, "end_line": 1179, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "append_needs", "long_name": "append_needs( need , flag = 1 )", "filename": "cfuncs.py", "nloc": 48, "complexity": 30, "token_count": 422, "parameters": [ "need", "flag" ], "start_line": 1184, "end_line": 1231, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 48, "top_nesting_level": 0 }, { "name": "get_needs", "long_name": "get_needs( )", "filename": "cfuncs.py", "nloc": 30, "complexity": 10, "token_count": 236, "parameters": [], "start_line": 1233, "end_line": 1262, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 30, "top_nesting_level": 0 } ], "methods_before": [ { "name": "buildcfuncs", "long_name": "buildcfuncs( )", "filename": "cfuncs.py", "nloc": 8, "complexity": 2, "token_count": 55, "parameters": [], "start_line": 1176, "end_line": 1183, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "append_needs", "long_name": "append_needs( need , flag = 1 )", "filename": "cfuncs.py", "nloc": 48, "complexity": 30, "token_count": 422, "parameters": [ "need", "flag" ], "start_line": 1188, "end_line": 1235, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 48, "top_nesting_level": 0 }, { "name": "get_needs", "long_name": "get_needs( )", "filename": "cfuncs.py", "nloc": 30, "complexity": 10, "token_count": 236, "parameters": [], "start_line": 1237, "end_line": 1266, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 30, "top_nesting_level": 0 } ], "changed_methods": [], "nloc": 1190, "complexity": 42, "token_count": 1729, "diff_parsed": { "added": [ "\\t\\tif (*len == -1)", "\\t\\t\\t*len = (arr->itemsize)*PyArray_SIZE(arr);", "\\t\\tSTRINGMALLOC(*str,*len);", "\\t\\tSTRINGCOPYN(*str,arr->data,*len);", "\\t\\treturn 1;" ], "deleted": [ "\\t\\tif (arr->descr->elsize==sizeof(char)) {", "\\t\\t\\tif (*len == -1)", "\\t\\t\\t\\t*len = (arr->descr->elsize)*PyArray_SIZE(arr);", "\\t\\t\\tSTRINGMALLOC(*str,*len);", "\\t\\t\\tSTRINGCOPYN(*str,arr->data,*len);", "\\t\\t\\treturn 1;", "\\t\\t}", "\\t\\tPyErr_SetString(PyExc_ValueError,\\\"array object element size is not 1.\\\");", "\\t\\tgoto capi_fail;" ] } } ] }, { "hash": "146140cce09b455477d56c06df22aafe647ae6c6", "msg": "Added more types to weave.", "author": { "name": "Travis Oliphant", "email": "oliphant@enthought.com" }, "committer": { "name": "Travis Oliphant", "email": "oliphant@enthought.com" }, "author_date": "2005-10-26T04:52:01+00:00", "author_timezone": 0, "committer_date": "2005-10-26T04:52:01+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "98830f76c36d104d8bd18d2c794500f51ba645b2" ], "project_name": "repo_copy", "project_path": "/tmp/tmpn4cqam_6/repo_copy", "deletions": 34, "insertions": 70, "lines": 104, "files": 4, "dmm_unit_size": 1.0, "dmm_unit_complexity": 1.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy/base/code_generators/generate_array_api.py", "new_path": "scipy/base/code_generators/generate_array_api.py", "filename": "generate_array_api.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -502,6 +502,10 @@\n \"\"\",\n 'EquivArrTypes', 'PyArrayObject *, PyArrayObject *', 'Bool'),\n \n+ (r\"\"\"\n+ \"\"\",\n+ 'EquivalentTypenums', 'int, int', 'Bool'),\n+\n (r\"\"\"Zeros\n \"\"\",\n 'Zeros', 'int, intp *, PyArray_Typecode *', 'PyObject *'),\n", "added_lines": 4, "deleted_lines": 0, "source_code": "\n# doc is comment_documentation\n\n# use list so order is preserved.\nobjectapi_list = [\n (r\"\"\"Set internal structure with number functions that all\n arrays will use\n \"\"\",\n 'SetNumericOps','PyObject *dict','int'),\n\n (r\"\"\"Get dictionary showing number functions that all\n arrays will use\n \"\"\",\n 'GetNumericOps','void','PyObject *'),\n\n\n (r\"\"\"For object arrays, increment all internal references.\n \"\"\",\n 'INCREF','PyArrayObject *','int'),\n\n (r\"\"\"Decrement all internal references for object arrays.\n \"\"\", \n 'XDECREF','PyArrayObject *','int'),\n\n (r\"\"\"Set the array print function to be a Python function.\n \"\"\",\n 'SetStringFunction','PyObject *op, int repr','void'),\n\n (r\"\"\"Get the PyArray_Descr structure for a type.\n \"\"\",\n 'DescrFromType','int','PyArray_Descr *'),\n\n (r\"\"\"Get pointer to zero of correct type for array. \n \"\"\",\n 'Zero', 'PyArrayObject *', 'char *'),\n\n (r\"\"\"Get pointer to one of correct type for array\n \"\"\",\n 'One', 'PyArrayObject *', 'char *'),\n\n\n (r\"\"\"Cast an array to a different type.\n \"\"\",\n 'Cast','PyArrayObject *, int','PyObject *'),\n\n (r\"\"\"Cast an array using typecode structure.\n \"\"\",\n 'CastToType','PyArrayObject *, PyArray_Typecode *','PyObject *'),\n\n (r\"\"\"Cast to an already created array.\n \"\"\",\n 'CastTo', 'PyArrayObject *, PyArrayObject *', 'int'),\n\n (r\"\"\"Check the type coercion rules.\n \"\"\",\n 'CanCastSafely','int fromtype, int totype','int'),\n\n (r\"\"\"\n \"\"\",\n 'CanCastTo','PyArray_Typecode *, PyArray_Typecode *', 'Bool'),\n\n (r\"\"\"Return the typecode of the array a Python object would be\n converted to\n \"\"\",\n 'ObjectType','PyObject *, int','int'),\n\n (r\"\"\"\n \"\"\",\n 'ArrayType','PyObject *, PyArray_Typecode *, PyArray_Typecode *','void'),\n\n (r\"\"\"Return type typecode from array scalar.\n \"\"\",\n 'TypecodeFromScalar','PyObject *, PyArray_Typecode *','void'),\n\n (r\"\"\"Compute the size of an array (in number of items)\n \"\"\",\n 'Size','PyObject *','intp'),\n\n (r\"\"\"Get scalar-equivalent to 0-d array\n \"\"\",\n 'Scalar', 'char *, int, int, int', 'PyObject *'),\n\n (r\"\"\"Get scalar-equivalent to 0-d array\n \"\"\",\n 'ToScalar', 'char *, PyArrayObject *', 'PyObject *'),\n\n (r\"\"\"Get 0-dim array from scalar\n \"\"\",\n 'FromScalar', 'PyObject *, PyArray_Typecode *', 'PyObject *'),\n\n (r\"\"\"Convert to c-type\n \"\"\",\n 'ScalarAsCtype', 'PyObject *, void *', 'void'),\n\n (r\"\"\"Register Data type\n \"\"\",\n 'RegisterDataType', 'PyTypeObject *', 'int'),\n\n (r\"\"\"Insert Descr Table\n \"\"\",\n 'RegisterDescrForType', 'int, PyArray_Descr *', 'int'),\n \n (r\"\"\"Construct an empty array from dimensions and typenum\n \"\"\",\n 'FromDims','int nd, int *, int typenum','PyObject *'),\n\n (r\"\"\"Construct an array from dimensions, typenum, and a pointer\n to the data. Python will never free this (unless you later set\n the OWN_DATA flag). \n \"\"\",\n 'FromDimsAndData','int, int *, int, char *','PyObject *'),\n\n (r\"\"\"Construct an array from an arbitrary Python Object.\n Last two integers are min_dimensions, and max_dimensions.\n If max_dimensions = 0, then any number of dimensions are allowed.\n Fix the dimension by setting min_dimension == max_dimension.\n If the array is already contiguous (and aligned and not swapped)\n no copy is done, just a new reference created.\n Base-class ndarray is returned.\n \"\"\",\n 'ContiguousFromObject',\n 'PyObject *, int typenum, int, int',\n 'PyObject *'),\n\n (r\"\"\"Construct an array from an arbitrary Python Object.\n Last two integers are min_dimensions, and max_dimensions.\n If max_dimensions = 0, then any number of dimensions are allowed.\n Fix the dimension by setting min_dimension == max_dimension.\n If the array is already contiguous (and aligned and not swapped)\n no copy is done, just a new reference created. Subclasses\n passed through.\n \"\"\",\n 'ContiguousFromAny',\n 'PyObject *, int typenum, int, int',\n 'PyObject *'),\n \n\n (r\"\"\"Same as ContiguousFromObject except ensure a copy.\n \"\"\",\n 'CopyFromObject','PyObject *, int, int, int','PyObject *'),\n\n (r\"\"\"Can return a discontiguous array (but aligned and byteswapped)\n \"\"\",\n 'FromObject','PyObject *, int, int, int','PyObject *'),\n\n (r\"\"\"\n \"\"\",\n 'FromAny', 'PyObject *, PyArray_Typecode *, int, int, int', 'PyObject *'),\n\n (r\"\"\"\n \"\"\",\n 'EnsureArray', 'PyObject *', 'PyObject *'),\n\n (r\"\"\"\n \"\"\",\n 'FromFile', 'FILE *, PyArray_Typecode *, intp, char *','PyObject *'),\n\n (r\"\"\"\n \"\"\",\n 'FromBuffer', 'PyObject *, PyArray_Typecode *, intp, int','PyObject *'),\n\n (r\"\"\"Return either an array or the appropriate Python object if the\n array is 0d and matches a Python type.\n \"\"\",\n 'Return','PyArrayObject *','PyObject *'),\n\n (r\"\"\"Get a subset of bytes from each element of the array\n \"\"\",\n 'GetField', 'PyArrayObject *, PyArray_Typecode *, int', 'PyObject *'),\n\n (r\"\"\"\n \"\"\",\n 'Byteswap', 'PyArrayObject *, Bool', 'PyObject *'),\n\n (r\"\"\"Resize (reallocate data). Only works if nothing else is\n referencing this array and it is contiguous.\n \"\"\",\n 'Resize','PyArrayObject *ap, PyArray_Dims *newshape','PyObject *'),\n\n (r\"\"\"Copy an array.\n \"\"\",\n 'Copy','PyArrayObject *','PyObject *'),\n\n (r\"\"\"Like FromDimsAndData but uses the Descr structure instead of\n typecode as input.\n \"\"\",\n 'FromDimsAndDataAndDescr','int, int *, PyArray_Descr *, char *',\n 'PyObject *'),\n\n (r\"\"\"Copy an Array into another array.\n \"\"\",\n 'CopyInto', 'PyArrayObject *dest, PyArrayObject *src', 'int'),\n\n (r\"\"\"To List\n \"\"\",\n 'ToList','PyArrayObject *', 'PyObject *'),\n\n (r\"\"\"To File\n \"\"\",\n 'ToFile','PyArrayObject *, FILE *, char *, char *', 'int'),\n\n (r\"\"\"\n \"\"\",\n 'Dump', 'PyObject *, PyObject *, int', 'int'),\n\n (r\"\"\"\n \"\"\",\n 'Dumps', 'PyObject *, int', 'PyObject *'),\n \n \n (r\"\"\"Is the typenum valid?\n \"\"\",\n 'ValidType','int','int'), \n\n (r\"\"\"Update Several Flags at once.\n \"\"\",\n 'UpdateFlags','PyArrayObject *, int','void'),\n\n (r\"\"\"Generic new array creation routine.\n \"\"\",\n 'New','PyTypeObject *, int nd, intp *dims, int type, intp *strides, char *data, int itemsize, int fortran, PyObject *obj', 'PyObject *'),\n\n (r\"\"\"Get Priority from object\n \"\"\",\n 'GetPriority', 'PyObject *, double', 'double'),\n\n (r\"\"\"Get Iterator.\n \"\"\",\n 'IterNew','PyObject *', 'PyObject *'),\n\n (r\"\"\"Map Iterator.\n \"\"\",\n 'MapIterNew', 'PyObject *', 'PyObject *'),\n\n (r\"\"\"Bind Map Iterator\n \"\"\",\n 'MapIterBind', 'PyArrayMapIterObject *, PyArrayObject *', 'void'),\n\n (r\"\"\"Bind Map Iterator\n \"\"\",\n 'MapIterReset', 'PyArrayMapIterObject *', 'void'),\n\n (r\"\"\"\n \"\"\",\n 'MapIterNext', 'PyArrayMapIterObject *', 'void'),\n\n (r\"\"\"\n \"\"\",\n 'PyIntAsInt', 'PyObject *', 'int'),\n\n (r\"\"\"\n \"\"\",\n 'PyIntAsIntp','PyObject *', 'intp'),\n\n (r\"\"\"\n \"\"\",\n 'Broadcast', 'PyArrayMultiIterObject *', 'int'),\n\n (r\"\"\"\n \"\"\",\n 'FillObjectArray', 'PyArrayObject *, PyObject *','void'),\n\n (r\"\"\"\n \"\"\",\n 'FillWithScalar','PyArrayObject *, PyObject *', 'int'),\n\n (r\"\"\"\n \"\"\",\n 'CheckStrides', 'int, int, intp, intp *, intp *', 'Bool')\n\n ]\n\nmultiapi_list = [\n (r\"\"\"Return Transpose.\n \"\"\",\n 'Transpose','PyArrayObject *, PyObject *','PyObject *'),\n\n (r\"\"\"Take\n \"\"\",\n 'Take','PyArrayObject *, PyObject *, int axis','PyObject *'),\n\n (r\"\"\"Put values into an array\n \"\"\",\n 'Put','PyArrayObject *arr, PyObject *items, PyObject *values','PyObject *'),\n\n (r\"\"\"Put values into an array according to a mask.\n \"\"\",\n 'PutMask','PyArrayObject *arr, PyObject *mask, PyObject *values','PyObject *'),\n\n (r\"\"\"Repeat the array.\n \"\"\",\n 'Repeat','PyArrayObject *, PyObject *, int','PyObject *'),\n\n (r\"\"\"Numeric.choose()\n \"\"\",\n 'Choose','PyArrayObject *, PyObject *','PyObject *'),\n\n (r\"\"\"Sort an array\n \"\"\",\n 'Sort','PyArrayObject *, int', 'PyObject *'),\n\n (r\"\"\"ArgSort an array\n \"\"\",\n 'ArgSort','PyArrayObject *, int','PyObject *'),\n\n (r\"\"\"Numeric.searchsorted(a,v)\n \"\"\",\n 'SearchSorted','PyArrayObject *, PyObject *','PyObject *'),\n\n (r\"\"\"ArgMax\n \"\"\",\n 'ArgMax','PyArrayObject *, int','PyObject *'),\n \n (r\"\"\"ArgMin\n \"\"\",\n 'ArgMin','PyArrayObject *, int','PyObject *'),\n\n (r\"\"\"Reshape an array\n \"\"\",\n 'Reshape','PyArrayObject *, PyObject *','PyObject *'),\n\n (r\"\"\"New shape for an array\n \"\"\",\n 'Newshape','PyArrayObject *, PyArray_Dims *','PyObject *'),\n\n (r\"\"\"\n \"\"\",\n 'Squeeze','PyArrayObject *','PyObject *'),\n\n (r\"\"\"View\n \"\"\",\n 'View','PyArrayObject *, PyArray_Typecode *','PyObject *'),\n\n (r\"\"\"SwapAxes\n \"\"\",\n 'SwapAxes','PyArrayObject *, int, int','PyObject *'),\n\n (r\"\"\"Max\n \"\"\",\n 'Max','PyArrayObject *, int','PyObject *'),\n\n (r\"\"\"Min\n \"\"\",\n 'Min','PyArrayObject *, int','PyObject *'),\n\n (r\"\"\"Ptp\n \"\"\",\n 'Ptp','PyArrayObject *, int','PyObject *'),\n\n (r\"\"\"Mean\n \"\"\",\n 'Mean','PyArrayObject *, int, int','PyObject *'),\n\n (r\"\"\"Trace\n \"\"\",\n 'Trace','PyArrayObject *, int, int, int, int','PyObject *'),\n\n (r\"\"\"Diagonal\n \"\"\",\n 'Diagonal','PyArrayObject *, int, int, int','PyObject *'),\n\n (r\"\"\"Clip\n \"\"\",\n 'Clip','PyArrayObject *, PyObject *, PyObject *','PyObject *'),\n\n (r\"\"\"Conjugate\n \"\"\",\n 'Conjugate','PyArrayObject *','PyObject *'),\n\n (r\"\"\"Nonzero\n \"\"\",\n 'Nonzero','PyArrayObject *','PyObject *'),\n\n (r\"\"\"Std\n \"\"\",\n 'Std','PyArrayObject *, int, int','PyObject *'),\n\n (r\"\"\"Sum\n \"\"\",\n 'Sum','PyArrayObject *, int, int','PyObject *'),\n\n (r\"\"\"CumSum\n \"\"\",\n 'CumSum','PyArrayObject *, int, int','PyObject *'),\n\n (r\"\"\"Prod\n \"\"\",\n 'Prod','PyArrayObject *, int, int','PyObject *'),\n\n (r\"\"\"CumProd\n \"\"\",\n 'CumProd','PyArrayObject *, int, int','PyObject *'),\n\n (r\"\"\"All\n \"\"\",\n 'All','PyArrayObject *, int','PyObject *'),\n\n (r\"\"\"Any\n \"\"\",\n 'Any','PyArrayObject *, int','PyObject *'),\n\n (r\"\"\"Compress\n \"\"\",\n 'Compress','PyArrayObject *, PyObject *, int','PyObject *'),\n\n (r\"\"\"Flatten\n \"\"\",\n 'Flatten','PyArrayObject *, int','PyObject *'),\n\n (r\"\"\"Ravel\n \"\"\",\n 'Ravel','PyArrayObject *, int','PyObject *'),\n\n (r\"\"\"Multiply a List\n \"\"\",\n 'MultiplyList','intp *lp, int n','intp'),\n\n (r\"\"\"Multiply a List of ints\n \"\"\",\n 'MultiplyIntList','int *lp, int n','int'),\n\n\n (r\"\"\"Compare Lists\n \"\"\",\n 'CompareLists','intp *, intp *, int n','int'), \n\n (r\"\"\"Simulat a C-array\n \"\"\",\n \"AsCArray\",'PyObject **, void *ptr, intp *, int, int','int'),\n\n (r\"\"\"Convert to a 1D C-array\n \"\"\",\n 'As1D','PyObject **, char **ptr, int *d1, int typecode','int'),\n\n (r\"\"\"Convert to a 2D C-array\n \"\"\",\n 'As2D','PyObject **, char ***ptr, int *d1, int *d2, int typecode','int'),\n\n (r\"\"\"Free pointers created if As2D is called\n \"\"\",\n 'Free','PyObject *, void *','int'),\n\n (r\"\"\"Useful to pass as converter function for O& processing in\n PyArgs_ParseTuple.\n \"\"\",\n 'Converter','PyObject *, PyObject **','int'),\n\n (r\"\"\"PyArray_IntpFromSequence\n \"\"\",\n 'IntpFromSequence', 'PyObject *, intp *, int', 'int'), \n\n (r\"\"\"Concatenate an arbitrary Python sequence into\n an array.\n \"\"\",\n 'Concatenate','PyObject *, int','PyObject *'),\n\n (r\"\"\"Numeric.innerproduct(a,v)\n \"\"\",\n 'InnerProduct','PyObject *, PyObject *','PyObject *'),\n\n (r\"\"\"Numeric.matrixproduct(a,v)\n \"\"\",\n 'MatrixProduct','PyObject *, PyObject *','PyObject *'),\n\n (r\"\"\"Fast Copy and Transpose\n \"\"\",\n 'CopyAndTranspose','PyObject *','PyObject *'),\n\n (r\"\"\"Numeric.correlate(a1,a2,mode)\n \"\"\",\n 'Correlate','PyObject *, PyObject *, int mode','PyObject *'),\n \n (r\"\"\"Typestr converter\n \"\"\",\n 'TypestrConvert', 'int, int', 'int'),\n\n (r\"\"\"Get typenum from an object -- a converter function\n \"\"\",\n 'TypecodeConverter','PyObject *, PyArray_Typecode *', 'int'),\n\n (r\"\"\"Get intp chunk from sequence\n \"\"\",\n 'IntpConverter', 'PyObject *, PyArray_Dims *', 'int'),\n\n (r\"\"\"Get buffer chunk from object\n \"\"\",\n 'BufferConverter', 'PyObject *, PyArray_Chunk *', 'int'),\n\n (r\"\"\"Get axis from an object (possibly None) -- a converter function,\n \"\"\",\n 'AxisConverter','PyObject *, int *', 'int'),\n\n (r\"\"\"Convert an object to true / false\n \"\"\",\n 'BoolConverter','PyObject *, Bool *', 'int'),\n\n (r\"\"\"\n \"\"\",\n 'EquivalentTypes', 'PyArray_Typecode *, PyArray_Typecode *', 'Bool'),\n\n (r\"\"\"\n \"\"\",\n 'EquivArrTypes', 'PyArrayObject *, PyArrayObject *', 'Bool'),\n\n (r\"\"\"\n \"\"\",\n 'EquivalentTypenums', 'int, int', 'Bool'),\n\n (r\"\"\"Zeros\n \"\"\",\n 'Zeros', 'int, intp *, PyArray_Typecode *', 'PyObject *'),\n\n (r\"\"\"Empty\n \"\"\",\n 'Empty', 'int, intp *, PyArray_Typecode *', 'PyObject *'),\n\n\n (r\"\"\"Where\n \"\"\",\n 'Where', 'PyObject *, PyObject *, PyObject *', 'PyObject *'),\n\n (r\"\"\"Arange\n \"\"\",\n 'Arange', 'double, double, double, int', 'PyObject *')\n \n ]\n\n\ntypes = ['Generic','Numeric','Integer','SignedInteger','UnsignedInteger', 'Inexact',\n 'Floating', 'ComplexFloating', 'Flexible', 'Character',\n 'Bool','Byte','Short','Int', 'Long', 'LongLong', 'UByte', 'UShort',\n 'UInt', 'ULong', 'ULongLong', 'Float', 'Double', 'LongDouble',\n 'CFloat', 'CDouble', 'CLongDouble', 'Object', 'String', 'Unicode',\n 'Void']\n\n# API fixes for __arrayobject_api.h\n\nfixed = 5\nnumtypes = len(types) + fixed\nnumobject = len(objectapi_list) + numtypes\nnummulti = len(multiapi_list) \nnumtotal = numobject + nummulti\n\n\nmodule_list = []\nextension_list = []\ninit_list = []\n\n# setup types\nfor k, atype in enumerate(types):\n num = fixed + k\n astr = \" (void *) &Py%sArrType_Type,\" % types[k]\n init_list.append(astr)\n astr = \"static PyTypeObject Py%sArrType_Type;\" % types[k]\n module_list.append(astr)\n astr = \"#define Py%sArrType_Type (*(PyTypeObject *)PyArray_API[%d])\" % \\\n (types[k], num)\n extension_list.append(astr)\n\n\n#setup object API\nfor k, item in enumerate(objectapi_list):\n num = numtypes + k\n astr = \"static %s PyArray_%s \\\\\\n (%s);\" % \\\n (item[3],item[1],item[2])\n module_list.append(astr)\n astr = \"#define PyArray_%s \\\\\\n (*(%s (*)(%s)) \\\\\\n\"\\\n \" PyArray_API[%d])\" % (item[1],item[3],item[2],num)\n extension_list.append(astr)\n astr = \" (void *) PyArray_%s,\" % item[1]\n init_list.append(astr)\n\n \n##outstr = r\"\"\"\n###ifdef _ARRAYOBJECT\n\n##static PyTypeObject PyArray_Type;\n##static PyTypeObject PyArrayIter_Type;\n\n##%s\n\n\n###else\n\n###define PyArray_Type (*(PyTypeObject *)PyArray_API[0])\n###define PyArrayIter_Type (*(PyTypeObject *)PyArray_API[1])\n\n##%s\n\n###endif\n##\"\"\" % ('\\n'.join(module_list), '\\n'.join(extension_list))\n\n### Write out to header\n##fid = open('__arrayobject_api.h','w')\n##fid.write(outstr)\n##fid.close()\n\n\n##outstr = r\"\"\"\n##/* Export only these pointers */\n\n##void *arrayobject_API[] = {\n## (void *) &PyArray_Type,\n## (void *) &PyArrayIter_Type,\n##%s\n##};\n##\"\"\" % '\\n'.join(init_list)\n\n###Write out to c-code\n##fid = open('__arrayobject_api.c','w')\n##fid.write(outstr)\n##fid.close()\n\n\n#module_list = []\n#extension_list = []\n#init_list = []\n\n# setup multiarray module API\nfor k, item in enumerate(multiapi_list):\n num = numobject + k\n astr = \"static %s PyArray_%s \\\\\\n (%s);\" % \\\n (item[3],item[1],item[2])\n module_list.append(astr)\n astr = \"#define PyArray_%s \\\\\\n (*(%s (*)(%s)) \\\\\\n\"\\\n \" PyArray_API[%d])\" % (item[1],item[3],item[2],num)\n extension_list.append(astr)\n astr = \" (void *) PyArray_%s,\" % item[1]\n init_list.append(astr)\n\n\noutstr = r\"\"\"\n#ifdef _MULTIARRAYMODULE\n\nstatic PyTypeObject PyBigArray_Type;\nstatic PyTypeObject PyArray_Type;\nstatic PyTypeObject PyArrayIter_Type;\nstatic PyTypeObject PyArrayMapIter_Type;\nstatic int PyArray_NUMUSERTYPES=0;\n\n%s\n\n#else\n\n#if defined(PY_ARRAY_UNIQUE_SYMBOL)\n#define PyArray_API PY_ARRAY_UNIQUE_SYMBOL\n#endif\n\n#if defined(NO_IMPORT) || defined(NO_IMPORT_ARRAY)\nextern void **PyArray_API;\n#else\n#if defined(PY_ARRAY_UNIQUE_SYMBOL)\nvoid **PyArray_API;\n#else\nstatic void **PyArray_API=NULL;\n#endif\n#endif\n\n#define PyBigArray_Type (*(PyTypeObject *)PyArray_API[0])\n#define PyArray_Type (*(PyTypeObject *)PyArray_API[1])\n#define PyArrayIter_Type (*(PyTypeObject *)PyArray_API[2])\n#define PyArrayMapIter_Type (*(PyTypeObject *)PyArray_API[3])\n#define PyArray_NUMUSERTYPES (*(int *)PyArray_API[4])\n\n%s\n\n#if !defined(NO_IMPORT_ARRAY) && !defined(NO_IMPORT)\nstatic int\nimport_array(void) \n{\n PyObject *numpy = PyImport_ImportModule(\"scipy.base.multiarray\");\n PyObject *c_api = NULL;\n if (numpy == NULL) return -1;\n c_api = PyObject_GetAttrString(numpy, \"_ARRAY_API\");\n if (c_api == NULL) {Py_DECREF(numpy); return -1;}\n if (PyCObject_Check(c_api)) { \n PyArray_API = (void **)PyCObject_AsVoidPtr(c_api); \n }\n Py_DECREF(c_api);\n Py_DECREF(numpy);\n if (PyArray_API == NULL) return -1;\n return 0;\n}\n#endif\n\n#endif\n\n\"\"\" % ('\\n'.join(module_list), \n '\\n'.join(extension_list))\n\n# Write to header\nfid = open('__multiarray_api.h','w')\nfid.write(outstr)\nfid.close()\n\n\noutstr = r\"\"\"\n/* These pointers will be stored in the C-object for use in other\n extension modules\n*/\n\nvoid *PyArray_API[] = {\n (void *) &PyBigArray_Type,\n (void *) &PyArray_Type,\n (void *) &PyArrayIter_Type,\n (void *) &PyArrayMapIter_Type,\n (int *) &PyArray_NUMUSERTYPES,\n%s\n};\n\"\"\" % '\\n'.join(init_list)\n\n# Write to c-code\nfid = open('__multiarray_api.c','w')\nfid.write(outstr)\nfid.close()\n\n\n\n\n", "source_code_before": "\n# doc is comment_documentation\n\n# use list so order is preserved.\nobjectapi_list = [\n (r\"\"\"Set internal structure with number functions that all\n arrays will use\n \"\"\",\n 'SetNumericOps','PyObject *dict','int'),\n\n (r\"\"\"Get dictionary showing number functions that all\n arrays will use\n \"\"\",\n 'GetNumericOps','void','PyObject *'),\n\n\n (r\"\"\"For object arrays, increment all internal references.\n \"\"\",\n 'INCREF','PyArrayObject *','int'),\n\n (r\"\"\"Decrement all internal references for object arrays.\n \"\"\", \n 'XDECREF','PyArrayObject *','int'),\n\n (r\"\"\"Set the array print function to be a Python function.\n \"\"\",\n 'SetStringFunction','PyObject *op, int repr','void'),\n\n (r\"\"\"Get the PyArray_Descr structure for a type.\n \"\"\",\n 'DescrFromType','int','PyArray_Descr *'),\n\n (r\"\"\"Get pointer to zero of correct type for array. \n \"\"\",\n 'Zero', 'PyArrayObject *', 'char *'),\n\n (r\"\"\"Get pointer to one of correct type for array\n \"\"\",\n 'One', 'PyArrayObject *', 'char *'),\n\n\n (r\"\"\"Cast an array to a different type.\n \"\"\",\n 'Cast','PyArrayObject *, int','PyObject *'),\n\n (r\"\"\"Cast an array using typecode structure.\n \"\"\",\n 'CastToType','PyArrayObject *, PyArray_Typecode *','PyObject *'),\n\n (r\"\"\"Cast to an already created array.\n \"\"\",\n 'CastTo', 'PyArrayObject *, PyArrayObject *', 'int'),\n\n (r\"\"\"Check the type coercion rules.\n \"\"\",\n 'CanCastSafely','int fromtype, int totype','int'),\n\n (r\"\"\"\n \"\"\",\n 'CanCastTo','PyArray_Typecode *, PyArray_Typecode *', 'Bool'),\n\n (r\"\"\"Return the typecode of the array a Python object would be\n converted to\n \"\"\",\n 'ObjectType','PyObject *, int','int'),\n\n (r\"\"\"\n \"\"\",\n 'ArrayType','PyObject *, PyArray_Typecode *, PyArray_Typecode *','void'),\n\n (r\"\"\"Return type typecode from array scalar.\n \"\"\",\n 'TypecodeFromScalar','PyObject *, PyArray_Typecode *','void'),\n\n (r\"\"\"Compute the size of an array (in number of items)\n \"\"\",\n 'Size','PyObject *','intp'),\n\n (r\"\"\"Get scalar-equivalent to 0-d array\n \"\"\",\n 'Scalar', 'char *, int, int, int', 'PyObject *'),\n\n (r\"\"\"Get scalar-equivalent to 0-d array\n \"\"\",\n 'ToScalar', 'char *, PyArrayObject *', 'PyObject *'),\n\n (r\"\"\"Get 0-dim array from scalar\n \"\"\",\n 'FromScalar', 'PyObject *, PyArray_Typecode *', 'PyObject *'),\n\n (r\"\"\"Convert to c-type\n \"\"\",\n 'ScalarAsCtype', 'PyObject *, void *', 'void'),\n\n (r\"\"\"Register Data type\n \"\"\",\n 'RegisterDataType', 'PyTypeObject *', 'int'),\n\n (r\"\"\"Insert Descr Table\n \"\"\",\n 'RegisterDescrForType', 'int, PyArray_Descr *', 'int'),\n \n (r\"\"\"Construct an empty array from dimensions and typenum\n \"\"\",\n 'FromDims','int nd, int *, int typenum','PyObject *'),\n\n (r\"\"\"Construct an array from dimensions, typenum, and a pointer\n to the data. Python will never free this (unless you later set\n the OWN_DATA flag). \n \"\"\",\n 'FromDimsAndData','int, int *, int, char *','PyObject *'),\n\n (r\"\"\"Construct an array from an arbitrary Python Object.\n Last two integers are min_dimensions, and max_dimensions.\n If max_dimensions = 0, then any number of dimensions are allowed.\n Fix the dimension by setting min_dimension == max_dimension.\n If the array is already contiguous (and aligned and not swapped)\n no copy is done, just a new reference created.\n Base-class ndarray is returned.\n \"\"\",\n 'ContiguousFromObject',\n 'PyObject *, int typenum, int, int',\n 'PyObject *'),\n\n (r\"\"\"Construct an array from an arbitrary Python Object.\n Last two integers are min_dimensions, and max_dimensions.\n If max_dimensions = 0, then any number of dimensions are allowed.\n Fix the dimension by setting min_dimension == max_dimension.\n If the array is already contiguous (and aligned and not swapped)\n no copy is done, just a new reference created. Subclasses\n passed through.\n \"\"\",\n 'ContiguousFromAny',\n 'PyObject *, int typenum, int, int',\n 'PyObject *'),\n \n\n (r\"\"\"Same as ContiguousFromObject except ensure a copy.\n \"\"\",\n 'CopyFromObject','PyObject *, int, int, int','PyObject *'),\n\n (r\"\"\"Can return a discontiguous array (but aligned and byteswapped)\n \"\"\",\n 'FromObject','PyObject *, int, int, int','PyObject *'),\n\n (r\"\"\"\n \"\"\",\n 'FromAny', 'PyObject *, PyArray_Typecode *, int, int, int', 'PyObject *'),\n\n (r\"\"\"\n \"\"\",\n 'EnsureArray', 'PyObject *', 'PyObject *'),\n\n (r\"\"\"\n \"\"\",\n 'FromFile', 'FILE *, PyArray_Typecode *, intp, char *','PyObject *'),\n\n (r\"\"\"\n \"\"\",\n 'FromBuffer', 'PyObject *, PyArray_Typecode *, intp, int','PyObject *'),\n\n (r\"\"\"Return either an array or the appropriate Python object if the\n array is 0d and matches a Python type.\n \"\"\",\n 'Return','PyArrayObject *','PyObject *'),\n\n (r\"\"\"Get a subset of bytes from each element of the array\n \"\"\",\n 'GetField', 'PyArrayObject *, PyArray_Typecode *, int', 'PyObject *'),\n\n (r\"\"\"\n \"\"\",\n 'Byteswap', 'PyArrayObject *, Bool', 'PyObject *'),\n\n (r\"\"\"Resize (reallocate data). Only works if nothing else is\n referencing this array and it is contiguous.\n \"\"\",\n 'Resize','PyArrayObject *ap, PyArray_Dims *newshape','PyObject *'),\n\n (r\"\"\"Copy an array.\n \"\"\",\n 'Copy','PyArrayObject *','PyObject *'),\n\n (r\"\"\"Like FromDimsAndData but uses the Descr structure instead of\n typecode as input.\n \"\"\",\n 'FromDimsAndDataAndDescr','int, int *, PyArray_Descr *, char *',\n 'PyObject *'),\n\n (r\"\"\"Copy an Array into another array.\n \"\"\",\n 'CopyInto', 'PyArrayObject *dest, PyArrayObject *src', 'int'),\n\n (r\"\"\"To List\n \"\"\",\n 'ToList','PyArrayObject *', 'PyObject *'),\n\n (r\"\"\"To File\n \"\"\",\n 'ToFile','PyArrayObject *, FILE *, char *, char *', 'int'),\n\n (r\"\"\"\n \"\"\",\n 'Dump', 'PyObject *, PyObject *, int', 'int'),\n\n (r\"\"\"\n \"\"\",\n 'Dumps', 'PyObject *, int', 'PyObject *'),\n \n \n (r\"\"\"Is the typenum valid?\n \"\"\",\n 'ValidType','int','int'), \n\n (r\"\"\"Update Several Flags at once.\n \"\"\",\n 'UpdateFlags','PyArrayObject *, int','void'),\n\n (r\"\"\"Generic new array creation routine.\n \"\"\",\n 'New','PyTypeObject *, int nd, intp *dims, int type, intp *strides, char *data, int itemsize, int fortran, PyObject *obj', 'PyObject *'),\n\n (r\"\"\"Get Priority from object\n \"\"\",\n 'GetPriority', 'PyObject *, double', 'double'),\n\n (r\"\"\"Get Iterator.\n \"\"\",\n 'IterNew','PyObject *', 'PyObject *'),\n\n (r\"\"\"Map Iterator.\n \"\"\",\n 'MapIterNew', 'PyObject *', 'PyObject *'),\n\n (r\"\"\"Bind Map Iterator\n \"\"\",\n 'MapIterBind', 'PyArrayMapIterObject *, PyArrayObject *', 'void'),\n\n (r\"\"\"Bind Map Iterator\n \"\"\",\n 'MapIterReset', 'PyArrayMapIterObject *', 'void'),\n\n (r\"\"\"\n \"\"\",\n 'MapIterNext', 'PyArrayMapIterObject *', 'void'),\n\n (r\"\"\"\n \"\"\",\n 'PyIntAsInt', 'PyObject *', 'int'),\n\n (r\"\"\"\n \"\"\",\n 'PyIntAsIntp','PyObject *', 'intp'),\n\n (r\"\"\"\n \"\"\",\n 'Broadcast', 'PyArrayMultiIterObject *', 'int'),\n\n (r\"\"\"\n \"\"\",\n 'FillObjectArray', 'PyArrayObject *, PyObject *','void'),\n\n (r\"\"\"\n \"\"\",\n 'FillWithScalar','PyArrayObject *, PyObject *', 'int'),\n\n (r\"\"\"\n \"\"\",\n 'CheckStrides', 'int, int, intp, intp *, intp *', 'Bool')\n\n ]\n\nmultiapi_list = [\n (r\"\"\"Return Transpose.\n \"\"\",\n 'Transpose','PyArrayObject *, PyObject *','PyObject *'),\n\n (r\"\"\"Take\n \"\"\",\n 'Take','PyArrayObject *, PyObject *, int axis','PyObject *'),\n\n (r\"\"\"Put values into an array\n \"\"\",\n 'Put','PyArrayObject *arr, PyObject *items, PyObject *values','PyObject *'),\n\n (r\"\"\"Put values into an array according to a mask.\n \"\"\",\n 'PutMask','PyArrayObject *arr, PyObject *mask, PyObject *values','PyObject *'),\n\n (r\"\"\"Repeat the array.\n \"\"\",\n 'Repeat','PyArrayObject *, PyObject *, int','PyObject *'),\n\n (r\"\"\"Numeric.choose()\n \"\"\",\n 'Choose','PyArrayObject *, PyObject *','PyObject *'),\n\n (r\"\"\"Sort an array\n \"\"\",\n 'Sort','PyArrayObject *, int', 'PyObject *'),\n\n (r\"\"\"ArgSort an array\n \"\"\",\n 'ArgSort','PyArrayObject *, int','PyObject *'),\n\n (r\"\"\"Numeric.searchsorted(a,v)\n \"\"\",\n 'SearchSorted','PyArrayObject *, PyObject *','PyObject *'),\n\n (r\"\"\"ArgMax\n \"\"\",\n 'ArgMax','PyArrayObject *, int','PyObject *'),\n \n (r\"\"\"ArgMin\n \"\"\",\n 'ArgMin','PyArrayObject *, int','PyObject *'),\n\n (r\"\"\"Reshape an array\n \"\"\",\n 'Reshape','PyArrayObject *, PyObject *','PyObject *'),\n\n (r\"\"\"New shape for an array\n \"\"\",\n 'Newshape','PyArrayObject *, PyArray_Dims *','PyObject *'),\n\n (r\"\"\"\n \"\"\",\n 'Squeeze','PyArrayObject *','PyObject *'),\n\n (r\"\"\"View\n \"\"\",\n 'View','PyArrayObject *, PyArray_Typecode *','PyObject *'),\n\n (r\"\"\"SwapAxes\n \"\"\",\n 'SwapAxes','PyArrayObject *, int, int','PyObject *'),\n\n (r\"\"\"Max\n \"\"\",\n 'Max','PyArrayObject *, int','PyObject *'),\n\n (r\"\"\"Min\n \"\"\",\n 'Min','PyArrayObject *, int','PyObject *'),\n\n (r\"\"\"Ptp\n \"\"\",\n 'Ptp','PyArrayObject *, int','PyObject *'),\n\n (r\"\"\"Mean\n \"\"\",\n 'Mean','PyArrayObject *, int, int','PyObject *'),\n\n (r\"\"\"Trace\n \"\"\",\n 'Trace','PyArrayObject *, int, int, int, int','PyObject *'),\n\n (r\"\"\"Diagonal\n \"\"\",\n 'Diagonal','PyArrayObject *, int, int, int','PyObject *'),\n\n (r\"\"\"Clip\n \"\"\",\n 'Clip','PyArrayObject *, PyObject *, PyObject *','PyObject *'),\n\n (r\"\"\"Conjugate\n \"\"\",\n 'Conjugate','PyArrayObject *','PyObject *'),\n\n (r\"\"\"Nonzero\n \"\"\",\n 'Nonzero','PyArrayObject *','PyObject *'),\n\n (r\"\"\"Std\n \"\"\",\n 'Std','PyArrayObject *, int, int','PyObject *'),\n\n (r\"\"\"Sum\n \"\"\",\n 'Sum','PyArrayObject *, int, int','PyObject *'),\n\n (r\"\"\"CumSum\n \"\"\",\n 'CumSum','PyArrayObject *, int, int','PyObject *'),\n\n (r\"\"\"Prod\n \"\"\",\n 'Prod','PyArrayObject *, int, int','PyObject *'),\n\n (r\"\"\"CumProd\n \"\"\",\n 'CumProd','PyArrayObject *, int, int','PyObject *'),\n\n (r\"\"\"All\n \"\"\",\n 'All','PyArrayObject *, int','PyObject *'),\n\n (r\"\"\"Any\n \"\"\",\n 'Any','PyArrayObject *, int','PyObject *'),\n\n (r\"\"\"Compress\n \"\"\",\n 'Compress','PyArrayObject *, PyObject *, int','PyObject *'),\n\n (r\"\"\"Flatten\n \"\"\",\n 'Flatten','PyArrayObject *, int','PyObject *'),\n\n (r\"\"\"Ravel\n \"\"\",\n 'Ravel','PyArrayObject *, int','PyObject *'),\n\n (r\"\"\"Multiply a List\n \"\"\",\n 'MultiplyList','intp *lp, int n','intp'),\n\n (r\"\"\"Multiply a List of ints\n \"\"\",\n 'MultiplyIntList','int *lp, int n','int'),\n\n\n (r\"\"\"Compare Lists\n \"\"\",\n 'CompareLists','intp *, intp *, int n','int'), \n\n (r\"\"\"Simulat a C-array\n \"\"\",\n \"AsCArray\",'PyObject **, void *ptr, intp *, int, int','int'),\n\n (r\"\"\"Convert to a 1D C-array\n \"\"\",\n 'As1D','PyObject **, char **ptr, int *d1, int typecode','int'),\n\n (r\"\"\"Convert to a 2D C-array\n \"\"\",\n 'As2D','PyObject **, char ***ptr, int *d1, int *d2, int typecode','int'),\n\n (r\"\"\"Free pointers created if As2D is called\n \"\"\",\n 'Free','PyObject *, void *','int'),\n\n (r\"\"\"Useful to pass as converter function for O& processing in\n PyArgs_ParseTuple.\n \"\"\",\n 'Converter','PyObject *, PyObject **','int'),\n\n (r\"\"\"PyArray_IntpFromSequence\n \"\"\",\n 'IntpFromSequence', 'PyObject *, intp *, int', 'int'), \n\n (r\"\"\"Concatenate an arbitrary Python sequence into\n an array.\n \"\"\",\n 'Concatenate','PyObject *, int','PyObject *'),\n\n (r\"\"\"Numeric.innerproduct(a,v)\n \"\"\",\n 'InnerProduct','PyObject *, PyObject *','PyObject *'),\n\n (r\"\"\"Numeric.matrixproduct(a,v)\n \"\"\",\n 'MatrixProduct','PyObject *, PyObject *','PyObject *'),\n\n (r\"\"\"Fast Copy and Transpose\n \"\"\",\n 'CopyAndTranspose','PyObject *','PyObject *'),\n\n (r\"\"\"Numeric.correlate(a1,a2,mode)\n \"\"\",\n 'Correlate','PyObject *, PyObject *, int mode','PyObject *'),\n \n (r\"\"\"Typestr converter\n \"\"\",\n 'TypestrConvert', 'int, int', 'int'),\n\n (r\"\"\"Get typenum from an object -- a converter function\n \"\"\",\n 'TypecodeConverter','PyObject *, PyArray_Typecode *', 'int'),\n\n (r\"\"\"Get intp chunk from sequence\n \"\"\",\n 'IntpConverter', 'PyObject *, PyArray_Dims *', 'int'),\n\n (r\"\"\"Get buffer chunk from object\n \"\"\",\n 'BufferConverter', 'PyObject *, PyArray_Chunk *', 'int'),\n\n (r\"\"\"Get axis from an object (possibly None) -- a converter function,\n \"\"\",\n 'AxisConverter','PyObject *, int *', 'int'),\n\n (r\"\"\"Convert an object to true / false\n \"\"\",\n 'BoolConverter','PyObject *, Bool *', 'int'),\n\n (r\"\"\"\n \"\"\",\n 'EquivalentTypes', 'PyArray_Typecode *, PyArray_Typecode *', 'Bool'),\n\n (r\"\"\"\n \"\"\",\n 'EquivArrTypes', 'PyArrayObject *, PyArrayObject *', 'Bool'),\n\n (r\"\"\"Zeros\n \"\"\",\n 'Zeros', 'int, intp *, PyArray_Typecode *', 'PyObject *'),\n\n (r\"\"\"Empty\n \"\"\",\n 'Empty', 'int, intp *, PyArray_Typecode *', 'PyObject *'),\n\n\n (r\"\"\"Where\n \"\"\",\n 'Where', 'PyObject *, PyObject *, PyObject *', 'PyObject *'),\n\n (r\"\"\"Arange\n \"\"\",\n 'Arange', 'double, double, double, int', 'PyObject *')\n \n ]\n\n\ntypes = ['Generic','Numeric','Integer','SignedInteger','UnsignedInteger', 'Inexact',\n 'Floating', 'ComplexFloating', 'Flexible', 'Character',\n 'Bool','Byte','Short','Int', 'Long', 'LongLong', 'UByte', 'UShort',\n 'UInt', 'ULong', 'ULongLong', 'Float', 'Double', 'LongDouble',\n 'CFloat', 'CDouble', 'CLongDouble', 'Object', 'String', 'Unicode',\n 'Void']\n\n# API fixes for __arrayobject_api.h\n\nfixed = 5\nnumtypes = len(types) + fixed\nnumobject = len(objectapi_list) + numtypes\nnummulti = len(multiapi_list) \nnumtotal = numobject + nummulti\n\n\nmodule_list = []\nextension_list = []\ninit_list = []\n\n# setup types\nfor k, atype in enumerate(types):\n num = fixed + k\n astr = \" (void *) &Py%sArrType_Type,\" % types[k]\n init_list.append(astr)\n astr = \"static PyTypeObject Py%sArrType_Type;\" % types[k]\n module_list.append(astr)\n astr = \"#define Py%sArrType_Type (*(PyTypeObject *)PyArray_API[%d])\" % \\\n (types[k], num)\n extension_list.append(astr)\n\n\n#setup object API\nfor k, item in enumerate(objectapi_list):\n num = numtypes + k\n astr = \"static %s PyArray_%s \\\\\\n (%s);\" % \\\n (item[3],item[1],item[2])\n module_list.append(astr)\n astr = \"#define PyArray_%s \\\\\\n (*(%s (*)(%s)) \\\\\\n\"\\\n \" PyArray_API[%d])\" % (item[1],item[3],item[2],num)\n extension_list.append(astr)\n astr = \" (void *) PyArray_%s,\" % item[1]\n init_list.append(astr)\n\n \n##outstr = r\"\"\"\n###ifdef _ARRAYOBJECT\n\n##static PyTypeObject PyArray_Type;\n##static PyTypeObject PyArrayIter_Type;\n\n##%s\n\n\n###else\n\n###define PyArray_Type (*(PyTypeObject *)PyArray_API[0])\n###define PyArrayIter_Type (*(PyTypeObject *)PyArray_API[1])\n\n##%s\n\n###endif\n##\"\"\" % ('\\n'.join(module_list), '\\n'.join(extension_list))\n\n### Write out to header\n##fid = open('__arrayobject_api.h','w')\n##fid.write(outstr)\n##fid.close()\n\n\n##outstr = r\"\"\"\n##/* Export only these pointers */\n\n##void *arrayobject_API[] = {\n## (void *) &PyArray_Type,\n## (void *) &PyArrayIter_Type,\n##%s\n##};\n##\"\"\" % '\\n'.join(init_list)\n\n###Write out to c-code\n##fid = open('__arrayobject_api.c','w')\n##fid.write(outstr)\n##fid.close()\n\n\n#module_list = []\n#extension_list = []\n#init_list = []\n\n# setup multiarray module API\nfor k, item in enumerate(multiapi_list):\n num = numobject + k\n astr = \"static %s PyArray_%s \\\\\\n (%s);\" % \\\n (item[3],item[1],item[2])\n module_list.append(astr)\n astr = \"#define PyArray_%s \\\\\\n (*(%s (*)(%s)) \\\\\\n\"\\\n \" PyArray_API[%d])\" % (item[1],item[3],item[2],num)\n extension_list.append(astr)\n astr = \" (void *) PyArray_%s,\" % item[1]\n init_list.append(astr)\n\n\noutstr = r\"\"\"\n#ifdef _MULTIARRAYMODULE\n\nstatic PyTypeObject PyBigArray_Type;\nstatic PyTypeObject PyArray_Type;\nstatic PyTypeObject PyArrayIter_Type;\nstatic PyTypeObject PyArrayMapIter_Type;\nstatic int PyArray_NUMUSERTYPES=0;\n\n%s\n\n#else\n\n#if defined(PY_ARRAY_UNIQUE_SYMBOL)\n#define PyArray_API PY_ARRAY_UNIQUE_SYMBOL\n#endif\n\n#if defined(NO_IMPORT) || defined(NO_IMPORT_ARRAY)\nextern void **PyArray_API;\n#else\n#if defined(PY_ARRAY_UNIQUE_SYMBOL)\nvoid **PyArray_API;\n#else\nstatic void **PyArray_API=NULL;\n#endif\n#endif\n\n#define PyBigArray_Type (*(PyTypeObject *)PyArray_API[0])\n#define PyArray_Type (*(PyTypeObject *)PyArray_API[1])\n#define PyArrayIter_Type (*(PyTypeObject *)PyArray_API[2])\n#define PyArrayMapIter_Type (*(PyTypeObject *)PyArray_API[3])\n#define PyArray_NUMUSERTYPES (*(int *)PyArray_API[4])\n\n%s\n\n#if !defined(NO_IMPORT_ARRAY) && !defined(NO_IMPORT)\nstatic int\nimport_array(void) \n{\n PyObject *numpy = PyImport_ImportModule(\"scipy.base.multiarray\");\n PyObject *c_api = NULL;\n if (numpy == NULL) return -1;\n c_api = PyObject_GetAttrString(numpy, \"_ARRAY_API\");\n if (c_api == NULL) {Py_DECREF(numpy); return -1;}\n if (PyCObject_Check(c_api)) { \n PyArray_API = (void **)PyCObject_AsVoidPtr(c_api); \n }\n Py_DECREF(c_api);\n Py_DECREF(numpy);\n if (PyArray_API == NULL) return -1;\n return 0;\n}\n#endif\n\n#endif\n\n\"\"\" % ('\\n'.join(module_list), \n '\\n'.join(extension_list))\n\n# Write to header\nfid = open('__multiarray_api.h','w')\nfid.write(outstr)\nfid.close()\n\n\noutstr = r\"\"\"\n/* These pointers will be stored in the C-object for use in other\n extension modules\n*/\n\nvoid *PyArray_API[] = {\n (void *) &PyBigArray_Type,\n (void *) &PyArray_Type,\n (void *) &PyArrayIter_Type,\n (void *) &PyArrayMapIter_Type,\n (int *) &PyArray_NUMUSERTYPES,\n%s\n};\n\"\"\" % '\\n'.join(init_list)\n\n# Write to c-code\nfid = open('__multiarray_api.c','w')\nfid.write(outstr)\nfid.close()\n\n\n\n\n", "methods": [], "methods_before": [], "changed_methods": [], "nloc": 515, "complexity": 0, "token_count": 1747, "diff_parsed": { "added": [ " (r\"\"\"", " \"\"\",", " 'EquivalentTypenums', 'int, int', 'Bool'),", "" ], "deleted": [] } }, { "old_path": "scipy/base/src/multiarraymodule.c", "new_path": "scipy/base/src/multiarraymodule.c", "filename": "multiarraymodule.c", "extension": "c", "change_type": "MODIFY", "diff": "@@ -2853,6 +2853,21 @@ PyArray_EquivArrTypes(PyArrayObject *a1, PyArrayObject *a2)\n return PyArray_EquivalentTypes(&type1, &type2);\n }\n \n+/* All flexible types of the same typenum seen as equivalent */\n+static Bool\n+PyArray_EquivalentTypenums(int typenum1, int typenum2)\n+{\n+\tPyArray_Typecode type1={0,0,0};\n+\tPyArray_Typecode type2={0,0,0};\n+\t\n+\ttype1.type_num = typenum1;\n+\ttype2.type_num = typenum2;\n+\ttype1.itemsize = PyArray_DescrFromType(typenum1)->elsize;\n+\ttype2.itemsize = PyArray_DescrFromType(typenum2)->elsize;\n+\t\n+\treturn PyArray_EquivalentTypes(&type1, &type2);\n+}\n+\n \n /*** END C-API FUNCTIONS **/\n \n", "added_lines": 15, "deleted_lines": 0, "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 for scipy_core in 2005 \n\n Travis E. Oliphant\n Assistant Professor at\n Brigham Young University\n \n*/\n\n/* $Id: multiarraymodule.c,v 1.36 2005/09/14 00:14:00 teoliphant Exp $ */\n\n#include \"Python.h\"\n#include \"structmember.h\"\n/*#include \n#include \n*/\n\n#define _MULTIARRAYMODULE\n#include \"scipy/arrayobject.h\"\n\n#define PyAO PyArrayObject\n\nstatic PyObject *typeDict=NULL; /* Must be explicitly loaded */\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\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\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\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\nstatic int \nPyArray_CompareLists(intp *l1, intp *l2, int n) \n{\n int i;\n for(i=0;itype_num;\n\t}\n\n\tnew = PyArray_New(self->ob_type,\n\t\t\t self->nd, self->dimensions,\n\t\t\t self->descr->type_num,\n\t\t\t self->strides,\n\t\t\t self->data,\n\t\t\t self->itemsize,\n\t\t\t self->flags, (PyObject *)self);\n\n\tif (new==NULL) return NULL;\n\t\n Py_INCREF(self);\n PyArray_BASE(new) = (PyObject *)self;\n if ((type_num != PyArray_NOTYPE) && \\\n (type_num != self->descr->type_num)) {\n if (!PyTypeNum_ISFLEXIBLE(type_num)) {\n v = PyArray_TypeObjectFromType(type_num);\n }\n else {\n PyArray_Descr *descr;\n int itemsize = type->itemsize;\n descr = PyArray_DescrFromType(type_num);\n if (type_num == PyArray_UNICODE) \n itemsize /= sizeof(Py_UNICODE);\n /* construct a string representation */\n v = PyString_FromFormat(\"%c%d\", descr->type, \n itemsize);\n }\n if (v == NULL) goto fail;\n /* set attribute new.dtype = newtype */\n if (PyObject_SetAttrString(new, \"dtype\", v) < 0) goto fail;\n Py_DECREF(v);\n }\n\treturn new;\t\n\n fail:\n Py_XDECREF(v);\n Py_XDECREF(new);\n return NULL;\n}\n\nstatic PyObject *\nPyArray_Ravel(PyArrayObject *a, int fortran)\n{\n\tPyArray_Dims newdim = {NULL,1};\n\tintp val[1] = {-1};\n\n if (a->nd == 1) {\n Py_INCREF(a);\n return (PyObject *)a;\n }\n\tnewdim.ptr = val;\n\tif (!fortran && PyArray_ISCONTIGUOUS(a)) \n\t\treturn PyArray_Newshape(a, &newdim);\n\telse\n\t return PyArray_Flatten(a, fortran);\n}\n\nstatic PyObject *\nPyArray_Flatten(PyArrayObject *a, int fortran)\n{\n\tPyObject *ret, *new;\n\tintp size;\n\n\tsize = PyArray_SIZE(a);\n\tret = PyArray_New(a->ob_type,\n\t\t\t 1, &size,\n\t\t\t a->descr->type_num,\n\t\t\t NULL,\n NULL,\n\t\t\t a->itemsize,\n\t\t\t 0, (PyObject *)a);\n\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\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\tgoto fail;\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\tgoto fail;\n\t\t\t}\n\t\t}\n\t}\n \n\tret = (PyAO *)PyArray_New(self->ob_type,\n\t\t\t\t n, dimensions,\n\t\t\t\t self->descr->type_num,\n\t\t\t\t strides,\n\t\t\t\t self->data,\n\t\t\t\t self->itemsize,\n\t\t\t\t self->flags, (PyObject *)self);\n\t\n\tif (ret== NULL)\n goto fail;\n\t\n Py_INCREF(self);\n ret->base = (PyObject *)self;\n\tPyArray_UpdateFlags(ret, CONTIGUOUS | FORTRAN);\n\t\n return (PyObject *)ret;\n\t\n fail:\n return NULL;\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\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\tret = PyArray_New(self->ob_type, newnd, dimensions, \n\t\t\t self->descr->type_num, strides,\n\t\t\t self->data, self->itemsize, self->flags,\n\t\t\t (PyObject *)self);\n\tself->flags &= ~OWN_DATA;\n\tself->base = (PyObject *)self;\n\tPy_INCREF(self);\n\treturn (PyObject *)ret;\n}\n\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\nstatic PyObject *\nPyArray_Std(PyArrayObject *self, int axis, int rtype)\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\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->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->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\tPyTuple_SET_ITEM(ret, j, item);\n\t\t\tif (item == NULL) goto fail;\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->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\treturn ret;\n\n fail:\n\tPy_XDECREF(ret);\n\tPy_XDECREF(it);\n\treturn NULL;\n \n}\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)) goto fail;\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) goto fail;\n\tret = PyArray_Choose((PyAO *)selector, newtup);\n\tPy_DECREF(selector);\n\tPy_DECREF(newtup);\n\treturn ret;\n\n fail:\n\tPy_XDECREF(res1);\n\tPy_XDECREF(res2);\n\tPy_XDECREF(two);\n\tPy_XDECREF(selector);\n\treturn NULL;\n}\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_Copy(self);\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\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\nstatic PyObject *\nPyArray_Diagonal(PyArrayObject *self, int offset, int axis1, int axis2)\n{\n\tint n = self->nd;\n\tPyObject *new;\n\tPyObject *newaxes;\n\tint i, pos;\t\n\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 = PyTuple_New(n);\n\tif (newaxes==NULL) return NULL;\n\t/* insert at the end */\n\tPyTuple_SET_ITEM(newaxes, n-2, PyInt_FromLong((long)axis1));\n\tPyTuple_SET_ITEM(newaxes, n-1, PyInt_FromLong((long)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->type_num;\n\t\ttypecode.itemsize = self->itemsize;\n\t\ttypecode.fortran = 0;\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\treturn -1;\n\t}\n\tif ((ap = (PyArrayObject*)PyArray_FromAny(*op, &typecode, nd, nd,\n\t\t\t\t\t\t CARRAY_FLAGS)) == NULL)\n\t\treturn -1;\n\tswitch(nd) {\n\tcase 1:\n\t\t*((char **)ptr) = ap->data;\n\t\tbreak;\n\tcase 2:\n\t\tn = ap->dimensions[0];\n\t\tptr2 = (char **)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 ***)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\nstatic int \nPyArray_As1D(PyObject **op, char **ptr, int *d1, int typecode) \n{\n\tintp newd1;\n\t\n\tif (PyArray_AsCArray(op, (void *)ptr, &newd1, 1, typecode) == -1)\n\t\treturn -1;\t\n\t*d1 = (int) newd1;\n\treturn 0;\n}\n\n\nstatic int \nPyArray_As2D(PyObject **op, char ***ptr, int *d1, int *d2, int typecode) \n{\n\tintp newdims[2];\n\n\tif (PyArray_AsCArray(op, (void *)ptr, newdims, 2, typecode) == -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\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\tfree(ptr);\n }\n Py_DECREF(ap);\n return 0;\n}\n\n\nstatic PyObject *\n_swap_and_concat(PyObject *op, int axis, int n)\n{\n\tPyObject *newtup=NULL;\n\tPyObject *otmp, *arr;\n\tint i;\n\n\tnewtup = PyTuple_New(n);\n\tif (newtup==NULL) return NULL;\n\tfor (i=0; i= MAX_DIMS) {\n\t\t\totmp = PyArray_Ravel(mps[i],0);\n\t\t\tPy_DECREF(mps[i]);\n\t\t\tmps[i] = (PyArrayObject *)otmp;\n\t\t}\n\t\tprior2 = PyArray_GetPriority((PyObject *)(mps[i]), 0.0);\n\t\tif (prior2 > prior1) {\n\t\t\tprior1 = prior2;\n\t\t\tsubtype = mps[i]->ob_type;\n\t\t\tret = mps[i];\n\t\t}\n\t}\n\t\n\tnew_dim = 0;\n\tfor(i=0; ind;\n\t\telse {\n\t\t\tif (nd != mps[i]->nd) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"arrays must have same \"\\\n\t\t\t\t\t\t\"number of dimensions\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CompareLists(mps[0]->dimensions+1, \n\t\t\t\t\t\t mps[i]->dimensions+1, \n\t\t\t\t\t\t nd-1)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"array dimensions must \"\\\n\t\t\t\t\t\t\"agree except for d_0\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t}\n\t\tif (nd == 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"0-d arrays can't be concatenated\");\n\t\t\tgoto fail;\n\t\t}\n\t\tnew_dim += mps[i]->dimensions[0];\n\t}\n\t\n\ttmp = mps[0]->dimensions[0];\n\tmps[0]->dimensions[0] = new_dim;\n\tret = (PyArrayObject *)PyArray_New(subtype, nd,\n\t\t\t\t\t mps[0]->dimensions, \n\t\t\t\t\t type_num, NULL, NULL, 0, 0,\n (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 = PyTuple_New(n);\n\tfor (i=0; ind;\n\t\tpermutation = (intp *)malloc(n*sizeof(int));\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\tgoto fail;\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\tret = (PyArrayObject *)PyArray_New(ap->ob_type, n, permutation, \n\t\t\t\t\t ap->descr->type_num, NULL,\n\t\t\t\t\t ap->data, ap->itemsize, ap->flags,\n\t\t\t\t\t (PyObject *)ap);\n\tif (ret == NULL) goto fail;\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);\n\t\n\tif (op && (op != Py_None))\n\t\tPyArray_Free(op, (char *)axes);\n\tfree(permutation);\n\treturn (PyObject *)ret;\n\t\n fail:\n\tPy_XDECREF(ret);\n\tif (permutation != NULL) free(permutation);\n\tif (op != Py_None)\n\t\tPyArray_Free(op, (char *)axes);\n\treturn NULL;\n}\n\nstatic PyObject *\nPyArray_Repeat(PyArrayObject *aop, PyObject *op, int axis) {\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\tret = (PyArrayObject *)PyArray_New(aop->ob_type, aop->nd,\n\t\t\t\t\t aop->dimensions, \n\t\t\t\t\t aop->descr->type_num,\n\t\t\t\t\t NULL, NULL, aop->itemsize, 0,\n\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->itemsize;\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\t/* why not ??? \n\tif (PyTypeNum_ISFLEXIBLE(type_num)) {\n\t\tPyErr_SetString(PyExc_NotImplementedError, \n\t\t\t\t\"not implemented for flexible sizes\");\n\t\treturn NULL;\n\t}\n\t*/\n\tret = (PyArrayObject *)PyArray_New(ap->ob_type, ap->nd,\n\t\t\t\t\t ap->dimensions, type_num,\n\t\t\t\t\t NULL, NULL, 0, 0, (PyObject *)ap);\n\tif (ret == NULL) goto fail;\n\t\n\telsize = ret->itemsize;\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->compare(a,b,global_obj);\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#define SWAPBACK(op, ap) { \\\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\nstatic PyObject *\nPyArray_Sort(PyArrayObject *op, int axis) \n{\n\tPyArrayObject *ap=NULL, *store_arr=NULL;\n\tchar *ip;\n\tint i, n, m, elsize, orign;\n\n\tif ((ap = (PyAO*) _check_axis(op, &axis, 0))==NULL) return NULL;\n\n\tSWAPAXES(op, ap);\n\n\tap = (PyArrayObject *)PyArray_CopyFromObject((PyObject *)op, \n\t\t\t\t\t\t PyArray_NOTYPE,\n\t\t\t\t\t\t 1, 0);\n\tPy_DECREF(op);\n\n\tif (ap == NULL) return NULL;\n\n\tif (ap->descr->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"compare not supported for type\");\n\t\tPy_DECREF(ap);\n\t\treturn NULL;\n\t}\n\t\n\telsize = ap->itemsize;\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; iitemsize;\n\tconst intp *ipa = ip1;\n\tconst intp *ipb = ip2;\t\n\treturn global_obj->descr->compare(global_data + (isize * *ipa),\n global_data + (isize * *ipb), \n\t\t\t\t\t global_obj);\n}\n\nstatic PyObject *\nPyArray_ArgSort(PyArrayObject *op, int axis) \n{\n\tPyArrayObject *ap, *ret, *store;\n\tintp *ip;\n\tintp i, j, n, m, orign;\n\tint argsort_elsize;\n\tchar *store_ptr;\n\n\tif ((ap = (PyAO *)_check_axis(op, &axis, 0))==NULL) return NULL;\n\n\tSWAPAXES(op, ap);\n\n\tap = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)op, \n\t\t\t\t\t\t\t PyArray_NOTYPE,\n\t\t\t\t\t\t\t 1, 0);\n\tPy_DECREF(op);\n\n\tif (ap == NULL) return NULL;\n\t\n\tret = (PyArrayObject *)PyArray_New(ap->ob_type, ap->nd,\n\t\t\t\t\t ap->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, (PyObject *)ap);\n\tif (ret == NULL) goto fail;\n\t\n\tif (ap->descr->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\tip = (intp *)ret->data;\n\targsort_elsize = ap->itemsize;\n\tm = ap->dimensions[ap->nd-1];\n\tif (m == 0) goto finish;\n\n\tn = PyArray_SIZE(ap)/m;\n\tstore_ptr = global_data;\n\tglobal_data = ap->data;\n\tstore = global_obj;\n\tglobal_obj = ap;\n\tfor (i=0; idescr->compare;\n\tintp min_i, max_i, i, j;\n\tint location, elsize = ap1->itemsize;\n\tintp elements = ap1->dimensions[ap1->nd-1];\n\tintp n = PyArray_Size((PyObject *)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\nstatic PyObject *\nPyArray_SearchSorted(PyArrayObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1, *ap2, *ret;\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->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"compare not supported for type\");\n\t\tgoto fail;\n\t}\n\t\n\tlocal_where(ap1, ap2, ret); \n\t\n\tPy_DECREF(ap1);\n\tPy_DECREF(ap2);\n\treturn (PyObject *)ret;\n\t\n fail:\n\tPy_XDECREF(ap1);\n\tPy_XDECREF(ap2);\n\tPy_XDECREF(ret);\n\treturn NULL;\n}\n\n\n\n/* Could perhaps be redone to not make contiguous arrays \n */\n\nstatic PyObject *\nPyArray_InnerProduct(PyObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1, *ap2, *ret;\n\tintp i, j, l, i1, i2, n1, n2;\n\tint typenum;\n\tintp is1, is2, os;\n\tchar *ip1, *ip2, *op;\n\tintp dimensions[MAX_DIMS], nd;\n\tPyArray_DotFunc *dot;\n\tPyTypeObject *subtype;\n double prior1, prior2;\n\t\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\n\t\t\n\tret = NULL;\n\tap1 = (PyArrayObject *)PyArray_ContiguousFromAny(op1, typenum, \n\t\t\t\t\t\t\t 0, 0);\n\tif (ap1 == NULL) return NULL;\n\tap2 = (PyArrayObject *)PyArray_ContiguousFromAny(op2, typenum, \n\t\t\t\t\t\t\t 0, 0);\n\tif (ap2 == NULL) goto fail;\n\t\n\tif (ap1->nd == 0 || ap2->nd == 0) {\n\t\tret = (ap1->nd == 0 ? ap1 : ap2);\n\t\tret = (PyArrayObject *)ret->ob_type->tp_as_number->\\\n\t\t\tnb_multiply((PyObject *)ap1, (PyObject *)ap2);\n\t\tPy_DECREF(ap1);\n\t\tPy_DECREF(ap2);\n\t\treturn (PyObject *)ret;\n\t}\n\t\n\tl = ap1->dimensions[ap1->nd-1];\n\t\n\tif (ap2->dimensions[ap2->nd-1] != l) {\n\t\tPyErr_SetString(PyExc_ValueError, \"matrices are not aligned\");\n\t\tgoto fail;\n\t}\n\t\n\tif (l == 0) n1 = n2 = 0;\n\telse {\n\t\tn1 = PyArray_SIZE(ap1)/l;\n\t\tn2 = PyArray_SIZE(ap2)/l;\n\t}\n\n\tnd = ap1->nd+ap2->nd-2;\n\tj = 0;\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap1->dimensions[i];\n\t}\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap2->dimensions[i];\n\t}\n\n\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n prior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n prior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n subtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n\n\tret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions, \n\t\t\t\t\t typenum, NULL, NULL, 0, 0, \n (PyObject *)\n\t\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n\tif (ret == NULL) goto fail;\n\n\tdot = (ret->descr->dotfunc);\n\t\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"dot not available for this type\");\n\t\tgoto fail;\n\t}\n\n\t\n\tis1 = ap1->strides[ap1->nd-1]; \n\tis2 = ap2->strides[ap2->nd-1];\n\top = ret->data; os = ret->itemsize;\n\t\n\tip1 = ap1->data;\n\tfor(i1=0; i1data;\n\t\tfor(i2=0; i2nd == 0 || ap2->nd == 0) {\n\t\tret = (ap1->nd == 0 ? ap1 : ap2);\n\t\tret = (PyArrayObject *)ret->ob_type->tp_as_number->\\\n\t\t\tnb_multiply((PyObject *)ap1, (PyObject *)ap2);\n\t\tPy_DECREF(ap1);\n\t\tPy_DECREF(ap2);\n\t\treturn (PyObject *)ret;\n\t}\n\t\n\tl = ap1->dimensions[ap1->nd-1];\n\tif (ap2->nd > 1) {\n\t\tmatchDim = ap2->nd - 2;\n\t\totherDim = ap2->nd - 1;\n\t}\n\telse {\n\t\tmatchDim = 0;\n\t\totherDim = 0;\n\t}\n\n\tif (ap2->dimensions[matchDim] != l) {\n\t\tPyErr_SetString(PyExc_ValueError, \"objects are not aligned\");\n\t\tgoto fail;\n\t}\n\t\n\tif (l == 0) n1 = n2 = 0;\n\telse {\n\t\tn1 = PyArray_SIZE(ap1)/l;\n\t\tn2 = PyArray_SIZE(ap2)/l;\n\t}\n\n\tnd = ap1->nd+ap2->nd-2;\n\tj = 0;\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap1->dimensions[i];\n\t}\n\tfor(i=0; ind-2; i++) {\n\t\tdimensions[j++] = ap2->dimensions[i];\n\t}\n\tif(ap2->nd > 1) {\n\t\tdimensions[j++] = ap2->dimensions[ap2->nd-1];\n\t}\n\t/*\n\tfprintf(stderr, \"nd=%d dimensions=\", nd);\n\t for(i=0; i prior1 ? ap2->ob_type : ap1->ob_type);\n\n\tret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions, \n\t\t\t\t\t typenum, NULL, NULL, 0, 0, \n (PyObject *)\n\t\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n\tif (ret == NULL) goto fail;\n\n\tdot = ret->descr->dotfunc;\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"dot not available for this type\");\n\t\tgoto fail;\n\t}\n\t\t\n\tis1 = ap1->strides[ap1->nd-1]; is2 = ap2->strides[matchDim];\n\tif(ap1->nd > 1)\n\t\tis1r = ap1->strides[ap1->nd-2];\n\telse\n\t\tis1r = ap1->strides[ap1->nd-1];\n\tis2r = ap2->strides[otherDim];\n\n\top = ret->data; os = ret->itemsize;\n\n\tip1 = ap1->data;\n\tfor(i1=0; i1data;\n\t\tfor(i2=0; i2ob_type, 2, dims, PyArray_TYPE(arr),\n\t\t\t NULL, NULL, elsize, 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[ap1->nd-1];\n\tn2 = ap2->dimensions[ap2->nd-1];\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 = (int)(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\t\n\tret = (PyArrayObject *)PyArray_New(ap1->ob_type, 1,\n\t\t\t\t\t &length, typenum, \n\t\t\t\t\t NULL, NULL, 0, 0, \n (PyObject *)ap1);\n\tif (ret == NULL) goto fail;\n\n\t\n\tdot = ret->descr->dotfunc;\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"function not available for this type\");\n\t\tgoto fail;\n\t}\n\t\n\tis1 = ap1->strides[ap1->nd-1]; is2 = ap2->strides[ap2->nd-1];\n\top = ret->data; os = ret->itemsize;\n\t\n\tip1 = ap1->data; ip2 = ap2->data+n_left*is2;\n\tn = n-n_left;\n\tfor(i=0; idescr->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->itemsize;\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 ret = (PyArrayObject *)PyArray_New(self->ob_type, nd, shape, \n\t\t\t\t\t self->descr->type_num,\n\t\t\t\t\t NULL, NULL, 0, 0, \n (PyObject *)self);\n\t\n if (ret == NULL) goto fail;\n\t\n max_item = self->dimensions[axis];\n chunk = chunk * ret->itemsize;\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\nstatic PyObject *\nPyArray_Put(PyArrayObject *self, PyObject *indices0, PyObject* values0) \n{\n PyArrayObject *indices, *values;\n int i, chunk, ni, max_item, nv, tmp; \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->itemsize;\n\n indices = (PyArrayObject *)PyArray_ContiguousFromAny(indices0, PyArray_INTP, 0, 0);\n if (indices == NULL) goto fail;\n ni = PyArray_SIZE(indices);\n\n values = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny(values0, self->descr->type_num, \n\t\t\t\t\t 0, 0);\n if (values == NULL) goto fail;\n nv = PyArray_SIZE(values);\n if (nv > 0) { /* nv == 0 for a null array */\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 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\nstatic PyObject *\nPyArray_PutMask(PyArrayObject *self, PyObject *mask0, PyObject* values0) \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->itemsize;\n\n mask = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny(mask0, PyArray_BOOL, 0, 0);\n if (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\t\tfor(i=0; idata + chunk * (i % nv);\n\t\t\ttmp = ((Bool *)(mask->data))[i];\n\t\t\tif (tmp) {\n\t\t\t\tmemmove(dest + i * chunk, src, chunk);\n\t\t\t\tif (thistype == PyArray_OBJECT)\n\t\t\t\t\tPy_INCREF(*((PyObject **)src));\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 \nstatic int \nPyArray_Converter(PyObject *object, PyObject **address) \n{\n if (PyArray_Check(object)) {\n *address = object;\n\t\tPy_INCREF(object);\n return PY_SUCCEED;\n }\n else {\n\t\t*address = PyArray_FromAny(object, NULL, 0, 0, CARRAY_FLAGS);\n\t\tif (*address == NULL) return PY_FAIL;\n\t\treturn PY_SUCCEED;\n }\n}\n\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\nstatic int\nPyArray_TypestrConvert(int itemsize, int gentype)\n{\n\tregister int newtype = gentype;\n\t\n\tif (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\nstatic int\nPyArray_BufferConverter(PyObject *obj, PyArray_Chunk *buf)\n{\n int buflen;\n\n buf->ptr = NULL;\n buf->flags = WRITEABLE;\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\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) goto fail;\n return PY_SUCCEED;\n\n fail:\n\tPyDimMem_FREE(seq->ptr);\n\treturn PY_FAIL;\n}\n\n/* This function takes a Python object representing a type and converts it \n to a C type_num and an itemsize (elements of PyArray_Typecode structure)\n \n Many objects can be used to represent a type.\n */\n\nstatic int\nPyArray_TypecodeConverter(PyObject *obj, PyArray_Typecode *at)\n{\n char *type;\n PyArray_Descr *descr;\n int check_num=PyArray_NOTYPE+10;\n\tint len;\n\tPyObject *item, *attr=NULL;\n\n\tat->itemsize = 0;\n if (obj == Py_None) {\n at->type_num = PyArray_NOTYPE;\n return PY_SUCCEED;\n }\n\n if (PyType_Check(obj) && PyType_IsSubtype((PyTypeObject *)obj, \n &PyGenericArrType_Type)) {\n PyArray_TypecodeFromTypeObject(obj, at);\n return PY_SUCCEED;\n }\n\n\n\t/* type object could be an array */\n\tif (PyArray_Check(obj)) {\n\t\tat->type_num = PyArray_TYPE(obj);\n\t\tat->itemsize = PyArray_ITEMSIZE(obj);\n\t\treturn PY_SUCCEED;\n\t}\n\n\t/* or an array scalar */\n if (PyArray_IsScalar(obj, Generic)) {\n PyArray_TypecodeFromScalar(obj, at);\n return PY_SUCCEED;\n }\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);\t\t\n\t\tif (len > 0) {\n\t\t\tcheck_num = (int) type[0];\n\t\t}\n\t\tif (len > 1) {\n\t\t\tat->itemsize = atoi(type+1);\n\t\t\t/* When specifying length of UNICODE\n\t\t\t the number of characters is given to match \n\t\t\t the STRING interface. Each character can be\n\t\t\t more than one byte and itemsize must be\n\t\t\t the number of bytes.\n\t\t\t*/\n\t\t\tif (check_num == PyArray_UNICODELTR ||\t\\\n\t\t\t check_num == PyArray_UNICODE) \n\t\t\t at->itemsize *= sizeof(Py_UNICODE);\n\n\t\t\t/* Support for generic processing */\n\t\t\telse if ((check_num != PyArray_STRINGLTR) &&\n\t\t\t\t (check_num != PyArray_VOIDLTR) &&\n\t\t\t\t (check_num != PyArray_STRING) &&\n\t\t\t\t (check_num != PyArray_VOID)) {\n\t\t\t\tcheck_num = \\\n\t\t\t\t\tPyArray_TypestrConvert(at->itemsize,\n\t\t\t\t\t\t\t check_num);\n\t\t\t at->itemsize = 0;\n\t\t\t\tif (check_num == PyArray_NOTYPE) goto fail;\n\t\t\t}\n\t\t}\n\t}\n\t/* Arbitray object with dtypechar and itemsize attributes. */\n\telse if (PyObject_HasAttrString(obj, \"dtypechar\") && \n\t\t PyObject_HasAttrString(obj, \"itemsize\")) {\n\t\tattr = PyObject_GetAttrString(obj, \"dtypechar\");\n\t\tif (attr && PyString_GET_SIZE(attr) > 0) {\n\t\t\ttype = PyString_AsString(attr);\n\t\t\tcheck_num = (int) type[0];\n\t\t}\n\t\tPy_XDECREF(attr);\n\t\tif (!PyErr_Occurred()) {\n\t\t\tattr = PyObject_GetAttrString(obj, \"itemsize\");\n\t\t\tat->itemsize = PyInt_AsLong(attr);\n\t\t\tPy_XDECREF(attr);\n\t\t}\t\t\t\n\t}\t\t\n\telse if (PyType_Check(obj)) {\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 *)(&PyBool_Type))\n\t\t\tcheck_num = PyArray_BOOL;\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 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}\t\n else { /* Default -- try integer conversion */\n\t\t/* Don't allow integer conversion */\n /* check_num = PyInt_AsLong(obj); */\n\t\t/* fprintf(stderr, \"****\\n\\ntype=%s\\n\\n****\\n\", \n\t\t\tobj->ob_type->tp_name);\n\t\t*/\n\t\tgoto fail;\n\t}\n\n\tif (PyErr_Occurred()) goto fail;\n\n\t/*\n\tif (check_num == PyArray_NOTYPE) return PY_FAIL;\n\t*/\n\tif (check_num == PyArray_NOTYPE) {\n\t\tat->type_num = PyArray_NOTYPE;\n\t\tat->itemsize = 0;\n\t\treturn PY_SUCCEED;\n\t}\n\n if ((descr = PyArray_DescrFromType(check_num))==NULL) {\n\t\t/* Now check to see if the object is registered\n\t\t in typeDict */\n\t\tif (typeDict != NULL) {\n\t\t\titem = PyDict_GetItem(typeDict, obj);\n\t\t\tif (item) {\n\t\t\t\tPyArray_TypecodeFromTypeObject(obj, at);\n\t\t\t\tPyErr_Clear();\n\t\t\t\treturn PY_SUCCEED;\n\t\t\t}\n\t\t}\n return PY_FAIL;\n\t}\n\t\n at->type_num = descr->type_num;\n\tif (at->itemsize == 0) at->itemsize = descr->elsize;\n\t\n return PY_SUCCEED;\n\n fail:\n\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\"data type not understood\");\n\treturn PY_FAIL;\n}\t\n\n\n/* This function returns true if the two typecodes are \n equivalent (same basic kind and same itemsize).\n*/\n\nstatic Bool\nPyArray_EquivalentTypes(PyArray_Typecode *typ1, PyArray_Typecode *typ2)\n{\n\tregister int typenum1=typ1->type_num;\n\tregister int typenum2=typ2->type_num;\n\tregister int size1=typ1->itemsize;\n\tregister int size2=typ2->itemsize;\n\n\tif (size1 != size2) return FALSE;\n\tif (typenum1==typenum2) return TRUE;\n\n\t/* If we are here then size1 == size2 */\n\tif (typenum1 < PyArray_FLOAT) {\n\t\tif (PyTypeNum_ISBOOL(typenum1))\n\t\t\treturn (Bool)(PyTypeNum_ISBOOL(typenum2));\n\t\telse if (PyTypeNum_ISUNSIGNED(typenum1))\n\t\t\treturn (Bool)(PyTypeNum_ISUNSIGNED(typenum2));\n\t\telse \n\t\t\treturn (Bool)(PyTypeNum_ISSIGNED(typenum2));\n\t}\n\telse {\n\t\tif (PyTypeNum_ISFLOAT(typenum1))\n\t\t\treturn (Bool)(PyTypeNum_ISFLOAT(typenum2));\n\t\telse if (PyTypeNum_ISCOMPLEX(typenum1))\n\t\t\treturn (Bool)(PyTypeNum_ISCOMPLEX(typenum2));\n\t}\n\t/* Default size1 != size2 and typenum1 != typenum2 */\n\treturn FALSE;\t\n}\n\nstatic Bool \nPyArray_EquivArrTypes(PyArrayObject *a1, PyArrayObject *a2)\n{\n PyArray_Typecode type1={0,0,0};\n PyArray_Typecode type2={0,0,0};\n\n\ttype1.type_num = PyArray_TYPE(a1);\n\ttype2.type_num = PyArray_TYPE(a2);\n\ttype1.itemsize = PyArray_ITEMSIZE(a1);\n\ttype2.itemsize = PyArray_ITEMSIZE(a2);\n\t\t\t\n return PyArray_EquivalentTypes(&type1, &type2);\n}\n\n/* All flexible types of the same typenum seen as equivalent */\nstatic Bool\nPyArray_EquivalentTypenums(int typenum1, int typenum2)\n{\n\tPyArray_Typecode type1={0,0,0};\n\tPyArray_Typecode type2={0,0,0};\n\t\n\ttype1.type_num = typenum1;\n\ttype2.type_num = typenum2;\n\ttype1.itemsize = PyArray_DescrFromType(typenum1)->elsize;\n\ttype2.itemsize = PyArray_DescrFromType(typenum2)->elsize;\n\t\n\treturn PyArray_EquivalentTypes(&type1, &type2);\n}\n\n\n/*** END C-API FUNCTIONS **/\n\n\n#define _ARET(x) PyArray_Return((PyArrayObject *)(x))\n\nstatic char doc_fromobject[] = \"array(object, dtype=None, copy=1, fortran=0, \"\\\n \"subok=0)\\n\"\\\n \"will return a new array formed from the given object type given.\\n\"\\\n \"Object can anything with an __array__ method, or any object\\n\"\\\n \"exposing the array interface, or any (nested) sequence.\\n\"\\\n \"If no type is given, then the type will be determined as the\\n\"\\\n \"minimum type required to hold the objects in the sequence.\\n\"\\\n \"If copy is zero and sequence is already an array with the right \\n\"\\\n \"type, a reference will be returned. If the sequence is an array,\\n\"\\\n \"type can be used only to upcast the array. For downcasting \\n\"\\\n \"use .astype(t) method. If subok is true, then subclasses of the\\n\"\\\n \"array may be returned. Otherwise, a base-class ndarray is returned\";\n\nstatic PyObject *\n_array_fromobject(PyObject *ignored, PyObject *args, PyObject *kws)\n{\n\tPyObject *op, *ret=NULL;\n\tstatic char *kwd[]= {\"object\", \"dtype\", \"copy\", \"fortran\", \"subok\", \n NULL};\n Bool subok=FALSE;\n\tBool copy=TRUE;\n\tPyArray_Typecode type = {PyArray_NOTYPE, 0, 0};\n\tPyArray_Typecode oldtype = {PyArray_NOTYPE, 0, 0};\n\tint type_num;\n\tBool fortran=FALSE;\n\tint flags=0;\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kws, \"O|O&O&O&O&\", kwd, &op, \n\t\t\t\t\tPyArray_TypecodeConverter,\n &type, \n\t\t\t\t\tPyArray_BoolConverter, ©, \n\t\t\t\t\tPyArray_BoolConverter, &fortran,\n PyArray_BoolConverter, &subok)) \n\t\treturn NULL;\n\ttype_num = type.type_num;\n\n\t/* fast exit if simple call */\n\tif ((PyArray_CheckExact(op) && PyBigArray_CheckExact(op)) && \\\n (copy==0) && \\\n\t (fortran == PyArray_CHKFLAGS(op, FORTRAN))) {\n\t\tif (type_num == PyArray_NOTYPE) {\n\t\t\tPy_INCREF(op);\n\t\t\treturn op;\n\t\t}\n\t\t/* One more chance */\n\t\toldtype.type_num = PyArray_TYPE(op);\n\t\toldtype.itemsize = PyArray_ITEMSIZE(op);\n\t\tif (PyArray_EquivalentTypes(&oldtype, &type)) {\n\t\t\tPy_INCREF(op);\n\t\t\treturn op;\n\t\t}\n\t}\n\n\ttype.fortran = fortran; \n\tif (copy) {\n\t\tflags = ENSURECOPY;\n\t}\n if (!subok) {\n flags |= ENSUREARRAY;\n }\n\n\tif ((ret = PyArray_FromAny(op, &type, 0, 0, flags)) == NULL) \n\t\treturn NULL;\n\n\treturn ret;\n}\n\nstatic PyObject *\nPyArray_Empty(int nd, intp *dims, PyArray_Typecode *type)\n{\n\tPyArrayObject *ret;\n\tintp n;\n \n\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, nd, dims, \n\t\t\t\t\t type->type_num,\n\t\t\t\t\t NULL, NULL, type->itemsize, \n\t\t\t\t\t type->fortran, NULL);\n\tif (ret == NULL) return NULL;\n \n\tn = PyArray_SIZE(ret);\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=intp,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_Typecode typecode = {PyArray_NOTYPE, 0, 0};\n PyArray_Dims shape;\n\tBool fortran = FALSE;\t\n PyObject *ret;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &shape, \n PyArray_TypecodeConverter,\n\t\t\t\t\t &typecode, \n\t\t\t\t\t PyArray_BoolConverter, &fortran)) \n\t\treturn NULL;\n\t\n\ttypecode.fortran = fortran;\n if (typecode.type_num ==PyArray_NOTYPE) \n\t\ttypecode.type_num = PyArray_INTP;\n \n\tret = PyArray_Empty(shape.len, shape.ptr, &typecode); \n PyDimMem_FREE(shape.ptr);\n return ret;\n}\n\nstatic char doc_scalar[] = \"scalar(dtypestr,obj) will return a new scalar array of the given type initialized with obj. Mainly for pickle support. typestr must be a valid data typestr (complete with < > or |). If dtypestr is object, 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[] = {\"dtypestr\",\"obj\", NULL};\n\tPyArray_Typecode typecode;\n\tPyObject *obj=NULL;\n\tchar *typestr;\n\tint typestrlen;\n\tint swap, alloc=0;\n\tvoid *dptr;\n\tPyObject *ret;\n\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"z#|O\",\n\t\t\t\t\t kwlist, &typestr, &typestrlen,\n\t\t\t\t\t &obj)) \n\t\treturn NULL;\n\t\n\tif (_array_typecode_fromstr(typestr, &swap, &typecode) < 0) \n\t\treturn NULL;\n\t\n\tif (typecode.itemsize == 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\tswap = 0;\n\t}\n\telse {\n\t\tif (obj == NULL) {\n\t\t\tdptr = malloc(typecode.itemsize);\n\t\t\tif (dptr == NULL) {\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tmemset(dptr, '\\0', typecode.itemsize);\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.itemsize) {\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.type_num,\n\t\t\t typecode.itemsize, swap); \n\n\t/* free dptr which contains zeros */\n\tif (alloc) free(dptr);\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_Zeros(int nd, intp *dims, PyArray_Typecode *type)\n{\n\tPyArrayObject *ret;\n\tintp n;\n\n\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, nd, dims, \n\t\t\t\t\t type->type_num,\n\t\t\t\t\t NULL, NULL, type->itemsize, \n\t\t\t\t\t type->fortran, NULL);\n\tif (ret == NULL) return NULL;\n \n\tn = PyArray_SIZE(ret);\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 {\t\t\n\t\tmemset(ret->data, 0, n*(ret->itemsize));\n\t}\n\treturn (PyObject *)ret;\n\n}\n\nstatic char doc_zeros[] = \"zeros((d1,...,dn),dtype=intp,fortran=0) will return a new array of shape (d1,...,dn) and type typecode with all it's entries initialized to zero.\";\n\n\nstatic PyObject *\narray_zeros(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {\"shape\",\"dtype\",\"fortran\",NULL};\n\tPyArray_Typecode typecode = {PyArray_NOTYPE, 0, 0};\n PyArray_Dims shape;\n\tBool fortran = FALSE;\t\n PyObject *ret;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &shape, \n PyArray_TypecodeConverter,\n\t\t\t\t\t &typecode, \n\t\t\t\t\t PyArray_BoolConverter,\n\t\t\t\t\t &fortran)) \n\t\treturn NULL;\n\t\n\ttypecode.fortran = fortran;\n if (typecode.type_num ==PyArray_NOTYPE) \n\t\ttypecode.type_num = PyArray_INTP;\n \n\tret = PyArray_Zeros(shape.len, shape.ptr, &typecode); \n PyDimMem_FREE(shape.ptr);\n return 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 char doc_fromString[] = \"fromstring(string, dtype=intp, count=-1, swap=False) 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\tPyArrayObject *ret; \n\tchar *data;\n\tlonglong nin=-1;\n\tintp s, n;\n\tstatic char *kwlist[] = {\"string\", \"dtype\", \"count\", \"swap\",NULL};\n\tPyArray_Typecode type = {PyArray_INTP, sizeof(intp), 0};\n\tint itemsize;\n\tint swapped=FALSE;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"s#|O&LO&\", kwlist, \n\t\t\t\t\t &data, &s, \n\t\t\t\t\t PyArray_TypecodeConverter, &type,\n\t\t\t\t\t &nin, \n\t\t\t\t\t PyArray_BoolConverter,\n\t\t\t\t\t &swapped)) {\n\t\treturn NULL;\n\t}\n\t\n\tn = (intp) nin;\n\n\titemsize = type.itemsize;\n\tif (itemsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \"zero-valued itemsize\");\n\t\treturn NULL;\n\t}\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\"string size must be a multiple\"\\\n\t\t\t\t\t\" of element size\");\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\"string is smaller than requested\"\\\n\t\t\t\t\t\" size\");\n\t\t\treturn NULL;\n\t\t}\n\t}\n\n\tif ((ret = (PyArrayObject *)PyArray_New(&PyArray_Type, 1, &n, \n\t\t\t\t\t\ttype.type_num, NULL, \n\t\t\t\t\t\tNULL, itemsize, 0,\n\t\t\t\t\t\tNULL)) == NULL)\n\t\treturn NULL;\n\t\t\n\tmemcpy(ret->data, data, n*ret->itemsize);\n\tif (swapped) ret->flags &= ~NOTSWAPPED;\n\tPyArray_INCREF(ret);\n\treturn (PyObject *)ret;\n}\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\nstatic int\n_fill_in_itemsize(PyArray_Typecode *typecode)\n{\n\tPyArray_Descr *descr;\n\tdescr = PyArray_DescrFromType(typecode->type_num);\n\tif (descr==NULL) return -1;\n\ttypecode->itemsize = descr->elsize;\n\treturn 0;\n}\n\n\nstatic PyObject *\nPyArray_FromFile(FILE *fp, PyArray_Typecode *typecode, intp num, char *sep)\n{\n\tPyArrayObject *r;\n\tsize_t nread = 0;\n\tPyArray_ScanFunc *scan;\n\n\tif (typecode->itemsize == 0) {\n\t\tif (_fill_in_itemsize(typecode) < 0) \n\t\t\treturn NULL;\n\t}\n\n\tif (num == -1 && sep == NULL) { /* 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\tfseek(fp, (long) start, SEEK_SET);\n\t\tif (numbytes == -1) {\n\t\t\tPyErr_SetString(PyExc_IOError, \"could not seek in file\");\n\t\t\treturn NULL;\n\t\t}\n\t\tif (typecode->itemsize == 0) {\n\t\t\ttypecode->itemsize = numbytes;\n\t\t\tnum = 1;\n\t\t}\n\t\telse {\n\t\t\tnum = numbytes / typecode->itemsize;\n\t\t}\n\t}\n\t\n\tif (sep==NULL) { /* binary data */\n\t\tr = (PyArrayObject *)PyArray_New(&PyArray_Type, 1, &num, \n\t\t\t\t\t\t typecode->type_num,\n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t typecode->itemsize, 0, NULL);\n\t\tif (r==NULL) return NULL;\n\t\tnread = fread(r->data, typecode->itemsize, 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 = PyArray_DescrFromType(typecode->type_num)->scanfunc;\n\t\tif (scan == NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"don't know how to read \"\t\\\n\t\t\t\t\t\"character files with that \"\t\\\n\t\t\t\t\t\"array type\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (num != -1) { /* number to read is known */\n\t\t\tr = (PyArrayObject *)PyArray_New(&PyArray_Type, 1, \n\t\t\t\t\t\t\t &num, \n\t\t\t\t\t\t\t typecode->type_num,\n\t\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t\t typecode->itemsize, \n\t\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, r->itemsize, sep, NULL);\n\t\t\t\tif (done < -2) break;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += r->itemsize;\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 *)PyArray_New(&PyArray_Type, 1, \n\t\t\t\t\t\t\t &size, \n\t\t\t\t\t\t\t typecode->type_num,\n\t\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t\t typecode->itemsize, \n\t\t\t\t\t\t\t 0, NULL);\n\t\t\tif (r==NULL) return NULL;\n\t\t\ttotalbytes = bytes = size * typecode->itemsize;\n\t\t\tdptr = r->data;\n\t\t\twhile (!done) {\n\t\t\t\tdone = scan(fp, dptr, r->itemsize, 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->itemsize;\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->itemsize);\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->itemsize);\n\t\tPyArray_DIM(r,0) = nread;\n\t}\n\treturn (PyObject *)r;\n}\n\nstatic char doc_fromfile[] = \\\n\t\"fromfile(file=, dtype=intp, count=-1, sep='')\\n\"\\\n\t\"\\n\"\\\n\t\" Return an array of the given data type from a \\n\"\\\n\t\" (text or binary) file. The file argument can be an open file\\n\"\\\n\t\" or a string with the name of a file to read from. If\\n\"\\\n\t\" count==-1, then the entire file is read, otherwise count is\\n\"\\\n\t\" the number of items of the given type read in. If sep is ''\\n\"\\\n\t\" then read a binary file, otherwise it gives the separator\\n\"\\\n\t\" between elements in a text file.\\n\"\\\n\t\"\\n\"\\\n\t\" WARNING: This function should be used sparingly, as it is not\\n\"\\\n\t\" a robust method of persistence. But it can be useful to\\n\"\\\n\t\" read in simply-formatted or binary data quickly.\";\n\nstatic PyObject *\narray_fromfile(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tPyObject *file=NULL, *ret;\n\tFILE *fp;\n\tchar *sep=\"\";\n\tchar *mode=NULL;\n\tlonglong nin=-1;\n\tstatic char *kwlist[] = {\"file\", \"dtype\", \"count\", \"sep\", NULL};\n\tPyArray_Typecode type = {PyArray_INTP, sizeof(intp), 0};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"O|O&Ls\", kwlist, \n\t\t\t\t\t &file,\n\t\t\t\t\t PyArray_TypecodeConverter, &type,\n\t\t\t\t\t &nin, &sep)) {\n\t\treturn NULL;\n\t}\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, \"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\nstatic PyObject *\nPyArray_FromBuffer(PyObject *buf, PyArray_Typecode *type, \n\t\t intp count, int swapped) \n{\n\tPyArrayObject *ret;\n\tchar *data;\n\tint ts;\n\tintp s, n;\n\tint itemsize;\n\tint write=1;\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\treturn NULL;\n\t}\n\tif (type->itemsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"itemsize cannot be zero in type\");\n\t\treturn NULL;\n\t}\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\treturn NULL;\n\t\t}\n\t}\n\ts = (intp)ts;\t\n\tn = (intp)count;\n\titemsize = type->itemsize;\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\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\treturn NULL;\n\t\t}\n\t}\n\t\n\tif ((ret = (PyArrayObject *)PyArray_New(&PyArray_Type, 1, &n, \n\t\t\t\t\t\ttype->type_num, NULL, \n\t\t\t\t\t\tdata, itemsize, DEFAULT_FLAGS,\n\t\t\t\t\t\tNULL)) == NULL)\n\t\treturn NULL;\n\t\n\tif (!write) ret->flags &= ~WRITEABLE;\n\tif (swapped) ret->flags &= ~NOTSWAPPED;\n\tPy_INCREF(buf);\n\t/* Store a reference for decref on deallocation */\n\tret->base = buf;\n\tPyArray_UpdateFlags(ret, ALIGNED);\n\treturn (PyObject *)ret; \t\n}\n\nstatic char doc_frombuffer[] = \\\n\t\"frombuffer(buffer=, dtype=intp, count=-1, swap=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 the buffer has data that is out\\n\" \\\n\t\" not in machine byte-order, than set swap=1. 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;\n\tstatic char *kwlist[] = {\"buffer\", \"dtype\", \"count\", \n\t\t\t\t \"swap\", NULL};\n\tPyArray_Typecode type = {PyArray_INTP, sizeof(intp), 0};\n\tint swapped=0;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"O|O&Li\", kwlist, \n\t\t\t\t\t &obj,\n\t\t\t\t\t PyArray_TypecodeConverter, &type,\n\t\t\t\t\t &nin, &swapped)) {\n\t\treturn NULL;\n\t}\n\n\treturn PyArray_FromBuffer(obj, &type, (intp)nin, swapped);\n}\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\nstatic PyObject *\nPyArray_Arange(double start, double stop, double step, int type_num)\n{\n\tintp length, i;\n\tPyObject *range;\n\tchar *rptr;\n\tint elsize, type;\n\tdouble value;\n\tPyArray_Descr *dbl_descr;\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\tdbl_descr = PyArray_DescrFromType(PyArray_DOUBLE);\n \n\trptr = ((PyArrayObject *)range)->data;\n\telsize = ((PyArrayObject *)range)->itemsize;\n\ttype = ((PyArrayObject *)range)->descr->type_num;\n\tfor (i=0; i < length; i++) {\n\t\tvalue = start + i*step;\n\t\tdbl_descr->cast[type]((char*)&value, rptr, 1, NULL, \n\t\t\t\t (PyArrayObject *)range);\n\t\trptr += elsize;\n\t}\n \n\treturn range;\n}\n\n\nstatic char doc_arange[] = \"arange(start, stop=None, step=1, dtype=intp)\\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=Py_None, *o_step=NULL;\n\tstatic char *kwd[]= {\"start\", \"stop\", \"step\", \"dtype\", NULL};\n\tdouble start, stop, step;\n\tPyArray_Typecode typecode = {PyArray_NOTYPE, 0};\n\tint type_num;\n\tint deftype = PyArray_INTP;\n\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_TypecodeConverter, \n\t\t\t\t\t&typecode)) \n\t\treturn NULL;\n\n\tdeftype = PyArray_ObjectType(o_start, deftype);\n\tif (o_stop != Py_None) {\n\t\tdeftype = PyArray_ObjectType(o_stop, deftype);\n\t}\n\tif (o_step != NULL) {\n\t\tdeftype = PyArray_ObjectType(o_step, deftype);\n\t}\n\n\ttype_num = typecode.type_num;\n\tif (type_num == PyArray_NOTYPE) {\n\t\ttype_num = deftype;\n\t}\n\n\tstart = PyFloat_AsDouble(o_start);\n\tif error_converting(start) return NULL;\n\n\tif (o_step == NULL) {\n\t\tstep = 1;\n\t}\n\telse {\n\t\tstep = PyFloat_AsDouble(o_step);\n\t\tif error_converting(step) return NULL;\n\t}\n\n\tif (o_stop == Py_None) {\n\t\tstop = start;\n\t\tstart = 0;\n\t}\n\telse {\n\t\tstop = PyFloat_AsDouble(o_stop);\n\t\tif error_converting(stop) return NULL;\n\t}\n\n\treturn PyArray_Arange(start, stop, step, type_num);\n}\n\n#undef _ARET\n\n/*****\n static char doc_arrayMap[] = \"arrayMap(func, [a1,...,an])\";\n\n static PyObject *array_arrayMap(PyObject *dummy, PyObject *args) {\n PyObject *shape, *a0;\n \n if (PyArg_ParseTuple(args, \"OO\", &a0, &shape) == NULL) return NULL;\n\t\n return PyArray_Map(a0, shape);\n }\n*****/\n\nstatic char \ndoc_set_string_function[] = \"set_string_function(f, repr=1) sets the python function f to be the function used to obtain a pretty printable string version of a array whenever a array is printed. f(M) should expect a array argument M, and should return a string consisting of the desired representation of M for printing.\";\n\nstatic PyObject *\narray_set_string_function(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tPyObject *op;\n\tint repr=1;\n\tstatic char *kwlist[] = {\"f\", \"repr\", NULL};\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"O|i\", kwlist, \n\t\t\t\t\t&op, &repr)) return NULL; \n\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 (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\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\tif ((x==NULL) || (y==NULL)) {\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\tarr = (PyArrayObject *)PyArray_FromAny(condition, NULL, 0, 0, 0);\n\tif (arr == NULL) return NULL;\n\n\tif ((x==NULL) && (y==NULL)) {\n\t\tret = PyArray_Nonzero(arr);\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\n\tzero = PyInt_FromLong((long) 0);\n\n\tobj = PyArray_EnsureArray(PyArray_GenericBinaryFunction(arr, zero, n_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_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_Typecode d1={PyArray_NOTYPE, 0, 0};\n\tPyArray_Typecode d2={PyArray_NOTYPE, 0, 0};\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_TypecodeConverter, &d1,\n\t\t\t\t\tPyArray_TypecodeConverter, &d2))\n\t\treturn NULL;\n\tif (d1.type_num == PyArray_NOTYPE || \\\n\t d2.type_num == PyArray_NOTYPE) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"did not understand one of the types; \"\\\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 struct PyMethodDef array_module_methods[] = {\n\t{\"set_string_function\", (PyCFunction)array_set_string_function, \n\t METH_VARARGS|METH_KEYWORDS, doc_set_string_function},\n\t{\"set_numeric_ops\", (PyCFunction)array_set_ops_function,\n\t METH_VARARGS|METH_KEYWORDS, doc_set_ops_function},\n\t{\"set_typeDict\", (PyCFunction)array_set_typeDict,\n\t METH_VARARGS, doc_set_typeDict},\n\n\t{\"array\",\t(PyCFunction)_array_fromobject, \n\t METH_VARARGS|METH_KEYWORDS, doc_fromobject},\n\t{\"arange\", (PyCFunction)array_arange, \n\t METH_VARARGS|METH_KEYWORDS, doc_arange},\n\t{\"zeros\",\t(PyCFunction)array_zeros, \n\t METH_VARARGS|METH_KEYWORDS, doc_zeros},\n\t{\"empty\",\t(PyCFunction)array_empty, \n\t METH_VARARGS|METH_KEYWORDS, doc_empty},\n\t{\"scalar\", (PyCFunction)array_scalar,\n\t METH_VARARGS|METH_KEYWORDS, doc_scalar},\n\t{\"where\", (PyCFunction)array_where,\n\t METH_VARARGS, doc_where},\n\t{\"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/* {\"arrayMap\",\t(PyCFunction)array_arrayMap, \n\t METH_VARARGS, doc_arrayMap},*/\n\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(Numeric, Generic);\n SINGLE_INHERIT(Integer, Numeric);\n SINGLE_INHERIT(Inexact, Numeric);\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 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 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 SINGLE_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\t \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, \"NOTSWAPPED\", s=PyInt_FromLong(NOTSWAPPED));\n Py_DECREF(s);\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\tif (PyType_Ready(&PyArrayIter_Type) < 0)\n\t\treturn; \n \n\tif (PyType_Ready(&PyArrayMapIter_Type) < 0)\n return; \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\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) \n return; /* otherwise there is an error */\n\n\n err:\t\n\t/* Check for errors */\n\tif (PyErr_Occurred())\n PyErr_Print();\n\t\tPy_FatalError(\"can't initialize module multiarray\");\n\n\treturn;\n}\n\n", "source_code_before": "\n/*\n Python Multiarray Module -- A useful collection of functions for creating and\n using ndarrays\n\n Original file \n Copyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\n Modified for scipy_core in 2005 \n\n Travis E. Oliphant\n Assistant Professor at\n Brigham Young University\n \n*/\n\n/* $Id: multiarraymodule.c,v 1.36 2005/09/14 00:14:00 teoliphant Exp $ */\n\n#include \"Python.h\"\n#include \"structmember.h\"\n/*#include \n#include \n*/\n\n#define _MULTIARRAYMODULE\n#include \"scipy/arrayobject.h\"\n\n#define PyAO PyArrayObject\n\nstatic PyObject *typeDict=NULL; /* Must be explicitly loaded */\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\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\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\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\nstatic int \nPyArray_CompareLists(intp *l1, intp *l2, int n) \n{\n int i;\n for(i=0;itype_num;\n\t}\n\n\tnew = PyArray_New(self->ob_type,\n\t\t\t self->nd, self->dimensions,\n\t\t\t self->descr->type_num,\n\t\t\t self->strides,\n\t\t\t self->data,\n\t\t\t self->itemsize,\n\t\t\t self->flags, (PyObject *)self);\n\n\tif (new==NULL) return NULL;\n\t\n Py_INCREF(self);\n PyArray_BASE(new) = (PyObject *)self;\n if ((type_num != PyArray_NOTYPE) && \\\n (type_num != self->descr->type_num)) {\n if (!PyTypeNum_ISFLEXIBLE(type_num)) {\n v = PyArray_TypeObjectFromType(type_num);\n }\n else {\n PyArray_Descr *descr;\n int itemsize = type->itemsize;\n descr = PyArray_DescrFromType(type_num);\n if (type_num == PyArray_UNICODE) \n itemsize /= sizeof(Py_UNICODE);\n /* construct a string representation */\n v = PyString_FromFormat(\"%c%d\", descr->type, \n itemsize);\n }\n if (v == NULL) goto fail;\n /* set attribute new.dtype = newtype */\n if (PyObject_SetAttrString(new, \"dtype\", v) < 0) goto fail;\n Py_DECREF(v);\n }\n\treturn new;\t\n\n fail:\n Py_XDECREF(v);\n Py_XDECREF(new);\n return NULL;\n}\n\nstatic PyObject *\nPyArray_Ravel(PyArrayObject *a, int fortran)\n{\n\tPyArray_Dims newdim = {NULL,1};\n\tintp val[1] = {-1};\n\n if (a->nd == 1) {\n Py_INCREF(a);\n return (PyObject *)a;\n }\n\tnewdim.ptr = val;\n\tif (!fortran && PyArray_ISCONTIGUOUS(a)) \n\t\treturn PyArray_Newshape(a, &newdim);\n\telse\n\t return PyArray_Flatten(a, fortran);\n}\n\nstatic PyObject *\nPyArray_Flatten(PyArrayObject *a, int fortran)\n{\n\tPyObject *ret, *new;\n\tintp size;\n\n\tsize = PyArray_SIZE(a);\n\tret = PyArray_New(a->ob_type,\n\t\t\t 1, &size,\n\t\t\t a->descr->type_num,\n\t\t\t NULL,\n NULL,\n\t\t\t a->itemsize,\n\t\t\t 0, (PyObject *)a);\n\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\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\tgoto fail;\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\tgoto fail;\n\t\t\t}\n\t\t}\n\t}\n \n\tret = (PyAO *)PyArray_New(self->ob_type,\n\t\t\t\t n, dimensions,\n\t\t\t\t self->descr->type_num,\n\t\t\t\t strides,\n\t\t\t\t self->data,\n\t\t\t\t self->itemsize,\n\t\t\t\t self->flags, (PyObject *)self);\n\t\n\tif (ret== NULL)\n goto fail;\n\t\n Py_INCREF(self);\n ret->base = (PyObject *)self;\n\tPyArray_UpdateFlags(ret, CONTIGUOUS | FORTRAN);\n\t\n return (PyObject *)ret;\n\t\n fail:\n return NULL;\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\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\tret = PyArray_New(self->ob_type, newnd, dimensions, \n\t\t\t self->descr->type_num, strides,\n\t\t\t self->data, self->itemsize, self->flags,\n\t\t\t (PyObject *)self);\n\tself->flags &= ~OWN_DATA;\n\tself->base = (PyObject *)self;\n\tPy_INCREF(self);\n\treturn (PyObject *)ret;\n}\n\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\nstatic PyObject *\nPyArray_Std(PyArrayObject *self, int axis, int rtype)\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\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->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->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\tPyTuple_SET_ITEM(ret, j, item);\n\t\t\tif (item == NULL) goto fail;\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->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\treturn ret;\n\n fail:\n\tPy_XDECREF(ret);\n\tPy_XDECREF(it);\n\treturn NULL;\n \n}\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)) goto fail;\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) goto fail;\n\tret = PyArray_Choose((PyAO *)selector, newtup);\n\tPy_DECREF(selector);\n\tPy_DECREF(newtup);\n\treturn ret;\n\n fail:\n\tPy_XDECREF(res1);\n\tPy_XDECREF(res2);\n\tPy_XDECREF(two);\n\tPy_XDECREF(selector);\n\treturn NULL;\n}\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_Copy(self);\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\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\nstatic PyObject *\nPyArray_Diagonal(PyArrayObject *self, int offset, int axis1, int axis2)\n{\n\tint n = self->nd;\n\tPyObject *new;\n\tPyObject *newaxes;\n\tint i, pos;\t\n\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 = PyTuple_New(n);\n\tif (newaxes==NULL) return NULL;\n\t/* insert at the end */\n\tPyTuple_SET_ITEM(newaxes, n-2, PyInt_FromLong((long)axis1));\n\tPyTuple_SET_ITEM(newaxes, n-1, PyInt_FromLong((long)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->type_num;\n\t\ttypecode.itemsize = self->itemsize;\n\t\ttypecode.fortran = 0;\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\treturn -1;\n\t}\n\tif ((ap = (PyArrayObject*)PyArray_FromAny(*op, &typecode, nd, nd,\n\t\t\t\t\t\t CARRAY_FLAGS)) == NULL)\n\t\treturn -1;\n\tswitch(nd) {\n\tcase 1:\n\t\t*((char **)ptr) = ap->data;\n\t\tbreak;\n\tcase 2:\n\t\tn = ap->dimensions[0];\n\t\tptr2 = (char **)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 ***)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\nstatic int \nPyArray_As1D(PyObject **op, char **ptr, int *d1, int typecode) \n{\n\tintp newd1;\n\t\n\tif (PyArray_AsCArray(op, (void *)ptr, &newd1, 1, typecode) == -1)\n\t\treturn -1;\t\n\t*d1 = (int) newd1;\n\treturn 0;\n}\n\n\nstatic int \nPyArray_As2D(PyObject **op, char ***ptr, int *d1, int *d2, int typecode) \n{\n\tintp newdims[2];\n\n\tif (PyArray_AsCArray(op, (void *)ptr, newdims, 2, typecode) == -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\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\tfree(ptr);\n }\n Py_DECREF(ap);\n return 0;\n}\n\n\nstatic PyObject *\n_swap_and_concat(PyObject *op, int axis, int n)\n{\n\tPyObject *newtup=NULL;\n\tPyObject *otmp, *arr;\n\tint i;\n\n\tnewtup = PyTuple_New(n);\n\tif (newtup==NULL) return NULL;\n\tfor (i=0; i= MAX_DIMS) {\n\t\t\totmp = PyArray_Ravel(mps[i],0);\n\t\t\tPy_DECREF(mps[i]);\n\t\t\tmps[i] = (PyArrayObject *)otmp;\n\t\t}\n\t\tprior2 = PyArray_GetPriority((PyObject *)(mps[i]), 0.0);\n\t\tif (prior2 > prior1) {\n\t\t\tprior1 = prior2;\n\t\t\tsubtype = mps[i]->ob_type;\n\t\t\tret = mps[i];\n\t\t}\n\t}\n\t\n\tnew_dim = 0;\n\tfor(i=0; ind;\n\t\telse {\n\t\t\tif (nd != mps[i]->nd) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"arrays must have same \"\\\n\t\t\t\t\t\t\"number of dimensions\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CompareLists(mps[0]->dimensions+1, \n\t\t\t\t\t\t mps[i]->dimensions+1, \n\t\t\t\t\t\t nd-1)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"array dimensions must \"\\\n\t\t\t\t\t\t\"agree except for d_0\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t}\n\t\tif (nd == 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"0-d arrays can't be concatenated\");\n\t\t\tgoto fail;\n\t\t}\n\t\tnew_dim += mps[i]->dimensions[0];\n\t}\n\t\n\ttmp = mps[0]->dimensions[0];\n\tmps[0]->dimensions[0] = new_dim;\n\tret = (PyArrayObject *)PyArray_New(subtype, nd,\n\t\t\t\t\t mps[0]->dimensions, \n\t\t\t\t\t type_num, NULL, NULL, 0, 0,\n (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 = PyTuple_New(n);\n\tfor (i=0; ind;\n\t\tpermutation = (intp *)malloc(n*sizeof(int));\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\tgoto fail;\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\tret = (PyArrayObject *)PyArray_New(ap->ob_type, n, permutation, \n\t\t\t\t\t ap->descr->type_num, NULL,\n\t\t\t\t\t ap->data, ap->itemsize, ap->flags,\n\t\t\t\t\t (PyObject *)ap);\n\tif (ret == NULL) goto fail;\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);\n\t\n\tif (op && (op != Py_None))\n\t\tPyArray_Free(op, (char *)axes);\n\tfree(permutation);\n\treturn (PyObject *)ret;\n\t\n fail:\n\tPy_XDECREF(ret);\n\tif (permutation != NULL) free(permutation);\n\tif (op != Py_None)\n\t\tPyArray_Free(op, (char *)axes);\n\treturn NULL;\n}\n\nstatic PyObject *\nPyArray_Repeat(PyArrayObject *aop, PyObject *op, int axis) {\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\tret = (PyArrayObject *)PyArray_New(aop->ob_type, aop->nd,\n\t\t\t\t\t aop->dimensions, \n\t\t\t\t\t aop->descr->type_num,\n\t\t\t\t\t NULL, NULL, aop->itemsize, 0,\n\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->itemsize;\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\t/* why not ??? \n\tif (PyTypeNum_ISFLEXIBLE(type_num)) {\n\t\tPyErr_SetString(PyExc_NotImplementedError, \n\t\t\t\t\"not implemented for flexible sizes\");\n\t\treturn NULL;\n\t}\n\t*/\n\tret = (PyArrayObject *)PyArray_New(ap->ob_type, ap->nd,\n\t\t\t\t\t ap->dimensions, type_num,\n\t\t\t\t\t NULL, NULL, 0, 0, (PyObject *)ap);\n\tif (ret == NULL) goto fail;\n\t\n\telsize = ret->itemsize;\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->compare(a,b,global_obj);\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#define SWAPBACK(op, ap) { \\\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\nstatic PyObject *\nPyArray_Sort(PyArrayObject *op, int axis) \n{\n\tPyArrayObject *ap=NULL, *store_arr=NULL;\n\tchar *ip;\n\tint i, n, m, elsize, orign;\n\n\tif ((ap = (PyAO*) _check_axis(op, &axis, 0))==NULL) return NULL;\n\n\tSWAPAXES(op, ap);\n\n\tap = (PyArrayObject *)PyArray_CopyFromObject((PyObject *)op, \n\t\t\t\t\t\t PyArray_NOTYPE,\n\t\t\t\t\t\t 1, 0);\n\tPy_DECREF(op);\n\n\tif (ap == NULL) return NULL;\n\n\tif (ap->descr->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"compare not supported for type\");\n\t\tPy_DECREF(ap);\n\t\treturn NULL;\n\t}\n\t\n\telsize = ap->itemsize;\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; iitemsize;\n\tconst intp *ipa = ip1;\n\tconst intp *ipb = ip2;\t\n\treturn global_obj->descr->compare(global_data + (isize * *ipa),\n global_data + (isize * *ipb), \n\t\t\t\t\t global_obj);\n}\n\nstatic PyObject *\nPyArray_ArgSort(PyArrayObject *op, int axis) \n{\n\tPyArrayObject *ap, *ret, *store;\n\tintp *ip;\n\tintp i, j, n, m, orign;\n\tint argsort_elsize;\n\tchar *store_ptr;\n\n\tif ((ap = (PyAO *)_check_axis(op, &axis, 0))==NULL) return NULL;\n\n\tSWAPAXES(op, ap);\n\n\tap = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)op, \n\t\t\t\t\t\t\t PyArray_NOTYPE,\n\t\t\t\t\t\t\t 1, 0);\n\tPy_DECREF(op);\n\n\tif (ap == NULL) return NULL;\n\t\n\tret = (PyArrayObject *)PyArray_New(ap->ob_type, ap->nd,\n\t\t\t\t\t ap->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, (PyObject *)ap);\n\tif (ret == NULL) goto fail;\n\t\n\tif (ap->descr->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\tip = (intp *)ret->data;\n\targsort_elsize = ap->itemsize;\n\tm = ap->dimensions[ap->nd-1];\n\tif (m == 0) goto finish;\n\n\tn = PyArray_SIZE(ap)/m;\n\tstore_ptr = global_data;\n\tglobal_data = ap->data;\n\tstore = global_obj;\n\tglobal_obj = ap;\n\tfor (i=0; idescr->compare;\n\tintp min_i, max_i, i, j;\n\tint location, elsize = ap1->itemsize;\n\tintp elements = ap1->dimensions[ap1->nd-1];\n\tintp n = PyArray_Size((PyObject *)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\nstatic PyObject *\nPyArray_SearchSorted(PyArrayObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1, *ap2, *ret;\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->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"compare not supported for type\");\n\t\tgoto fail;\n\t}\n\t\n\tlocal_where(ap1, ap2, ret); \n\t\n\tPy_DECREF(ap1);\n\tPy_DECREF(ap2);\n\treturn (PyObject *)ret;\n\t\n fail:\n\tPy_XDECREF(ap1);\n\tPy_XDECREF(ap2);\n\tPy_XDECREF(ret);\n\treturn NULL;\n}\n\n\n\n/* Could perhaps be redone to not make contiguous arrays \n */\n\nstatic PyObject *\nPyArray_InnerProduct(PyObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1, *ap2, *ret;\n\tintp i, j, l, i1, i2, n1, n2;\n\tint typenum;\n\tintp is1, is2, os;\n\tchar *ip1, *ip2, *op;\n\tintp dimensions[MAX_DIMS], nd;\n\tPyArray_DotFunc *dot;\n\tPyTypeObject *subtype;\n double prior1, prior2;\n\t\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\n\t\t\n\tret = NULL;\n\tap1 = (PyArrayObject *)PyArray_ContiguousFromAny(op1, typenum, \n\t\t\t\t\t\t\t 0, 0);\n\tif (ap1 == NULL) return NULL;\n\tap2 = (PyArrayObject *)PyArray_ContiguousFromAny(op2, typenum, \n\t\t\t\t\t\t\t 0, 0);\n\tif (ap2 == NULL) goto fail;\n\t\n\tif (ap1->nd == 0 || ap2->nd == 0) {\n\t\tret = (ap1->nd == 0 ? ap1 : ap2);\n\t\tret = (PyArrayObject *)ret->ob_type->tp_as_number->\\\n\t\t\tnb_multiply((PyObject *)ap1, (PyObject *)ap2);\n\t\tPy_DECREF(ap1);\n\t\tPy_DECREF(ap2);\n\t\treturn (PyObject *)ret;\n\t}\n\t\n\tl = ap1->dimensions[ap1->nd-1];\n\t\n\tif (ap2->dimensions[ap2->nd-1] != l) {\n\t\tPyErr_SetString(PyExc_ValueError, \"matrices are not aligned\");\n\t\tgoto fail;\n\t}\n\t\n\tif (l == 0) n1 = n2 = 0;\n\telse {\n\t\tn1 = PyArray_SIZE(ap1)/l;\n\t\tn2 = PyArray_SIZE(ap2)/l;\n\t}\n\n\tnd = ap1->nd+ap2->nd-2;\n\tj = 0;\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap1->dimensions[i];\n\t}\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap2->dimensions[i];\n\t}\n\n\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n prior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n prior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n subtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n\n\tret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions, \n\t\t\t\t\t typenum, NULL, NULL, 0, 0, \n (PyObject *)\n\t\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n\tif (ret == NULL) goto fail;\n\n\tdot = (ret->descr->dotfunc);\n\t\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"dot not available for this type\");\n\t\tgoto fail;\n\t}\n\n\t\n\tis1 = ap1->strides[ap1->nd-1]; \n\tis2 = ap2->strides[ap2->nd-1];\n\top = ret->data; os = ret->itemsize;\n\t\n\tip1 = ap1->data;\n\tfor(i1=0; i1data;\n\t\tfor(i2=0; i2nd == 0 || ap2->nd == 0) {\n\t\tret = (ap1->nd == 0 ? ap1 : ap2);\n\t\tret = (PyArrayObject *)ret->ob_type->tp_as_number->\\\n\t\t\tnb_multiply((PyObject *)ap1, (PyObject *)ap2);\n\t\tPy_DECREF(ap1);\n\t\tPy_DECREF(ap2);\n\t\treturn (PyObject *)ret;\n\t}\n\t\n\tl = ap1->dimensions[ap1->nd-1];\n\tif (ap2->nd > 1) {\n\t\tmatchDim = ap2->nd - 2;\n\t\totherDim = ap2->nd - 1;\n\t}\n\telse {\n\t\tmatchDim = 0;\n\t\totherDim = 0;\n\t}\n\n\tif (ap2->dimensions[matchDim] != l) {\n\t\tPyErr_SetString(PyExc_ValueError, \"objects are not aligned\");\n\t\tgoto fail;\n\t}\n\t\n\tif (l == 0) n1 = n2 = 0;\n\telse {\n\t\tn1 = PyArray_SIZE(ap1)/l;\n\t\tn2 = PyArray_SIZE(ap2)/l;\n\t}\n\n\tnd = ap1->nd+ap2->nd-2;\n\tj = 0;\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap1->dimensions[i];\n\t}\n\tfor(i=0; ind-2; i++) {\n\t\tdimensions[j++] = ap2->dimensions[i];\n\t}\n\tif(ap2->nd > 1) {\n\t\tdimensions[j++] = ap2->dimensions[ap2->nd-1];\n\t}\n\t/*\n\tfprintf(stderr, \"nd=%d dimensions=\", nd);\n\t for(i=0; i prior1 ? ap2->ob_type : ap1->ob_type);\n\n\tret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions, \n\t\t\t\t\t typenum, NULL, NULL, 0, 0, \n (PyObject *)\n\t\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n\tif (ret == NULL) goto fail;\n\n\tdot = ret->descr->dotfunc;\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"dot not available for this type\");\n\t\tgoto fail;\n\t}\n\t\t\n\tis1 = ap1->strides[ap1->nd-1]; is2 = ap2->strides[matchDim];\n\tif(ap1->nd > 1)\n\t\tis1r = ap1->strides[ap1->nd-2];\n\telse\n\t\tis1r = ap1->strides[ap1->nd-1];\n\tis2r = ap2->strides[otherDim];\n\n\top = ret->data; os = ret->itemsize;\n\n\tip1 = ap1->data;\n\tfor(i1=0; i1data;\n\t\tfor(i2=0; i2ob_type, 2, dims, PyArray_TYPE(arr),\n\t\t\t NULL, NULL, elsize, 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[ap1->nd-1];\n\tn2 = ap2->dimensions[ap2->nd-1];\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 = (int)(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\t\n\tret = (PyArrayObject *)PyArray_New(ap1->ob_type, 1,\n\t\t\t\t\t &length, typenum, \n\t\t\t\t\t NULL, NULL, 0, 0, \n (PyObject *)ap1);\n\tif (ret == NULL) goto fail;\n\n\t\n\tdot = ret->descr->dotfunc;\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"function not available for this type\");\n\t\tgoto fail;\n\t}\n\t\n\tis1 = ap1->strides[ap1->nd-1]; is2 = ap2->strides[ap2->nd-1];\n\top = ret->data; os = ret->itemsize;\n\t\n\tip1 = ap1->data; ip2 = ap2->data+n_left*is2;\n\tn = n-n_left;\n\tfor(i=0; idescr->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->itemsize;\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 ret = (PyArrayObject *)PyArray_New(self->ob_type, nd, shape, \n\t\t\t\t\t self->descr->type_num,\n\t\t\t\t\t NULL, NULL, 0, 0, \n (PyObject *)self);\n\t\n if (ret == NULL) goto fail;\n\t\n max_item = self->dimensions[axis];\n chunk = chunk * ret->itemsize;\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\nstatic PyObject *\nPyArray_Put(PyArrayObject *self, PyObject *indices0, PyObject* values0) \n{\n PyArrayObject *indices, *values;\n int i, chunk, ni, max_item, nv, tmp; \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->itemsize;\n\n indices = (PyArrayObject *)PyArray_ContiguousFromAny(indices0, PyArray_INTP, 0, 0);\n if (indices == NULL) goto fail;\n ni = PyArray_SIZE(indices);\n\n values = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny(values0, self->descr->type_num, \n\t\t\t\t\t 0, 0);\n if (values == NULL) goto fail;\n nv = PyArray_SIZE(values);\n if (nv > 0) { /* nv == 0 for a null array */\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 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\nstatic PyObject *\nPyArray_PutMask(PyArrayObject *self, PyObject *mask0, PyObject* values0) \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->itemsize;\n\n mask = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny(mask0, PyArray_BOOL, 0, 0);\n if (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\t\tfor(i=0; idata + chunk * (i % nv);\n\t\t\ttmp = ((Bool *)(mask->data))[i];\n\t\t\tif (tmp) {\n\t\t\t\tmemmove(dest + i * chunk, src, chunk);\n\t\t\t\tif (thistype == PyArray_OBJECT)\n\t\t\t\t\tPy_INCREF(*((PyObject **)src));\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 \nstatic int \nPyArray_Converter(PyObject *object, PyObject **address) \n{\n if (PyArray_Check(object)) {\n *address = object;\n\t\tPy_INCREF(object);\n return PY_SUCCEED;\n }\n else {\n\t\t*address = PyArray_FromAny(object, NULL, 0, 0, CARRAY_FLAGS);\n\t\tif (*address == NULL) return PY_FAIL;\n\t\treturn PY_SUCCEED;\n }\n}\n\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\nstatic int\nPyArray_TypestrConvert(int itemsize, int gentype)\n{\n\tregister int newtype = gentype;\n\t\n\tif (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\nstatic int\nPyArray_BufferConverter(PyObject *obj, PyArray_Chunk *buf)\n{\n int buflen;\n\n buf->ptr = NULL;\n buf->flags = WRITEABLE;\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\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) goto fail;\n return PY_SUCCEED;\n\n fail:\n\tPyDimMem_FREE(seq->ptr);\n\treturn PY_FAIL;\n}\n\n/* This function takes a Python object representing a type and converts it \n to a C type_num and an itemsize (elements of PyArray_Typecode structure)\n \n Many objects can be used to represent a type.\n */\n\nstatic int\nPyArray_TypecodeConverter(PyObject *obj, PyArray_Typecode *at)\n{\n char *type;\n PyArray_Descr *descr;\n int check_num=PyArray_NOTYPE+10;\n\tint len;\n\tPyObject *item, *attr=NULL;\n\n\tat->itemsize = 0;\n if (obj == Py_None) {\n at->type_num = PyArray_NOTYPE;\n return PY_SUCCEED;\n }\n\n if (PyType_Check(obj) && PyType_IsSubtype((PyTypeObject *)obj, \n &PyGenericArrType_Type)) {\n PyArray_TypecodeFromTypeObject(obj, at);\n return PY_SUCCEED;\n }\n\n\n\t/* type object could be an array */\n\tif (PyArray_Check(obj)) {\n\t\tat->type_num = PyArray_TYPE(obj);\n\t\tat->itemsize = PyArray_ITEMSIZE(obj);\n\t\treturn PY_SUCCEED;\n\t}\n\n\t/* or an array scalar */\n if (PyArray_IsScalar(obj, Generic)) {\n PyArray_TypecodeFromScalar(obj, at);\n return PY_SUCCEED;\n }\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);\t\t\n\t\tif (len > 0) {\n\t\t\tcheck_num = (int) type[0];\n\t\t}\n\t\tif (len > 1) {\n\t\t\tat->itemsize = atoi(type+1);\n\t\t\t/* When specifying length of UNICODE\n\t\t\t the number of characters is given to match \n\t\t\t the STRING interface. Each character can be\n\t\t\t more than one byte and itemsize must be\n\t\t\t the number of bytes.\n\t\t\t*/\n\t\t\tif (check_num == PyArray_UNICODELTR ||\t\\\n\t\t\t check_num == PyArray_UNICODE) \n\t\t\t at->itemsize *= sizeof(Py_UNICODE);\n\n\t\t\t/* Support for generic processing */\n\t\t\telse if ((check_num != PyArray_STRINGLTR) &&\n\t\t\t\t (check_num != PyArray_VOIDLTR) &&\n\t\t\t\t (check_num != PyArray_STRING) &&\n\t\t\t\t (check_num != PyArray_VOID)) {\n\t\t\t\tcheck_num = \\\n\t\t\t\t\tPyArray_TypestrConvert(at->itemsize,\n\t\t\t\t\t\t\t check_num);\n\t\t\t at->itemsize = 0;\n\t\t\t\tif (check_num == PyArray_NOTYPE) goto fail;\n\t\t\t}\n\t\t}\n\t}\n\t/* Arbitray object with dtypechar and itemsize attributes. */\n\telse if (PyObject_HasAttrString(obj, \"dtypechar\") && \n\t\t PyObject_HasAttrString(obj, \"itemsize\")) {\n\t\tattr = PyObject_GetAttrString(obj, \"dtypechar\");\n\t\tif (attr && PyString_GET_SIZE(attr) > 0) {\n\t\t\ttype = PyString_AsString(attr);\n\t\t\tcheck_num = (int) type[0];\n\t\t}\n\t\tPy_XDECREF(attr);\n\t\tif (!PyErr_Occurred()) {\n\t\t\tattr = PyObject_GetAttrString(obj, \"itemsize\");\n\t\t\tat->itemsize = PyInt_AsLong(attr);\n\t\t\tPy_XDECREF(attr);\n\t\t}\t\t\t\n\t}\t\t\n\telse if (PyType_Check(obj)) {\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 *)(&PyBool_Type))\n\t\t\tcheck_num = PyArray_BOOL;\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 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}\t\n else { /* Default -- try integer conversion */\n\t\t/* Don't allow integer conversion */\n /* check_num = PyInt_AsLong(obj); */\n\t\t/* fprintf(stderr, \"****\\n\\ntype=%s\\n\\n****\\n\", \n\t\t\tobj->ob_type->tp_name);\n\t\t*/\n\t\tgoto fail;\n\t}\n\n\tif (PyErr_Occurred()) goto fail;\n\n\t/*\n\tif (check_num == PyArray_NOTYPE) return PY_FAIL;\n\t*/\n\tif (check_num == PyArray_NOTYPE) {\n\t\tat->type_num = PyArray_NOTYPE;\n\t\tat->itemsize = 0;\n\t\treturn PY_SUCCEED;\n\t}\n\n if ((descr = PyArray_DescrFromType(check_num))==NULL) {\n\t\t/* Now check to see if the object is registered\n\t\t in typeDict */\n\t\tif (typeDict != NULL) {\n\t\t\titem = PyDict_GetItem(typeDict, obj);\n\t\t\tif (item) {\n\t\t\t\tPyArray_TypecodeFromTypeObject(obj, at);\n\t\t\t\tPyErr_Clear();\n\t\t\t\treturn PY_SUCCEED;\n\t\t\t}\n\t\t}\n return PY_FAIL;\n\t}\n\t\n at->type_num = descr->type_num;\n\tif (at->itemsize == 0) at->itemsize = descr->elsize;\n\t\n return PY_SUCCEED;\n\n fail:\n\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\"data type not understood\");\n\treturn PY_FAIL;\n}\t\n\n\n/* This function returns true if the two typecodes are \n equivalent (same basic kind and same itemsize).\n*/\n\nstatic Bool\nPyArray_EquivalentTypes(PyArray_Typecode *typ1, PyArray_Typecode *typ2)\n{\n\tregister int typenum1=typ1->type_num;\n\tregister int typenum2=typ2->type_num;\n\tregister int size1=typ1->itemsize;\n\tregister int size2=typ2->itemsize;\n\n\tif (size1 != size2) return FALSE;\n\tif (typenum1==typenum2) return TRUE;\n\n\t/* If we are here then size1 == size2 */\n\tif (typenum1 < PyArray_FLOAT) {\n\t\tif (PyTypeNum_ISBOOL(typenum1))\n\t\t\treturn (Bool)(PyTypeNum_ISBOOL(typenum2));\n\t\telse if (PyTypeNum_ISUNSIGNED(typenum1))\n\t\t\treturn (Bool)(PyTypeNum_ISUNSIGNED(typenum2));\n\t\telse \n\t\t\treturn (Bool)(PyTypeNum_ISSIGNED(typenum2));\n\t}\n\telse {\n\t\tif (PyTypeNum_ISFLOAT(typenum1))\n\t\t\treturn (Bool)(PyTypeNum_ISFLOAT(typenum2));\n\t\telse if (PyTypeNum_ISCOMPLEX(typenum1))\n\t\t\treturn (Bool)(PyTypeNum_ISCOMPLEX(typenum2));\n\t}\n\t/* Default size1 != size2 and typenum1 != typenum2 */\n\treturn FALSE;\t\n}\n\nstatic Bool \nPyArray_EquivArrTypes(PyArrayObject *a1, PyArrayObject *a2)\n{\n PyArray_Typecode type1={0,0,0};\n PyArray_Typecode type2={0,0,0};\n\n\ttype1.type_num = PyArray_TYPE(a1);\n\ttype2.type_num = PyArray_TYPE(a2);\n\ttype1.itemsize = PyArray_ITEMSIZE(a1);\n\ttype2.itemsize = PyArray_ITEMSIZE(a2);\n\t\t\t\n return PyArray_EquivalentTypes(&type1, &type2);\n}\n\n\n/*** END C-API FUNCTIONS **/\n\n\n#define _ARET(x) PyArray_Return((PyArrayObject *)(x))\n\nstatic char doc_fromobject[] = \"array(object, dtype=None, copy=1, fortran=0, \"\\\n \"subok=0)\\n\"\\\n \"will return a new array formed from the given object type given.\\n\"\\\n \"Object can anything with an __array__ method, or any object\\n\"\\\n \"exposing the array interface, or any (nested) sequence.\\n\"\\\n \"If no type is given, then the type will be determined as the\\n\"\\\n \"minimum type required to hold the objects in the sequence.\\n\"\\\n \"If copy is zero and sequence is already an array with the right \\n\"\\\n \"type, a reference will be returned. If the sequence is an array,\\n\"\\\n \"type can be used only to upcast the array. For downcasting \\n\"\\\n \"use .astype(t) method. If subok is true, then subclasses of the\\n\"\\\n \"array may be returned. Otherwise, a base-class ndarray is returned\";\n\nstatic PyObject *\n_array_fromobject(PyObject *ignored, PyObject *args, PyObject *kws)\n{\n\tPyObject *op, *ret=NULL;\n\tstatic char *kwd[]= {\"object\", \"dtype\", \"copy\", \"fortran\", \"subok\", \n NULL};\n Bool subok=FALSE;\n\tBool copy=TRUE;\n\tPyArray_Typecode type = {PyArray_NOTYPE, 0, 0};\n\tPyArray_Typecode oldtype = {PyArray_NOTYPE, 0, 0};\n\tint type_num;\n\tBool fortran=FALSE;\n\tint flags=0;\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kws, \"O|O&O&O&O&\", kwd, &op, \n\t\t\t\t\tPyArray_TypecodeConverter,\n &type, \n\t\t\t\t\tPyArray_BoolConverter, ©, \n\t\t\t\t\tPyArray_BoolConverter, &fortran,\n PyArray_BoolConverter, &subok)) \n\t\treturn NULL;\n\ttype_num = type.type_num;\n\n\t/* fast exit if simple call */\n\tif ((PyArray_CheckExact(op) && PyBigArray_CheckExact(op)) && \\\n (copy==0) && \\\n\t (fortran == PyArray_CHKFLAGS(op, FORTRAN))) {\n\t\tif (type_num == PyArray_NOTYPE) {\n\t\t\tPy_INCREF(op);\n\t\t\treturn op;\n\t\t}\n\t\t/* One more chance */\n\t\toldtype.type_num = PyArray_TYPE(op);\n\t\toldtype.itemsize = PyArray_ITEMSIZE(op);\n\t\tif (PyArray_EquivalentTypes(&oldtype, &type)) {\n\t\t\tPy_INCREF(op);\n\t\t\treturn op;\n\t\t}\n\t}\n\n\ttype.fortran = fortran; \n\tif (copy) {\n\t\tflags = ENSURECOPY;\n\t}\n if (!subok) {\n flags |= ENSUREARRAY;\n }\n\n\tif ((ret = PyArray_FromAny(op, &type, 0, 0, flags)) == NULL) \n\t\treturn NULL;\n\n\treturn ret;\n}\n\nstatic PyObject *\nPyArray_Empty(int nd, intp *dims, PyArray_Typecode *type)\n{\n\tPyArrayObject *ret;\n\tintp n;\n \n\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, nd, dims, \n\t\t\t\t\t type->type_num,\n\t\t\t\t\t NULL, NULL, type->itemsize, \n\t\t\t\t\t type->fortran, NULL);\n\tif (ret == NULL) return NULL;\n \n\tn = PyArray_SIZE(ret);\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=intp,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_Typecode typecode = {PyArray_NOTYPE, 0, 0};\n PyArray_Dims shape;\n\tBool fortran = FALSE;\t\n PyObject *ret;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &shape, \n PyArray_TypecodeConverter,\n\t\t\t\t\t &typecode, \n\t\t\t\t\t PyArray_BoolConverter, &fortran)) \n\t\treturn NULL;\n\t\n\ttypecode.fortran = fortran;\n if (typecode.type_num ==PyArray_NOTYPE) \n\t\ttypecode.type_num = PyArray_INTP;\n \n\tret = PyArray_Empty(shape.len, shape.ptr, &typecode); \n PyDimMem_FREE(shape.ptr);\n return ret;\n}\n\nstatic char doc_scalar[] = \"scalar(dtypestr,obj) will return a new scalar array of the given type initialized with obj. Mainly for pickle support. typestr must be a valid data typestr (complete with < > or |). If dtypestr is object, 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[] = {\"dtypestr\",\"obj\", NULL};\n\tPyArray_Typecode typecode;\n\tPyObject *obj=NULL;\n\tchar *typestr;\n\tint typestrlen;\n\tint swap, alloc=0;\n\tvoid *dptr;\n\tPyObject *ret;\n\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"z#|O\",\n\t\t\t\t\t kwlist, &typestr, &typestrlen,\n\t\t\t\t\t &obj)) \n\t\treturn NULL;\n\t\n\tif (_array_typecode_fromstr(typestr, &swap, &typecode) < 0) \n\t\treturn NULL;\n\t\n\tif (typecode.itemsize == 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\tswap = 0;\n\t}\n\telse {\n\t\tif (obj == NULL) {\n\t\t\tdptr = malloc(typecode.itemsize);\n\t\t\tif (dptr == NULL) {\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tmemset(dptr, '\\0', typecode.itemsize);\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.itemsize) {\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.type_num,\n\t\t\t typecode.itemsize, swap); \n\n\t/* free dptr which contains zeros */\n\tif (alloc) free(dptr);\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_Zeros(int nd, intp *dims, PyArray_Typecode *type)\n{\n\tPyArrayObject *ret;\n\tintp n;\n\n\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, nd, dims, \n\t\t\t\t\t type->type_num,\n\t\t\t\t\t NULL, NULL, type->itemsize, \n\t\t\t\t\t type->fortran, NULL);\n\tif (ret == NULL) return NULL;\n \n\tn = PyArray_SIZE(ret);\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 {\t\t\n\t\tmemset(ret->data, 0, n*(ret->itemsize));\n\t}\n\treturn (PyObject *)ret;\n\n}\n\nstatic char doc_zeros[] = \"zeros((d1,...,dn),dtype=intp,fortran=0) will return a new array of shape (d1,...,dn) and type typecode with all it's entries initialized to zero.\";\n\n\nstatic PyObject *\narray_zeros(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {\"shape\",\"dtype\",\"fortran\",NULL};\n\tPyArray_Typecode typecode = {PyArray_NOTYPE, 0, 0};\n PyArray_Dims shape;\n\tBool fortran = FALSE;\t\n PyObject *ret;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &shape, \n PyArray_TypecodeConverter,\n\t\t\t\t\t &typecode, \n\t\t\t\t\t PyArray_BoolConverter,\n\t\t\t\t\t &fortran)) \n\t\treturn NULL;\n\t\n\ttypecode.fortran = fortran;\n if (typecode.type_num ==PyArray_NOTYPE) \n\t\ttypecode.type_num = PyArray_INTP;\n \n\tret = PyArray_Zeros(shape.len, shape.ptr, &typecode); \n PyDimMem_FREE(shape.ptr);\n return 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 char doc_fromString[] = \"fromstring(string, dtype=intp, count=-1, swap=False) 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\tPyArrayObject *ret; \n\tchar *data;\n\tlonglong nin=-1;\n\tintp s, n;\n\tstatic char *kwlist[] = {\"string\", \"dtype\", \"count\", \"swap\",NULL};\n\tPyArray_Typecode type = {PyArray_INTP, sizeof(intp), 0};\n\tint itemsize;\n\tint swapped=FALSE;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"s#|O&LO&\", kwlist, \n\t\t\t\t\t &data, &s, \n\t\t\t\t\t PyArray_TypecodeConverter, &type,\n\t\t\t\t\t &nin, \n\t\t\t\t\t PyArray_BoolConverter,\n\t\t\t\t\t &swapped)) {\n\t\treturn NULL;\n\t}\n\t\n\tn = (intp) nin;\n\n\titemsize = type.itemsize;\n\tif (itemsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \"zero-valued itemsize\");\n\t\treturn NULL;\n\t}\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\"string size must be a multiple\"\\\n\t\t\t\t\t\" of element size\");\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\"string is smaller than requested\"\\\n\t\t\t\t\t\" size\");\n\t\t\treturn NULL;\n\t\t}\n\t}\n\n\tif ((ret = (PyArrayObject *)PyArray_New(&PyArray_Type, 1, &n, \n\t\t\t\t\t\ttype.type_num, NULL, \n\t\t\t\t\t\tNULL, itemsize, 0,\n\t\t\t\t\t\tNULL)) == NULL)\n\t\treturn NULL;\n\t\t\n\tmemcpy(ret->data, data, n*ret->itemsize);\n\tif (swapped) ret->flags &= ~NOTSWAPPED;\n\tPyArray_INCREF(ret);\n\treturn (PyObject *)ret;\n}\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\nstatic int\n_fill_in_itemsize(PyArray_Typecode *typecode)\n{\n\tPyArray_Descr *descr;\n\tdescr = PyArray_DescrFromType(typecode->type_num);\n\tif (descr==NULL) return -1;\n\ttypecode->itemsize = descr->elsize;\n\treturn 0;\n}\n\n\nstatic PyObject *\nPyArray_FromFile(FILE *fp, PyArray_Typecode *typecode, intp num, char *sep)\n{\n\tPyArrayObject *r;\n\tsize_t nread = 0;\n\tPyArray_ScanFunc *scan;\n\n\tif (typecode->itemsize == 0) {\n\t\tif (_fill_in_itemsize(typecode) < 0) \n\t\t\treturn NULL;\n\t}\n\n\tif (num == -1 && sep == NULL) { /* 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\tfseek(fp, (long) start, SEEK_SET);\n\t\tif (numbytes == -1) {\n\t\t\tPyErr_SetString(PyExc_IOError, \"could not seek in file\");\n\t\t\treturn NULL;\n\t\t}\n\t\tif (typecode->itemsize == 0) {\n\t\t\ttypecode->itemsize = numbytes;\n\t\t\tnum = 1;\n\t\t}\n\t\telse {\n\t\t\tnum = numbytes / typecode->itemsize;\n\t\t}\n\t}\n\t\n\tif (sep==NULL) { /* binary data */\n\t\tr = (PyArrayObject *)PyArray_New(&PyArray_Type, 1, &num, \n\t\t\t\t\t\t typecode->type_num,\n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t typecode->itemsize, 0, NULL);\n\t\tif (r==NULL) return NULL;\n\t\tnread = fread(r->data, typecode->itemsize, 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 = PyArray_DescrFromType(typecode->type_num)->scanfunc;\n\t\tif (scan == NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"don't know how to read \"\t\\\n\t\t\t\t\t\"character files with that \"\t\\\n\t\t\t\t\t\"array type\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (num != -1) { /* number to read is known */\n\t\t\tr = (PyArrayObject *)PyArray_New(&PyArray_Type, 1, \n\t\t\t\t\t\t\t &num, \n\t\t\t\t\t\t\t typecode->type_num,\n\t\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t\t typecode->itemsize, \n\t\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, r->itemsize, sep, NULL);\n\t\t\t\tif (done < -2) break;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += r->itemsize;\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 *)PyArray_New(&PyArray_Type, 1, \n\t\t\t\t\t\t\t &size, \n\t\t\t\t\t\t\t typecode->type_num,\n\t\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t\t typecode->itemsize, \n\t\t\t\t\t\t\t 0, NULL);\n\t\t\tif (r==NULL) return NULL;\n\t\t\ttotalbytes = bytes = size * typecode->itemsize;\n\t\t\tdptr = r->data;\n\t\t\twhile (!done) {\n\t\t\t\tdone = scan(fp, dptr, r->itemsize, 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->itemsize;\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->itemsize);\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->itemsize);\n\t\tPyArray_DIM(r,0) = nread;\n\t}\n\treturn (PyObject *)r;\n}\n\nstatic char doc_fromfile[] = \\\n\t\"fromfile(file=, dtype=intp, count=-1, sep='')\\n\"\\\n\t\"\\n\"\\\n\t\" Return an array of the given data type from a \\n\"\\\n\t\" (text or binary) file. The file argument can be an open file\\n\"\\\n\t\" or a string with the name of a file to read from. If\\n\"\\\n\t\" count==-1, then the entire file is read, otherwise count is\\n\"\\\n\t\" the number of items of the given type read in. If sep is ''\\n\"\\\n\t\" then read a binary file, otherwise it gives the separator\\n\"\\\n\t\" between elements in a text file.\\n\"\\\n\t\"\\n\"\\\n\t\" WARNING: This function should be used sparingly, as it is not\\n\"\\\n\t\" a robust method of persistence. But it can be useful to\\n\"\\\n\t\" read in simply-formatted or binary data quickly.\";\n\nstatic PyObject *\narray_fromfile(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tPyObject *file=NULL, *ret;\n\tFILE *fp;\n\tchar *sep=\"\";\n\tchar *mode=NULL;\n\tlonglong nin=-1;\n\tstatic char *kwlist[] = {\"file\", \"dtype\", \"count\", \"sep\", NULL};\n\tPyArray_Typecode type = {PyArray_INTP, sizeof(intp), 0};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"O|O&Ls\", kwlist, \n\t\t\t\t\t &file,\n\t\t\t\t\t PyArray_TypecodeConverter, &type,\n\t\t\t\t\t &nin, &sep)) {\n\t\treturn NULL;\n\t}\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, \"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\nstatic PyObject *\nPyArray_FromBuffer(PyObject *buf, PyArray_Typecode *type, \n\t\t intp count, int swapped) \n{\n\tPyArrayObject *ret;\n\tchar *data;\n\tint ts;\n\tintp s, n;\n\tint itemsize;\n\tint write=1;\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\treturn NULL;\n\t}\n\tif (type->itemsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"itemsize cannot be zero in type\");\n\t\treturn NULL;\n\t}\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\treturn NULL;\n\t\t}\n\t}\n\ts = (intp)ts;\t\n\tn = (intp)count;\n\titemsize = type->itemsize;\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\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\treturn NULL;\n\t\t}\n\t}\n\t\n\tif ((ret = (PyArrayObject *)PyArray_New(&PyArray_Type, 1, &n, \n\t\t\t\t\t\ttype->type_num, NULL, \n\t\t\t\t\t\tdata, itemsize, DEFAULT_FLAGS,\n\t\t\t\t\t\tNULL)) == NULL)\n\t\treturn NULL;\n\t\n\tif (!write) ret->flags &= ~WRITEABLE;\n\tif (swapped) ret->flags &= ~NOTSWAPPED;\n\tPy_INCREF(buf);\n\t/* Store a reference for decref on deallocation */\n\tret->base = buf;\n\tPyArray_UpdateFlags(ret, ALIGNED);\n\treturn (PyObject *)ret; \t\n}\n\nstatic char doc_frombuffer[] = \\\n\t\"frombuffer(buffer=, dtype=intp, count=-1, swap=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 the buffer has data that is out\\n\" \\\n\t\" not in machine byte-order, than set swap=1. 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;\n\tstatic char *kwlist[] = {\"buffer\", \"dtype\", \"count\", \n\t\t\t\t \"swap\", NULL};\n\tPyArray_Typecode type = {PyArray_INTP, sizeof(intp), 0};\n\tint swapped=0;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"O|O&Li\", kwlist, \n\t\t\t\t\t &obj,\n\t\t\t\t\t PyArray_TypecodeConverter, &type,\n\t\t\t\t\t &nin, &swapped)) {\n\t\treturn NULL;\n\t}\n\n\treturn PyArray_FromBuffer(obj, &type, (intp)nin, swapped);\n}\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\nstatic PyObject *\nPyArray_Arange(double start, double stop, double step, int type_num)\n{\n\tintp length, i;\n\tPyObject *range;\n\tchar *rptr;\n\tint elsize, type;\n\tdouble value;\n\tPyArray_Descr *dbl_descr;\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\tdbl_descr = PyArray_DescrFromType(PyArray_DOUBLE);\n \n\trptr = ((PyArrayObject *)range)->data;\n\telsize = ((PyArrayObject *)range)->itemsize;\n\ttype = ((PyArrayObject *)range)->descr->type_num;\n\tfor (i=0; i < length; i++) {\n\t\tvalue = start + i*step;\n\t\tdbl_descr->cast[type]((char*)&value, rptr, 1, NULL, \n\t\t\t\t (PyArrayObject *)range);\n\t\trptr += elsize;\n\t}\n \n\treturn range;\n}\n\n\nstatic char doc_arange[] = \"arange(start, stop=None, step=1, dtype=intp)\\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=Py_None, *o_step=NULL;\n\tstatic char *kwd[]= {\"start\", \"stop\", \"step\", \"dtype\", NULL};\n\tdouble start, stop, step;\n\tPyArray_Typecode typecode = {PyArray_NOTYPE, 0};\n\tint type_num;\n\tint deftype = PyArray_INTP;\n\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_TypecodeConverter, \n\t\t\t\t\t&typecode)) \n\t\treturn NULL;\n\n\tdeftype = PyArray_ObjectType(o_start, deftype);\n\tif (o_stop != Py_None) {\n\t\tdeftype = PyArray_ObjectType(o_stop, deftype);\n\t}\n\tif (o_step != NULL) {\n\t\tdeftype = PyArray_ObjectType(o_step, deftype);\n\t}\n\n\ttype_num = typecode.type_num;\n\tif (type_num == PyArray_NOTYPE) {\n\t\ttype_num = deftype;\n\t}\n\n\tstart = PyFloat_AsDouble(o_start);\n\tif error_converting(start) return NULL;\n\n\tif (o_step == NULL) {\n\t\tstep = 1;\n\t}\n\telse {\n\t\tstep = PyFloat_AsDouble(o_step);\n\t\tif error_converting(step) return NULL;\n\t}\n\n\tif (o_stop == Py_None) {\n\t\tstop = start;\n\t\tstart = 0;\n\t}\n\telse {\n\t\tstop = PyFloat_AsDouble(o_stop);\n\t\tif error_converting(stop) return NULL;\n\t}\n\n\treturn PyArray_Arange(start, stop, step, type_num);\n}\n\n#undef _ARET\n\n/*****\n static char doc_arrayMap[] = \"arrayMap(func, [a1,...,an])\";\n\n static PyObject *array_arrayMap(PyObject *dummy, PyObject *args) {\n PyObject *shape, *a0;\n \n if (PyArg_ParseTuple(args, \"OO\", &a0, &shape) == NULL) return NULL;\n\t\n return PyArray_Map(a0, shape);\n }\n*****/\n\nstatic char \ndoc_set_string_function[] = \"set_string_function(f, repr=1) sets the python function f to be the function used to obtain a pretty printable string version of a array whenever a array is printed. f(M) should expect a array argument M, and should return a string consisting of the desired representation of M for printing.\";\n\nstatic PyObject *\narray_set_string_function(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tPyObject *op;\n\tint repr=1;\n\tstatic char *kwlist[] = {\"f\", \"repr\", NULL};\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"O|i\", kwlist, \n\t\t\t\t\t&op, &repr)) return NULL; \n\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 (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\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\tif ((x==NULL) || (y==NULL)) {\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\tarr = (PyArrayObject *)PyArray_FromAny(condition, NULL, 0, 0, 0);\n\tif (arr == NULL) return NULL;\n\n\tif ((x==NULL) && (y==NULL)) {\n\t\tret = PyArray_Nonzero(arr);\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\n\tzero = PyInt_FromLong((long) 0);\n\n\tobj = PyArray_EnsureArray(PyArray_GenericBinaryFunction(arr, zero, n_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_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_Typecode d1={PyArray_NOTYPE, 0, 0};\n\tPyArray_Typecode d2={PyArray_NOTYPE, 0, 0};\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_TypecodeConverter, &d1,\n\t\t\t\t\tPyArray_TypecodeConverter, &d2))\n\t\treturn NULL;\n\tif (d1.type_num == PyArray_NOTYPE || \\\n\t d2.type_num == PyArray_NOTYPE) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"did not understand one of the types; \"\\\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 struct PyMethodDef array_module_methods[] = {\n\t{\"set_string_function\", (PyCFunction)array_set_string_function, \n\t METH_VARARGS|METH_KEYWORDS, doc_set_string_function},\n\t{\"set_numeric_ops\", (PyCFunction)array_set_ops_function,\n\t METH_VARARGS|METH_KEYWORDS, doc_set_ops_function},\n\t{\"set_typeDict\", (PyCFunction)array_set_typeDict,\n\t METH_VARARGS, doc_set_typeDict},\n\n\t{\"array\",\t(PyCFunction)_array_fromobject, \n\t METH_VARARGS|METH_KEYWORDS, doc_fromobject},\n\t{\"arange\", (PyCFunction)array_arange, \n\t METH_VARARGS|METH_KEYWORDS, doc_arange},\n\t{\"zeros\",\t(PyCFunction)array_zeros, \n\t METH_VARARGS|METH_KEYWORDS, doc_zeros},\n\t{\"empty\",\t(PyCFunction)array_empty, \n\t METH_VARARGS|METH_KEYWORDS, doc_empty},\n\t{\"scalar\", (PyCFunction)array_scalar,\n\t METH_VARARGS|METH_KEYWORDS, doc_scalar},\n\t{\"where\", (PyCFunction)array_where,\n\t METH_VARARGS, doc_where},\n\t{\"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/* {\"arrayMap\",\t(PyCFunction)array_arrayMap, \n\t METH_VARARGS, doc_arrayMap},*/\n\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(Numeric, Generic);\n SINGLE_INHERIT(Integer, Numeric);\n SINGLE_INHERIT(Inexact, Numeric);\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 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 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 SINGLE_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\t \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, \"NOTSWAPPED\", s=PyInt_FromLong(NOTSWAPPED));\n Py_DECREF(s);\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\tif (PyType_Ready(&PyArrayIter_Type) < 0)\n\t\treturn; \n \n\tif (PyType_Ready(&PyArrayMapIter_Type) < 0)\n return; \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\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) \n return; /* otherwise there is an error */\n\n\n err:\t\n\t/* Check for errors */\n\tif (PyErr_Occurred())\n PyErr_Print();\n\t\tPy_FatalError(\"can't initialize module multiarray\");\n\n\treturn;\n}\n\n", "methods": [ { "name": "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": 51, "end_line": 56, "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": 59, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "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": 68, "end_line": 80, "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": 83, "end_line": 90, "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_Typecode * type)", "filename": "multiarraymodule.c", "nloc": 42, "complexity": 9, "token_count": 245, "parameters": [ "self", "type" ], "start_line": 93, "end_line": 141, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "PyArray_Ravel", "long_name": "PyArray_Ravel( PyArrayObject * a , int fortran)", "filename": "multiarraymodule.c", "nloc": 14, "complexity": 4, "token_count": 87, "parameters": [ "a", "fortran" ], "start_line": 144, "end_line": 158, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "PyArray_Flatten", "long_name": "PyArray_Flatten( PyArrayObject * a , int fortran)", "filename": "multiarraymodule.c", "nloc": 32, "complexity": 5, "token_count": 162, "parameters": [ "a", "fortran" ], "start_line": 161, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "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": 202, "end_line": 211, "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": 214, "end_line": 240, "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": 75, "complexity": 17, "token_count": 411, "parameters": [ "self", "newdims" ], "start_line": 248, "end_line": 339, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 92, "top_nesting_level": 0 }, { "name": "PyArray_Squeeze", "long_name": "PyArray_Squeeze( PyArrayObject * self)", "filename": "multiarraymodule.c", "nloc": 30, "complexity": 4, "token_count": 192, "parameters": [ "self" ], "start_line": 347, "end_line": 378, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "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": 382, "end_line": 403, "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)", "filename": "multiarraymodule.c", "nloc": 43, "complexity": 12, "token_count": 433, "parameters": [ "self", "axis", "rtype" ], "start_line": 406, "end_line": 461, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 56, "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": 465, "end_line": 475, "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": 478, "end_line": 488, "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": 491, "end_line": 501, "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": 504, "end_line": 515, "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": 518, "end_line": 529, "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": 532, "end_line": 543, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_Compress", "long_name": "PyArray_Compress( PyArrayObject * self , PyObject * condition , int axis)", "filename": "multiarraymodule.c", "nloc": 18, "complexity": 3, "token_count": 110, "parameters": [ "self", "condition", "axis" ], "start_line": 547, "end_line": 567, "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": 50, "complexity": 13, "token_count": 403, "parameters": [ "self" ], "start_line": 570, "end_line": 628, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 59, "top_nesting_level": 0 }, { "name": "PyArray_Clip", "long_name": "PyArray_Clip( PyArrayObject * self , PyObject * min , PyObject * max)", "filename": "multiarraymodule.c", "nloc": 30, "complexity": 6, "token_count": 241, "parameters": [ "self", "min", "max" ], "start_line": 631, "end_line": 664, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "top_nesting_level": 0 }, { "name": "PyArray_Conjugate", "long_name": "PyArray_Conjugate( PyArrayObject * self)", "filename": "multiarraymodule.c", "nloc": 36, "complexity": 9, "token_count": 225, "parameters": [ "self" ], "start_line": 667, "end_line": 703, "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": 706, "end_line": 716, "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": 106, "complexity": 24, "token_count": 808, "parameters": [ "self", "offset", "axis1", "axis2" ], "start_line": 719, "end_line": 840, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 122, "top_nesting_level": 0 }, { "name": "PyArray_AsCArray", "long_name": "PyArray_AsCArray( PyObject ** op , * ptr , intp * dims , int nd , int type_num)", "filename": "multiarraymodule.c", "nloc": 55, "complexity": 13, "token_count": 432, "parameters": [ "op", "ptr", "dims", "nd", "type_num" ], "start_line": 857, "end_line": 913, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 57, "top_nesting_level": 0 }, { "name": "PyArray_As1D", "long_name": "PyArray_As1D( PyObject ** op , char ** ptr , int * d1 , int typecode)", "filename": "multiarraymodule.c", "nloc": 8, "complexity": 2, "token_count": 60, "parameters": [ "op", "ptr", "d1", "typecode" ], "start_line": 918, "end_line": 926, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "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": 9, "complexity": 2, "token_count": 81, "parameters": [ "op", "ptr", "d1", "d2", "typecode" ], "start_line": 930, "end_line": 940, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "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": 945, "end_line": 956, "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": 960, "end_line": 988, "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": 114, "complexity": 24, "token_count": 771, "parameters": [ "op", "axis" ], "start_line": 997, "end_line": 1125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 129, "top_nesting_level": 0 }, { "name": "PyArray_SwapAxes", "long_name": "PyArray_SwapAxes( PyArrayObject * ap , int a1 , int a2)", "filename": "multiarraymodule.c", "nloc": 37, "complexity": 12, "token_count": 227, "parameters": [ "ap", "a1", "a2" ], "start_line": 1128, "end_line": 1167, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 }, { "name": "PyArray_Transpose", "long_name": "PyArray_Transpose( PyArrayObject * ap , PyObject * op)", "filename": "multiarraymodule.c", "nloc": 49, "complexity": 15, "token_count": 403, "parameters": [ "ap", "op" ], "start_line": 1171, "end_line": 1230, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 60, "top_nesting_level": 0 }, { "name": "PyArray_Repeat", "long_name": "PyArray_Repeat( PyArrayObject * aop , PyObject * op , int axis)", "filename": "multiarraymodule.c", "nloc": 75, "complexity": 15, "token_count": 520, "parameters": [ "aop", "op", "axis" ], "start_line": 1233, "end_line": 1325, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 93, "top_nesting_level": 0 }, { "name": "PyArray_Choose", "long_name": "PyArray_Choose( PyArrayObject * ip , PyObject * op)", "filename": "multiarraymodule.c", "nloc": 89, "complexity": 18, "token_count": 650, "parameters": [ "ip", "op" ], "start_line": 1329, "end_line": 1441, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 113, "top_nesting_level": 0 }, { "name": "qsortCompare", "long_name": "qsortCompare( const * a , const * b)", "filename": "multiarraymodule.c", "nloc": 4, "complexity": 1, "token_count": 28, "parameters": [ "a", "b" ], "start_line": 1449, "end_line": 1452, "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)", "filename": "multiarraymodule.c", "nloc": 36, "complexity": 7, "token_count": 250, "parameters": [ "op", "axis" ], "start_line": 1474, "end_line": 1523, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "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": 63, "parameters": [ "ip1", "ip2" ], "start_line": 1529, "end_line": 1537, "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)", "filename": "multiarraymodule.c", "nloc": 48, "complexity": 8, "token_count": 350, "parameters": [ "op", "axis" ], "start_line": 1540, "end_line": 1599, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 60, "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": 1602, "end_line": 1637, "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": 223, "parameters": [ "op1", "op2" ], "start_line": 1640, "end_line": 1685, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 46, "top_nesting_level": 0 }, { "name": "PyArray_InnerProduct", "long_name": "PyArray_InnerProduct( PyObject * op1 , PyObject * op2)", "filename": "multiarraymodule.c", "nloc": 83, "complexity": 17, "token_count": 657, "parameters": [ "op1", "op2" ], "start_line": 1693, "end_line": 1796, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 104, "top_nesting_level": 0 }, { "name": "PyArray_MatrixProduct", "long_name": "PyArray_MatrixProduct( PyObject * op1 , PyObject * op2)", "filename": "multiarraymodule.c", "nloc": 101, "complexity": 20, "token_count": 783, "parameters": [ "op1", "op2" ], "start_line": 1801, "end_line": 1925, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 125, "top_nesting_level": 0 }, { "name": "PyArray_CopyAndTranspose", "long_name": "PyArray_CopyAndTranspose( PyObject * op)", "filename": "multiarraymodule.c", "nloc": 44, "complexity": 6, "token_count": 278, "parameters": [ "op" ], "start_line": 1928, "end_line": 1979, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 0 }, { "name": "PyArray_Correlate", "long_name": "PyArray_Correlate( PyObject * op1 , PyObject * op2 , int mode)", "filename": "multiarraymodule.c", "nloc": 89, "complexity": 13, "token_count": 625, "parameters": [ "op1", "op2", "mode" ], "start_line": 1982, "end_line": 2080, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 99, "top_nesting_level": 0 }, { "name": "PyArray_ArgMin", "long_name": "PyArray_ArgMin( PyArrayObject * ap , int axis)", "filename": "multiarraymodule.c", "nloc": 21, "complexity": 5, "token_count": 138, "parameters": [ "ap", "axis" ], "start_line": 2083, "end_line": 2108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "PyArray_Max", "long_name": "PyArray_Max( PyArrayObject * ap , int axis)", "filename": "multiarraymodule.c", "nloc": 11, "complexity": 2, "token_count": 67, "parameters": [ "ap", "axis" ], "start_line": 2111, "end_line": 2122, "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": 67, "parameters": [ "ap", "axis" ], "start_line": 2125, "end_line": 2136, "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": 2139, "end_line": 2162, "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": 322, "parameters": [ "op", "axis" ], "start_line": 2166, "end_line": 2223, "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": 62, "complexity": 12, "token_count": 468, "parameters": [ "self0", "indices0", "axis" ], "start_line": 2227, "end_line": 2299, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 73, "top_nesting_level": 0 }, { "name": "PyArray_Put", "long_name": "PyArray_Put( PyArrayObject * self , PyObject * indices0 , PyObject * values0)", "filename": "multiarraymodule.c", "nloc": 47, "complexity": 10, "token_count": 319, "parameters": [ "self", "indices0", "values0" ], "start_line": 2302, "end_line": 2354, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "top_nesting_level": 0 }, { "name": "PyArray_PutMask", "long_name": "PyArray_PutMask( PyArrayObject * self , PyObject * mask0 , PyObject * values0)", "filename": "multiarraymodule.c", "nloc": 56, "complexity": 10, "token_count": 334, "parameters": [ "self", "mask0", "values0" ], "start_line": 2357, "end_line": 2419, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 63, "top_nesting_level": 0 }, { "name": "PyArray_Converter", "long_name": "PyArray_Converter( PyObject * object , PyObject ** address)", "filename": "multiarraymodule.c", "nloc": 13, "complexity": 3, "token_count": 66, "parameters": [ "object", "address" ], "start_line": 2431, "end_line": 2443, "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": 2446, "end_line": 2454, "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": 90, "complexity": 33, "token_count": 284, "parameters": [ "itemsize", "gentype" ], "start_line": 2458, "end_line": 2567, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 110, "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": 2582, "end_line": 2607, "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": 35, "complexity": 10, "token_count": 186, "parameters": [ "obj", "seq" ], "start_line": 2619, "end_line": 2655, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "PyArray_TypecodeConverter", "long_name": "PyArray_TypecodeConverter( PyObject * obj , PyArray_Typecode * at)", "filename": "multiarraymodule.c", "nloc": 106, "complexity": 34, "token_count": 629, "parameters": [ "obj", "at" ], "start_line": 2664, "end_line": 2805, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 142, "top_nesting_level": 0 }, { "name": "PyArray_EquivalentTypes", "long_name": "PyArray_EquivalentTypes( PyArray_Typecode * typ1 , PyArray_Typecode * typ2)", "filename": "multiarraymodule.c", "nloc": 24, "complexity": 8, "token_count": 162, "parameters": [ "typ1", "typ2" ], "start_line": 2813, "end_line": 2840, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "PyArray_EquivArrTypes", "long_name": "PyArray_EquivArrTypes( PyArrayObject * a1 , PyArrayObject * a2)", "filename": "multiarraymodule.c", "nloc": 10, "complexity": 1, "token_count": 80, "parameters": [ "a1", "a2" ], "start_line": 2843, "end_line": 2854, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_EquivalentTypenums", "long_name": "PyArray_EquivalentTypenums( int typenum1 , int typenum2)", "filename": "multiarraymodule.c", "nloc": 10, "complexity": 1, "token_count": 76, "parameters": [ "typenum1", "typenum2" ], "start_line": 2858, "end_line": 2869, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "_array_fromobject", "long_name": "_array_fromobject( PyObject * ignored , PyObject * args , PyObject * kws)", "filename": "multiarraymodule.c", "nloc": 45, "complexity": 11, "token_count": 282, "parameters": [ "ignored", "args", "kws" ], "start_line": 2891, "end_line": 2942, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 0 }, { "name": "PyArray_Empty", "long_name": "PyArray_Empty( int nd , intp * dims , PyArray_Typecode * type)", "filename": "multiarraymodule.c", "nloc": 15, "complexity": 3, "token_count": 99, "parameters": [ "nd", "dims", "type" ], "start_line": 2945, "end_line": 2961, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "array_empty", "long_name": "array_empty( PyObject * ignored , PyObject * args , PyObject * kwds)", "filename": "multiarraymodule.c", "nloc": 21, "complexity": 3, "token_count": 134, "parameters": [ "ignored", "args", "kwds" ], "start_line": 2967, "end_line": 2991, "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": 56, "complexity": 11, "token_count": 290, "parameters": [ "ignored", "args", "kwds" ], "start_line": 2996, "end_line": 3060, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 65, "top_nesting_level": 0 }, { "name": "PyArray_Zeros", "long_name": "PyArray_Zeros( int nd , intp * dims , PyArray_Typecode * type)", "filename": "multiarraymodule.c", "nloc": 20, "complexity": 3, "token_count": 133, "parameters": [ "nd", "dims", "type" ], "start_line": 3064, "end_line": 3086, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "array_zeros", "long_name": "array_zeros( PyObject * ignored , PyObject * args , PyObject * kwds)", "filename": "multiarraymodule.c", "nloc": 22, "complexity": 3, "token_count": 134, "parameters": [ "ignored", "args", "kwds" ], "start_line": 3092, "end_line": 3116, "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": 3123, "end_line": 3132, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "array_fromString", "long_name": "array_fromString( PyObject * ignored , PyObject * args , PyObject * keywds)", "filename": "multiarraymodule.c", "nloc": 50, "complexity": 8, "token_count": 283, "parameters": [ "ignored", "args", "keywds" ], "start_line": 3137, "end_line": 3192, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 56, "top_nesting_level": 0 }, { "name": "_fill_in_itemsize", "long_name": "_fill_in_itemsize( PyArray_Typecode * typecode)", "filename": "multiarraymodule.c", "nloc": 8, "complexity": 2, "token_count": 42, "parameters": [ "typecode" ], "start_line": 3207, "end_line": 3214, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_FromFile", "long_name": "PyArray_FromFile( FILE * fp , PyArray_Typecode * typecode , intp num , char * sep)", "filename": "multiarraymodule.c", "nloc": 113, "complexity": 23, "token_count": 682, "parameters": [ "fp", "typecode", "num", "sep" ], "start_line": 3218, "end_line": 3345, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 128, "top_nesting_level": 0 }, { "name": "array_fromfile", "long_name": "array_fromfile( PyObject * ignored , PyObject * args , PyObject * keywds)", "filename": "multiarraymodule.c", "nloc": 34, "complexity": 6, "token_count": 221, "parameters": [ "ignored", "args", "keywds" ], "start_line": 3363, "end_line": 3398, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "PyArray_FromBuffer", "long_name": "PyArray_FromBuffer( PyObject * buf , PyArray_Typecode * type , intp count , int swapped)", "filename": "multiarraymodule.c", "nloc": 58, "complexity": 11, "token_count": 306, "parameters": [ "buf", "type", "count", "swapped" ], "start_line": 3401, "end_line": 3464, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 64, "top_nesting_level": 0 }, { "name": "array_frombuffer", "long_name": "array_frombuffer( PyObject * ignored , PyObject * args , PyObject * keywds)", "filename": "multiarraymodule.c", "nloc": 16, "complexity": 2, "token_count": 115, "parameters": [ "ignored", "args", "keywds" ], "start_line": 3478, "end_line": 3495, "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": 3502, "end_line": 3513, "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": 3520, "end_line": 3526, "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": 3533, "end_line": 3539, "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": 3543, "end_line": 3549, "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": 3553, "end_line": 3562, "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": 29, "complexity": 4, "token_count": 229, "parameters": [ "start", "stop", "step", "type_num" ], "start_line": 3566, "end_line": 3599, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "top_nesting_level": 0 }, { "name": "array_arange", "long_name": "array_arange( PyObject * ignored , PyObject * args , PyObject * kws)", "filename": "multiarraymodule.c", "nloc": 42, "complexity": 10, "token_count": 258, "parameters": [ "ignored", "args", "kws" ], "start_line": 3605, "end_line": 3653, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "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": 11, "complexity": 2, "token_count": 78, "parameters": [ "dummy", "args", "kwds" ], "start_line": 3673, "end_line": 3684, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "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": 3, "token_count": 67, "parameters": [ "self", "args", "kwds" ], "start_line": 3690, "end_line": 3707, "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": 29, "complexity": 8, "token_count": 226, "parameters": [ "condition", "x", "y" ], "start_line": 3711, "end_line": 3747, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "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": 3755, "end_line": 3763, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "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": 3769, "end_line": 3780, "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": 23, "complexity": 5, "token_count": 145, "parameters": [ "dummy", "args", "kwds" ], "start_line": 3787, "end_line": 3811, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "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": 3871, "end_line": 3980, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 110, "top_nesting_level": 0 }, { "name": "set_flaginfo", "long_name": "set_flaginfo( PyObject * d)", "filename": "multiarraymodule.c", "nloc": 23, "complexity": 1, "token_count": 171, "parameters": [ "d" ], "start_line": 3985, "end_line": 4011, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 0 }, { "name": "initmultiarray", "long_name": "initmultiarray()", "filename": "multiarraymodule.c", "nloc": 50, "complexity": 12, "token_count": 341, "parameters": [], "start_line": 4016, "end_line": 4094, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 79, "top_nesting_level": 0 } ], "methods_before": [ { "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": 51, "end_line": 56, "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": 59, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "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": 68, "end_line": 80, "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": 83, "end_line": 90, "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_Typecode * type)", "filename": "multiarraymodule.c", "nloc": 42, "complexity": 9, "token_count": 245, "parameters": [ "self", "type" ], "start_line": 93, "end_line": 141, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "PyArray_Ravel", "long_name": "PyArray_Ravel( PyArrayObject * a , int fortran)", "filename": "multiarraymodule.c", "nloc": 14, "complexity": 4, "token_count": 87, "parameters": [ "a", "fortran" ], "start_line": 144, "end_line": 158, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "PyArray_Flatten", "long_name": "PyArray_Flatten( PyArrayObject * a , int fortran)", "filename": "multiarraymodule.c", "nloc": 32, "complexity": 5, "token_count": 162, "parameters": [ "a", "fortran" ], "start_line": 161, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "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": 202, "end_line": 211, "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": 214, "end_line": 240, "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": 75, "complexity": 17, "token_count": 411, "parameters": [ "self", "newdims" ], "start_line": 248, "end_line": 339, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 92, "top_nesting_level": 0 }, { "name": "PyArray_Squeeze", "long_name": "PyArray_Squeeze( PyArrayObject * self)", "filename": "multiarraymodule.c", "nloc": 30, "complexity": 4, "token_count": 192, "parameters": [ "self" ], "start_line": 347, "end_line": 378, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "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": 382, "end_line": 403, "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)", "filename": "multiarraymodule.c", "nloc": 43, "complexity": 12, "token_count": 433, "parameters": [ "self", "axis", "rtype" ], "start_line": 406, "end_line": 461, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 56, "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": 465, "end_line": 475, "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": 478, "end_line": 488, "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": 491, "end_line": 501, "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": 504, "end_line": 515, "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": 518, "end_line": 529, "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": 532, "end_line": 543, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_Compress", "long_name": "PyArray_Compress( PyArrayObject * self , PyObject * condition , int axis)", "filename": "multiarraymodule.c", "nloc": 18, "complexity": 3, "token_count": 110, "parameters": [ "self", "condition", "axis" ], "start_line": 547, "end_line": 567, "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": 50, "complexity": 13, "token_count": 403, "parameters": [ "self" ], "start_line": 570, "end_line": 628, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 59, "top_nesting_level": 0 }, { "name": "PyArray_Clip", "long_name": "PyArray_Clip( PyArrayObject * self , PyObject * min , PyObject * max)", "filename": "multiarraymodule.c", "nloc": 30, "complexity": 6, "token_count": 241, "parameters": [ "self", "min", "max" ], "start_line": 631, "end_line": 664, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "top_nesting_level": 0 }, { "name": "PyArray_Conjugate", "long_name": "PyArray_Conjugate( PyArrayObject * self)", "filename": "multiarraymodule.c", "nloc": 36, "complexity": 9, "token_count": 225, "parameters": [ "self" ], "start_line": 667, "end_line": 703, "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": 706, "end_line": 716, "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": 106, "complexity": 24, "token_count": 808, "parameters": [ "self", "offset", "axis1", "axis2" ], "start_line": 719, "end_line": 840, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 122, "top_nesting_level": 0 }, { "name": "PyArray_AsCArray", "long_name": "PyArray_AsCArray( PyObject ** op , * ptr , intp * dims , int nd , int type_num)", "filename": "multiarraymodule.c", "nloc": 55, "complexity": 13, "token_count": 432, "parameters": [ "op", "ptr", "dims", "nd", "type_num" ], "start_line": 857, "end_line": 913, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 57, "top_nesting_level": 0 }, { "name": "PyArray_As1D", "long_name": "PyArray_As1D( PyObject ** op , char ** ptr , int * d1 , int typecode)", "filename": "multiarraymodule.c", "nloc": 8, "complexity": 2, "token_count": 60, "parameters": [ "op", "ptr", "d1", "typecode" ], "start_line": 918, "end_line": 926, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "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": 9, "complexity": 2, "token_count": 81, "parameters": [ "op", "ptr", "d1", "d2", "typecode" ], "start_line": 930, "end_line": 940, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "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": 945, "end_line": 956, "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": 960, "end_line": 988, "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": 114, "complexity": 24, "token_count": 771, "parameters": [ "op", "axis" ], "start_line": 997, "end_line": 1125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 129, "top_nesting_level": 0 }, { "name": "PyArray_SwapAxes", "long_name": "PyArray_SwapAxes( PyArrayObject * ap , int a1 , int a2)", "filename": "multiarraymodule.c", "nloc": 37, "complexity": 12, "token_count": 227, "parameters": [ "ap", "a1", "a2" ], "start_line": 1128, "end_line": 1167, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 }, { "name": "PyArray_Transpose", "long_name": "PyArray_Transpose( PyArrayObject * ap , PyObject * op)", "filename": "multiarraymodule.c", "nloc": 49, "complexity": 15, "token_count": 403, "parameters": [ "ap", "op" ], "start_line": 1171, "end_line": 1230, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 60, "top_nesting_level": 0 }, { "name": "PyArray_Repeat", "long_name": "PyArray_Repeat( PyArrayObject * aop , PyObject * op , int axis)", "filename": "multiarraymodule.c", "nloc": 75, "complexity": 15, "token_count": 520, "parameters": [ "aop", "op", "axis" ], "start_line": 1233, "end_line": 1325, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 93, "top_nesting_level": 0 }, { "name": "PyArray_Choose", "long_name": "PyArray_Choose( PyArrayObject * ip , PyObject * op)", "filename": "multiarraymodule.c", "nloc": 89, "complexity": 18, "token_count": 650, "parameters": [ "ip", "op" ], "start_line": 1329, "end_line": 1441, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 113, "top_nesting_level": 0 }, { "name": "qsortCompare", "long_name": "qsortCompare( const * a , const * b)", "filename": "multiarraymodule.c", "nloc": 4, "complexity": 1, "token_count": 28, "parameters": [ "a", "b" ], "start_line": 1449, "end_line": 1452, "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)", "filename": "multiarraymodule.c", "nloc": 36, "complexity": 7, "token_count": 250, "parameters": [ "op", "axis" ], "start_line": 1474, "end_line": 1523, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "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": 63, "parameters": [ "ip1", "ip2" ], "start_line": 1529, "end_line": 1537, "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)", "filename": "multiarraymodule.c", "nloc": 48, "complexity": 8, "token_count": 350, "parameters": [ "op", "axis" ], "start_line": 1540, "end_line": 1599, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 60, "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": 1602, "end_line": 1637, "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": 223, "parameters": [ "op1", "op2" ], "start_line": 1640, "end_line": 1685, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 46, "top_nesting_level": 0 }, { "name": "PyArray_InnerProduct", "long_name": "PyArray_InnerProduct( PyObject * op1 , PyObject * op2)", "filename": "multiarraymodule.c", "nloc": 83, "complexity": 17, "token_count": 657, "parameters": [ "op1", "op2" ], "start_line": 1693, "end_line": 1796, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 104, "top_nesting_level": 0 }, { "name": "PyArray_MatrixProduct", "long_name": "PyArray_MatrixProduct( PyObject * op1 , PyObject * op2)", "filename": "multiarraymodule.c", "nloc": 101, "complexity": 20, "token_count": 783, "parameters": [ "op1", "op2" ], "start_line": 1801, "end_line": 1925, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 125, "top_nesting_level": 0 }, { "name": "PyArray_CopyAndTranspose", "long_name": "PyArray_CopyAndTranspose( PyObject * op)", "filename": "multiarraymodule.c", "nloc": 44, "complexity": 6, "token_count": 278, "parameters": [ "op" ], "start_line": 1928, "end_line": 1979, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 0 }, { "name": "PyArray_Correlate", "long_name": "PyArray_Correlate( PyObject * op1 , PyObject * op2 , int mode)", "filename": "multiarraymodule.c", "nloc": 89, "complexity": 13, "token_count": 625, "parameters": [ "op1", "op2", "mode" ], "start_line": 1982, "end_line": 2080, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 99, "top_nesting_level": 0 }, { "name": "PyArray_ArgMin", "long_name": "PyArray_ArgMin( PyArrayObject * ap , int axis)", "filename": "multiarraymodule.c", "nloc": 21, "complexity": 5, "token_count": 138, "parameters": [ "ap", "axis" ], "start_line": 2083, "end_line": 2108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "PyArray_Max", "long_name": "PyArray_Max( PyArrayObject * ap , int axis)", "filename": "multiarraymodule.c", "nloc": 11, "complexity": 2, "token_count": 67, "parameters": [ "ap", "axis" ], "start_line": 2111, "end_line": 2122, "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": 67, "parameters": [ "ap", "axis" ], "start_line": 2125, "end_line": 2136, "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": 2139, "end_line": 2162, "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": 322, "parameters": [ "op", "axis" ], "start_line": 2166, "end_line": 2223, "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": 62, "complexity": 12, "token_count": 468, "parameters": [ "self0", "indices0", "axis" ], "start_line": 2227, "end_line": 2299, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 73, "top_nesting_level": 0 }, { "name": "PyArray_Put", "long_name": "PyArray_Put( PyArrayObject * self , PyObject * indices0 , PyObject * values0)", "filename": "multiarraymodule.c", "nloc": 47, "complexity": 10, "token_count": 319, "parameters": [ "self", "indices0", "values0" ], "start_line": 2302, "end_line": 2354, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "top_nesting_level": 0 }, { "name": "PyArray_PutMask", "long_name": "PyArray_PutMask( PyArrayObject * self , PyObject * mask0 , PyObject * values0)", "filename": "multiarraymodule.c", "nloc": 56, "complexity": 10, "token_count": 334, "parameters": [ "self", "mask0", "values0" ], "start_line": 2357, "end_line": 2419, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 63, "top_nesting_level": 0 }, { "name": "PyArray_Converter", "long_name": "PyArray_Converter( PyObject * object , PyObject ** address)", "filename": "multiarraymodule.c", "nloc": 13, "complexity": 3, "token_count": 66, "parameters": [ "object", "address" ], "start_line": 2431, "end_line": 2443, "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": 2446, "end_line": 2454, "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": 90, "complexity": 33, "token_count": 284, "parameters": [ "itemsize", "gentype" ], "start_line": 2458, "end_line": 2567, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 110, "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": 2582, "end_line": 2607, "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": 35, "complexity": 10, "token_count": 186, "parameters": [ "obj", "seq" ], "start_line": 2619, "end_line": 2655, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "PyArray_TypecodeConverter", "long_name": "PyArray_TypecodeConverter( PyObject * obj , PyArray_Typecode * at)", "filename": "multiarraymodule.c", "nloc": 106, "complexity": 34, "token_count": 629, "parameters": [ "obj", "at" ], "start_line": 2664, "end_line": 2805, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 142, "top_nesting_level": 0 }, { "name": "PyArray_EquivalentTypes", "long_name": "PyArray_EquivalentTypes( PyArray_Typecode * typ1 , PyArray_Typecode * typ2)", "filename": "multiarraymodule.c", "nloc": 24, "complexity": 8, "token_count": 162, "parameters": [ "typ1", "typ2" ], "start_line": 2813, "end_line": 2840, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "PyArray_EquivArrTypes", "long_name": "PyArray_EquivArrTypes( PyArrayObject * a1 , PyArrayObject * a2)", "filename": "multiarraymodule.c", "nloc": 10, "complexity": 1, "token_count": 80, "parameters": [ "a1", "a2" ], "start_line": 2843, "end_line": 2854, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "_array_fromobject", "long_name": "_array_fromobject( PyObject * ignored , PyObject * args , PyObject * kws)", "filename": "multiarraymodule.c", "nloc": 45, "complexity": 11, "token_count": 282, "parameters": [ "ignored", "args", "kws" ], "start_line": 2876, "end_line": 2927, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 0 }, { "name": "PyArray_Empty", "long_name": "PyArray_Empty( int nd , intp * dims , PyArray_Typecode * type)", "filename": "multiarraymodule.c", "nloc": 15, "complexity": 3, "token_count": 99, "parameters": [ "nd", "dims", "type" ], "start_line": 2930, "end_line": 2946, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "array_empty", "long_name": "array_empty( PyObject * ignored , PyObject * args , PyObject * kwds)", "filename": "multiarraymodule.c", "nloc": 21, "complexity": 3, "token_count": 134, "parameters": [ "ignored", "args", "kwds" ], "start_line": 2952, "end_line": 2976, "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": 56, "complexity": 11, "token_count": 290, "parameters": [ "ignored", "args", "kwds" ], "start_line": 2981, "end_line": 3045, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 65, "top_nesting_level": 0 }, { "name": "PyArray_Zeros", "long_name": "PyArray_Zeros( int nd , intp * dims , PyArray_Typecode * type)", "filename": "multiarraymodule.c", "nloc": 20, "complexity": 3, "token_count": 133, "parameters": [ "nd", "dims", "type" ], "start_line": 3049, "end_line": 3071, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "array_zeros", "long_name": "array_zeros( PyObject * ignored , PyObject * args , PyObject * kwds)", "filename": "multiarraymodule.c", "nloc": 22, "complexity": 3, "token_count": 134, "parameters": [ "ignored", "args", "kwds" ], "start_line": 3077, "end_line": 3101, "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": 3108, "end_line": 3117, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "array_fromString", "long_name": "array_fromString( PyObject * ignored , PyObject * args , PyObject * keywds)", "filename": "multiarraymodule.c", "nloc": 50, "complexity": 8, "token_count": 283, "parameters": [ "ignored", "args", "keywds" ], "start_line": 3122, "end_line": 3177, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 56, "top_nesting_level": 0 }, { "name": "_fill_in_itemsize", "long_name": "_fill_in_itemsize( PyArray_Typecode * typecode)", "filename": "multiarraymodule.c", "nloc": 8, "complexity": 2, "token_count": 42, "parameters": [ "typecode" ], "start_line": 3192, "end_line": 3199, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_FromFile", "long_name": "PyArray_FromFile( FILE * fp , PyArray_Typecode * typecode , intp num , char * sep)", "filename": "multiarraymodule.c", "nloc": 113, "complexity": 23, "token_count": 682, "parameters": [ "fp", "typecode", "num", "sep" ], "start_line": 3203, "end_line": 3330, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 128, "top_nesting_level": 0 }, { "name": "array_fromfile", "long_name": "array_fromfile( PyObject * ignored , PyObject * args , PyObject * keywds)", "filename": "multiarraymodule.c", "nloc": 34, "complexity": 6, "token_count": 221, "parameters": [ "ignored", "args", "keywds" ], "start_line": 3348, "end_line": 3383, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "PyArray_FromBuffer", "long_name": "PyArray_FromBuffer( PyObject * buf , PyArray_Typecode * type , intp count , int swapped)", "filename": "multiarraymodule.c", "nloc": 58, "complexity": 11, "token_count": 306, "parameters": [ "buf", "type", "count", "swapped" ], "start_line": 3386, "end_line": 3449, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 64, "top_nesting_level": 0 }, { "name": "array_frombuffer", "long_name": "array_frombuffer( PyObject * ignored , PyObject * args , PyObject * keywds)", "filename": "multiarraymodule.c", "nloc": 16, "complexity": 2, "token_count": 115, "parameters": [ "ignored", "args", "keywds" ], "start_line": 3463, "end_line": 3480, "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": 3487, "end_line": 3498, "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": 3505, "end_line": 3511, "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": 3518, "end_line": 3524, "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": 3528, "end_line": 3534, "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": 3538, "end_line": 3547, "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": 29, "complexity": 4, "token_count": 229, "parameters": [ "start", "stop", "step", "type_num" ], "start_line": 3551, "end_line": 3584, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "top_nesting_level": 0 }, { "name": "array_arange", "long_name": "array_arange( PyObject * ignored , PyObject * args , PyObject * kws)", "filename": "multiarraymodule.c", "nloc": 42, "complexity": 10, "token_count": 258, "parameters": [ "ignored", "args", "kws" ], "start_line": 3590, "end_line": 3638, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "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": 11, "complexity": 2, "token_count": 78, "parameters": [ "dummy", "args", "kwds" ], "start_line": 3658, "end_line": 3669, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "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": 3, "token_count": 67, "parameters": [ "self", "args", "kwds" ], "start_line": 3675, "end_line": 3692, "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": 29, "complexity": 8, "token_count": 226, "parameters": [ "condition", "x", "y" ], "start_line": 3696, "end_line": 3732, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "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": 3740, "end_line": 3748, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "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": 3754, "end_line": 3765, "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": 23, "complexity": 5, "token_count": 145, "parameters": [ "dummy", "args", "kwds" ], "start_line": 3772, "end_line": 3796, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "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": 3856, "end_line": 3965, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 110, "top_nesting_level": 0 }, { "name": "set_flaginfo", "long_name": "set_flaginfo( PyObject * d)", "filename": "multiarraymodule.c", "nloc": 23, "complexity": 1, "token_count": 171, "parameters": [ "d" ], "start_line": 3970, "end_line": 3996, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 0 }, { "name": "initmultiarray", "long_name": "initmultiarray()", "filename": "multiarraymodule.c", "nloc": 50, "complexity": 12, "token_count": 341, "parameters": [], "start_line": 4001, "end_line": 4079, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 79, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "PyArray_EquivalentTypenums", "long_name": "PyArray_EquivalentTypenums( int typenum1 , int typenum2)", "filename": "multiarraymodule.c", "nloc": 10, "complexity": 1, "token_count": 76, "parameters": [ "typenum1", "typenum2" ], "start_line": 2858, "end_line": 2869, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 } ], "nloc": 3165, "complexity": 653, "token_count": 20654, "diff_parsed": { "added": [ "/* All flexible types of the same typenum seen as equivalent */", "static Bool", "PyArray_EquivalentTypenums(int typenum1, int typenum2)", "{", "\tPyArray_Typecode type1={0,0,0};", "\tPyArray_Typecode type2={0,0,0};", "", "\ttype1.type_num = typenum1;", "\ttype2.type_num = typenum2;", "\ttype1.itemsize = PyArray_DescrFromType(typenum1)->elsize;", "\ttype2.itemsize = PyArray_DescrFromType(typenum2)->elsize;", "", "\treturn PyArray_EquivalentTypes(&type1, &type2);", "}", "" ], "deleted": [] } }, { "old_path": "scipy/weave/c_spec.py", "new_path": "scipy/weave/c_spec.py", "filename": "c_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -299,20 +299,26 @@ def c_to_py_code(self):\n # Numeric array Python numeric --> C type maps\n #----------------------------------------------------------------------------\n num_to_c_types['T'] = 'T' # for templates\n+num_to_c_types['G'] = 'std::complex '\n num_to_c_types['F'] = 'std::complex '\n num_to_c_types['D'] = 'std::complex '\n+num_to_c_types['g'] = 'longdouble'\n num_to_c_types['f'] = 'float'\n num_to_c_types['d'] = 'double'\n-num_to_c_types['1'] = 'char'\n-num_to_c_types['b'] = 'unsigned char'\n-num_to_c_types['s'] = 'short'\n-num_to_c_types['w'] = 'unsigned short'\n+num_to_c_types['b'] = 'char'\n+num_to_c_types['B'] = 'uchar'\n+num_to_c_types['h'] = 'short'\n+num_to_c_types['H'] = 'ushort'\n num_to_c_types['i'] = 'int'\n-num_to_c_types['u'] = 'unsigned int'\n+num_to_c_types['I'] = 'uint'\n \n # not strictly correct, but shoulld be fine fo numeric work.\n # add test somewhere to make sure long can be cast to int before using.\n-num_to_c_types['l'] = 'int'\n+num_to_c_types['l'] = 'long'\n+num_to_c_types['L'] = 'ulong'\n+\n+num_to_c_types['q'] = 'longlong'\n+num_to_c_types['Q'] = 'ulonglong'\n \n class scalar_converter(common_base_converter):\n def init_info(self):\n", "added_lines": 12, "deleted_lines": 6, "source_code": "from types import *\nfrom base_spec import base_converter\nimport base_info\n\n#----------------------------------------------------------------------------\n# C++ code template for converting code from python objects to C++ objects\n#\n# This is silly code. There is absolutely no reason why these simple\n# conversion functions should be classes. However, some versions of \n# Mandrake Linux ship with broken C++ compilers (or libraries) that do not\n# handle exceptions correctly when they are thrown from functions. However,\n# exceptions thrown from class methods always work, so we make everything\n# a class method to solve this error.\n#----------------------------------------------------------------------------\n\n#----------------------------------------------------------------------------\n# speed note\n# the convert_to_int macro below takes about 25 ns per conversion on my\n# 850 MHz PIII. A slightly more sophisticated macro version can trim this\n# to 20 ns, but this savings is dang near useless because the other \n# overhead swamps it...\n#----------------------------------------------------------------------------\npy_to_c_template = \\\n\"\"\"\nclass %(type_name)s_handler\n{\npublic: \n %(return_type)s convert_to_%(type_name)s(PyObject* py_obj, const char* name)\n {\n // Incref occurs even if conversion fails so that\n // the decref in cleanup_code has a matching incref.\n %(inc_ref_count)s\n if (!py_obj || !%(check_func)s(py_obj))\n handle_conversion_error(py_obj,\"%(type_name)s\", name); \n return %(to_c_return)s;\n }\n \n %(return_type)s py_to_%(type_name)s(PyObject* py_obj, const char* name)\n {\n // !! Pretty sure INCREF should only be called on success since\n // !! py_to_xxx is used by the user -- not the code generator.\n if (!py_obj || !%(check_func)s(py_obj))\n handle_bad_type(py_obj,\"%(type_name)s\", name); \n %(inc_ref_count)s\n return %(to_c_return)s;\n }\n};\n\n%(type_name)s_handler x__%(type_name)s_handler = %(type_name)s_handler();\n#define convert_to_%(type_name)s(py_obj,name) \\\\\n x__%(type_name)s_handler.convert_to_%(type_name)s(py_obj,name)\n#define py_to_%(type_name)s(py_obj,name) \\\\\n x__%(type_name)s_handler.py_to_%(type_name)s(py_obj,name)\n\n\"\"\"\n\n#----------------------------------------------------------------------------\n# C++ code template for converting code from C++ objects to Python objects\n#\n#----------------------------------------------------------------------------\n\nsimple_c_to_py_template = \\\n\"\"\"\nPyObject* %(type_name)s_to_py(PyObject* obj)\n{\n return (PyObject*) obj;\n}\n\n\"\"\"\n\nclass common_base_converter(base_converter):\n \n def __init__(self):\n self.init_info()\n self._build_information = [self.generate_build_info()]\n \n def init_info(self):\n self.matching_types = []\n self.headers = []\n self.include_dirs = []\n self.libraries = []\n self.library_dirs = []\n self.sources = []\n self.support_code = []\n self.module_init_code = []\n self.warnings = []\n self.define_macros = []\n self.extra_compile_args = []\n self.extra_link_args = []\n self.use_ref_count = 1\n self.name = \"no_name\"\n self.c_type = 'PyObject*'\n self.return_type = 'PyObject*'\n self.to_c_return = 'py_obj'\n \n def info_object(self):\n return base_info.custom_info()\n \n def generate_build_info(self):\n info = self.info_object()\n for header in self.headers:\n info.add_header(header)\n for d in self.include_dirs:\n info.add_include_dir(d)\n for lib in self.libraries:\n info.add_library(lib)\n for d in self.library_dirs:\n info.add_library_dir(d)\n for source in self.sources:\n info.add_source(source)\n for code in self.support_code:\n info.add_support_code(code)\n info.add_support_code(self.py_to_c_code())\n info.add_support_code(self.c_to_py_code())\n for init_code in self.module_init_code:\n info.add_module_init_code(init_code)\n for macro in self.define_macros:\n info.add_define_macro(macro)\n for warning in self.warnings:\n info.add_warning(warning)\n for arg in self.extra_compile_args:\n info.add_extra_compile_arg(arg)\n for arg in self.extra_link_args:\n info.add_extra_link_arg(arg)\n return info\n\n def type_match(self,value):\n return type(value) in self.matching_types\n\n def get_var_type(self,value):\n return type(value)\n \n def type_spec(self,name,value):\n # factory\n new_spec = self.__class__()\n new_spec.name = name \n new_spec.var_type = self.get_var_type(value)\n return new_spec\n\n def template_vars(self,inline=0):\n d = {}\n d['type_name'] = self.type_name\n d['check_func'] = self.check_func\n d['c_type'] = self.c_type\n d['return_type'] = self.return_type\n d['to_c_return'] = self.to_c_return\n d['name'] = self.name\n d['py_var'] = self.py_variable()\n d['var_lookup'] = self.retrieve_py_variable(inline)\n code = 'convert_to_%(type_name)s(%(py_var)s,\"%(name)s\")' % d\n d['var_convert'] = code\n if self.use_ref_count:\n d['inc_ref_count'] = \"Py_XINCREF(py_obj);\"\n else:\n d['inc_ref_count'] = \"\"\n return d\n\n def py_to_c_code(self):\n return py_to_c_template % self.template_vars()\n\n def c_to_py_code(self):\n return simple_c_to_py_template % self.template_vars()\n \n def declaration_code(self,templatize = 0,inline=0):\n code = '%(py_var)s = %(var_lookup)s;\\n' \\\n '%(c_type)s %(name)s = %(var_convert)s;\\n' % \\\n self.template_vars(inline=inline)\n return code \n\n def cleanup_code(self):\n if self.use_ref_count:\n code = 'Py_XDECREF(%(py_var)s);\\n' % self.template_vars()\n #code += 'printf(\"cleaning up %(py_var)s\\\\n\");\\n' % self.template_vars()\n else:\n code = \"\" \n return code\n \n def __repr__(self):\n msg = \"(file:: name: %s)\" % self.name\n return msg\n def __cmp__(self,other):\n #only works for equal\n result = -1\n try:\n result = cmp(self.name,other.name) or \\\n cmp(self.__class__, other.__class__)\n except AttributeError:\n pass\n return result \n\n#----------------------------------------------------------------------------\n# Module Converter\n#----------------------------------------------------------------------------\nclass module_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'module'\n self.check_func = 'PyModule_Check' \n # probably should test for callable classes here also.\n self.matching_types = [ModuleType]\n\n#----------------------------------------------------------------------------\n# String Converter\n#----------------------------------------------------------------------------\nclass string_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'string'\n self.check_func = 'PyString_Check' \n self.c_type = 'std::string'\n self.return_type = 'std::string'\n self.to_c_return = \"std::string(PyString_AsString(py_obj))\"\n self.matching_types = [StringType]\n self.headers.append('')\n def c_to_py_code(self):\n # !! Need to dedent returned code.\n code = \"\"\"\n PyObject* string_to_py(std::string s)\n {\n return PyString_FromString(s.c_str());\n }\n \"\"\"\n return code \n\n#----------------------------------------------------------------------------\n# Unicode Converter\n#----------------------------------------------------------------------------\nclass unicode_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'unicode'\n self.check_func = 'PyUnicode_Check'\n # This isn't supported by gcc 2.95.3 -- MSVC works fine with it. \n #self.c_type = 'std::wstring'\n #self.to_c_return = \"std::wstring(PyUnicode_AS_UNICODE(py_obj))\"\n self.c_type = 'Py_UNICODE*'\n self.return_type = self.c_type\n self.to_c_return = \"PyUnicode_AS_UNICODE(py_obj)\"\n self.matching_types = [UnicodeType]\n #self.headers.append('')\n \n def declaration_code(self,templatize = 0,inline=0):\n # since wstring doesn't seem to work everywhere, we need to provide\n # the length variable Nxxx for the unicode string xxx.\n code = '%(py_var)s = %(var_lookup)s;\\n' \\\n '%(c_type)s %(name)s = %(var_convert)s;\\n' \\\n 'int N%(name)s = PyUnicode_GET_SIZE(%(py_var)s);\\n' \\\n % self.template_vars(inline=inline)\n\n\n return code \n#----------------------------------------------------------------------------\n# File Converter\n#----------------------------------------------------------------------------\nclass file_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'file'\n self.check_func = 'PyFile_Check' \n self.c_type = 'FILE*'\n self.return_type = self.c_type\n self.to_c_return = \"PyFile_AsFile(py_obj)\"\n self.headers = ['']\n self.matching_types = [FileType]\n\n def c_to_py_code(self):\n # !! Need to dedent returned code.\n code = \"\"\"\n PyObject* file_to_py(FILE* file, char* name, char* mode)\n {\n PyObject* py_obj = NULL;\n //extern int fclose(FILE *);\n return (PyObject*) PyFile_FromFile(file, name, mode, fclose);\n }\n \"\"\"\n return code \n\n#----------------------------------------------------------------------------\n#\n# Scalar Number Conversions\n#\n#----------------------------------------------------------------------------\n\n# the following typemaps are for 32 bit platforms. A way to do this\n# general case? maybe ask numeric types how long they are and base\n# the decisions on that.\n\n#----------------------------------------------------------------------------\n# Standard Python numeric --> C type maps\n#----------------------------------------------------------------------------\nnum_to_c_types = {}\nnum_to_c_types[type(1)] = 'int'\nnum_to_c_types[type(1.)] = 'double'\nnum_to_c_types[type(1.+1.j)] = 'std::complex '\n# !! hmmm. The following is likely unsafe...\nnum_to_c_types[type(1L)] = 'int'\n\n#----------------------------------------------------------------------------\n# Numeric array Python numeric --> C type maps\n#----------------------------------------------------------------------------\nnum_to_c_types['T'] = 'T' # for templates\nnum_to_c_types['G'] = 'std::complex '\nnum_to_c_types['F'] = 'std::complex '\nnum_to_c_types['D'] = 'std::complex '\nnum_to_c_types['g'] = 'longdouble'\nnum_to_c_types['f'] = 'float'\nnum_to_c_types['d'] = 'double'\nnum_to_c_types['b'] = 'char'\nnum_to_c_types['B'] = 'uchar'\nnum_to_c_types['h'] = 'short'\nnum_to_c_types['H'] = 'ushort'\nnum_to_c_types['i'] = 'int'\nnum_to_c_types['I'] = 'uint'\n\n# not strictly correct, but shoulld be fine fo numeric work.\n# add test somewhere to make sure long can be cast to int before using.\nnum_to_c_types['l'] = 'long'\nnum_to_c_types['L'] = 'ulong'\n\nnum_to_c_types['q'] = 'longlong'\nnum_to_c_types['Q'] = 'ulonglong'\n\nclass scalar_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.warnings = ['disable: 4275', 'disable: 4101']\n self.headers = ['','']\n self.use_ref_count = 0\n\nclass int_converter(scalar_converter):\n def init_info(self):\n scalar_converter.init_info(self)\n self.type_name = 'int'\n self.check_func = 'PyInt_Check' \n self.c_type = 'int'\n self.return_type = 'int'\n self.to_c_return = \"(int) PyInt_AsLong(py_obj)\"\n self.matching_types = [IntType]\n\nclass long_converter(scalar_converter):\n def init_info(self):\n scalar_converter.init_info(self)\n # !! long to int conversion isn't safe!\n self.type_name = 'long'\n self.check_func = 'PyLong_Check' \n self.c_type = 'int'\n self.return_type = 'int'\n self.to_c_return = \"(int) PyLong_AsLong(py_obj)\"\n self.matching_types = [LongType]\n\nclass float_converter(scalar_converter):\n def init_info(self):\n scalar_converter.init_info(self)\n # Not sure this is really that safe...\n self.type_name = 'float'\n self.check_func = 'PyFloat_Check' \n self.c_type = 'double'\n self.return_type = 'double'\n self.to_c_return = \"PyFloat_AsDouble(py_obj)\"\n self.matching_types = [FloatType]\n\nclass complex_converter(scalar_converter):\n def init_info(self):\n scalar_converter.init_info(self)\n self.type_name = 'complex'\n self.check_func = 'PyComplex_Check' \n self.c_type = 'std::complex'\n self.return_type = 'std::complex'\n self.to_c_return = \"std::complex(PyComplex_RealAsDouble(py_obj),\"\\\n \"PyComplex_ImagAsDouble(py_obj))\"\n self.matching_types = [ComplexType]\n\n#----------------------------------------------------------------------------\n#\n# List, Tuple, and Dict converters.\n#\n# Based on SCXX by Gordon McMillan\n#----------------------------------------------------------------------------\nimport os, c_spec # yes, I import myself to find out my __file__ location.\nlocal_dir,junk = os.path.split(os.path.abspath(c_spec.__file__)) \nscxx_dir = os.path.join(local_dir,'scxx')\n\nclass scxx_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.headers = ['\"scxx/object.h\"','\"scxx/list.h\"','\"scxx/tuple.h\"',\n '\"scxx/dict.h\"','']\n self.include_dirs = [local_dir,scxx_dir]\n self.sources = [os.path.join(scxx_dir,'weave_imp.cpp'),]\n\nclass list_converter(scxx_converter):\n def init_info(self):\n scxx_converter.init_info(self)\n self.type_name = 'list'\n self.check_func = 'PyList_Check' \n self.c_type = 'py::list'\n self.return_type = 'py::list'\n self.to_c_return = 'py::list(py_obj)'\n self.matching_types = [ListType]\n # ref counting handled by py::list\n self.use_ref_count = 0\n\nclass tuple_converter(scxx_converter):\n def init_info(self):\n scxx_converter.init_info(self)\n self.type_name = 'tuple'\n self.check_func = 'PyTuple_Check' \n self.c_type = 'py::tuple'\n self.return_type = 'py::tuple'\n self.to_c_return = 'py::tuple(py_obj)'\n self.matching_types = [TupleType]\n # ref counting handled by py::tuple\n self.use_ref_count = 0\n\nclass dict_converter(scxx_converter):\n def init_info(self):\n scxx_converter.init_info(self)\n self.type_name = 'dict'\n self.check_func = 'PyDict_Check' \n self.c_type = 'py::dict'\n self.return_type = 'py::dict'\n self.to_c_return = 'py::dict(py_obj)'\n self.matching_types = [DictType]\n # ref counting handled by py::dict\n self.use_ref_count = 0\n\n#----------------------------------------------------------------------------\n# Instance Converter\n#----------------------------------------------------------------------------\nclass instance_converter(scxx_converter):\n def init_info(self):\n scxx_converter.init_info(self)\n self.type_name = 'instance'\n self.check_func = 'PyInstance_Check' \n self.c_type = 'py::object'\n self.return_type = 'py::object'\n self.to_c_return = 'py::object(py_obj)'\n self.matching_types = [InstanceType]\n # ref counting handled by py::object\n self.use_ref_count = 0\n\n#----------------------------------------------------------------------------\n# Catchall Converter\n#\n# catch all now handles callable objects\n#----------------------------------------------------------------------------\nclass catchall_converter(scxx_converter):\n def init_info(self):\n scxx_converter.init_info(self)\n self.type_name = 'catchall'\n self.check_func = '' \n self.c_type = 'py::object'\n self.return_type = 'py::object'\n self.to_c_return = 'py::object(py_obj)'\n # ref counting handled by py::object\n self.use_ref_count = 0\n def type_match(self,value):\n return 1\n\nif __name__ == \"__main__\":\n x = list_converter().type_spec(\"x\",1)\n print x.py_to_c_code()\n print\n print x.c_to_py_code()\n print\n print x.declaration_code(inline=1)\n print\n print x.cleanup_code()\n", "source_code_before": "from types import *\nfrom base_spec import base_converter\nimport base_info\n\n#----------------------------------------------------------------------------\n# C++ code template for converting code from python objects to C++ objects\n#\n# This is silly code. There is absolutely no reason why these simple\n# conversion functions should be classes. However, some versions of \n# Mandrake Linux ship with broken C++ compilers (or libraries) that do not\n# handle exceptions correctly when they are thrown from functions. However,\n# exceptions thrown from class methods always work, so we make everything\n# a class method to solve this error.\n#----------------------------------------------------------------------------\n\n#----------------------------------------------------------------------------\n# speed note\n# the convert_to_int macro below takes about 25 ns per conversion on my\n# 850 MHz PIII. A slightly more sophisticated macro version can trim this\n# to 20 ns, but this savings is dang near useless because the other \n# overhead swamps it...\n#----------------------------------------------------------------------------\npy_to_c_template = \\\n\"\"\"\nclass %(type_name)s_handler\n{\npublic: \n %(return_type)s convert_to_%(type_name)s(PyObject* py_obj, const char* name)\n {\n // Incref occurs even if conversion fails so that\n // the decref in cleanup_code has a matching incref.\n %(inc_ref_count)s\n if (!py_obj || !%(check_func)s(py_obj))\n handle_conversion_error(py_obj,\"%(type_name)s\", name); \n return %(to_c_return)s;\n }\n \n %(return_type)s py_to_%(type_name)s(PyObject* py_obj, const char* name)\n {\n // !! Pretty sure INCREF should only be called on success since\n // !! py_to_xxx is used by the user -- not the code generator.\n if (!py_obj || !%(check_func)s(py_obj))\n handle_bad_type(py_obj,\"%(type_name)s\", name); \n %(inc_ref_count)s\n return %(to_c_return)s;\n }\n};\n\n%(type_name)s_handler x__%(type_name)s_handler = %(type_name)s_handler();\n#define convert_to_%(type_name)s(py_obj,name) \\\\\n x__%(type_name)s_handler.convert_to_%(type_name)s(py_obj,name)\n#define py_to_%(type_name)s(py_obj,name) \\\\\n x__%(type_name)s_handler.py_to_%(type_name)s(py_obj,name)\n\n\"\"\"\n\n#----------------------------------------------------------------------------\n# C++ code template for converting code from C++ objects to Python objects\n#\n#----------------------------------------------------------------------------\n\nsimple_c_to_py_template = \\\n\"\"\"\nPyObject* %(type_name)s_to_py(PyObject* obj)\n{\n return (PyObject*) obj;\n}\n\n\"\"\"\n\nclass common_base_converter(base_converter):\n \n def __init__(self):\n self.init_info()\n self._build_information = [self.generate_build_info()]\n \n def init_info(self):\n self.matching_types = []\n self.headers = []\n self.include_dirs = []\n self.libraries = []\n self.library_dirs = []\n self.sources = []\n self.support_code = []\n self.module_init_code = []\n self.warnings = []\n self.define_macros = []\n self.extra_compile_args = []\n self.extra_link_args = []\n self.use_ref_count = 1\n self.name = \"no_name\"\n self.c_type = 'PyObject*'\n self.return_type = 'PyObject*'\n self.to_c_return = 'py_obj'\n \n def info_object(self):\n return base_info.custom_info()\n \n def generate_build_info(self):\n info = self.info_object()\n for header in self.headers:\n info.add_header(header)\n for d in self.include_dirs:\n info.add_include_dir(d)\n for lib in self.libraries:\n info.add_library(lib)\n for d in self.library_dirs:\n info.add_library_dir(d)\n for source in self.sources:\n info.add_source(source)\n for code in self.support_code:\n info.add_support_code(code)\n info.add_support_code(self.py_to_c_code())\n info.add_support_code(self.c_to_py_code())\n for init_code in self.module_init_code:\n info.add_module_init_code(init_code)\n for macro in self.define_macros:\n info.add_define_macro(macro)\n for warning in self.warnings:\n info.add_warning(warning)\n for arg in self.extra_compile_args:\n info.add_extra_compile_arg(arg)\n for arg in self.extra_link_args:\n info.add_extra_link_arg(arg)\n return info\n\n def type_match(self,value):\n return type(value) in self.matching_types\n\n def get_var_type(self,value):\n return type(value)\n \n def type_spec(self,name,value):\n # factory\n new_spec = self.__class__()\n new_spec.name = name \n new_spec.var_type = self.get_var_type(value)\n return new_spec\n\n def template_vars(self,inline=0):\n d = {}\n d['type_name'] = self.type_name\n d['check_func'] = self.check_func\n d['c_type'] = self.c_type\n d['return_type'] = self.return_type\n d['to_c_return'] = self.to_c_return\n d['name'] = self.name\n d['py_var'] = self.py_variable()\n d['var_lookup'] = self.retrieve_py_variable(inline)\n code = 'convert_to_%(type_name)s(%(py_var)s,\"%(name)s\")' % d\n d['var_convert'] = code\n if self.use_ref_count:\n d['inc_ref_count'] = \"Py_XINCREF(py_obj);\"\n else:\n d['inc_ref_count'] = \"\"\n return d\n\n def py_to_c_code(self):\n return py_to_c_template % self.template_vars()\n\n def c_to_py_code(self):\n return simple_c_to_py_template % self.template_vars()\n \n def declaration_code(self,templatize = 0,inline=0):\n code = '%(py_var)s = %(var_lookup)s;\\n' \\\n '%(c_type)s %(name)s = %(var_convert)s;\\n' % \\\n self.template_vars(inline=inline)\n return code \n\n def cleanup_code(self):\n if self.use_ref_count:\n code = 'Py_XDECREF(%(py_var)s);\\n' % self.template_vars()\n #code += 'printf(\"cleaning up %(py_var)s\\\\n\");\\n' % self.template_vars()\n else:\n code = \"\" \n return code\n \n def __repr__(self):\n msg = \"(file:: name: %s)\" % self.name\n return msg\n def __cmp__(self,other):\n #only works for equal\n result = -1\n try:\n result = cmp(self.name,other.name) or \\\n cmp(self.__class__, other.__class__)\n except AttributeError:\n pass\n return result \n\n#----------------------------------------------------------------------------\n# Module Converter\n#----------------------------------------------------------------------------\nclass module_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'module'\n self.check_func = 'PyModule_Check' \n # probably should test for callable classes here also.\n self.matching_types = [ModuleType]\n\n#----------------------------------------------------------------------------\n# String Converter\n#----------------------------------------------------------------------------\nclass string_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'string'\n self.check_func = 'PyString_Check' \n self.c_type = 'std::string'\n self.return_type = 'std::string'\n self.to_c_return = \"std::string(PyString_AsString(py_obj))\"\n self.matching_types = [StringType]\n self.headers.append('')\n def c_to_py_code(self):\n # !! Need to dedent returned code.\n code = \"\"\"\n PyObject* string_to_py(std::string s)\n {\n return PyString_FromString(s.c_str());\n }\n \"\"\"\n return code \n\n#----------------------------------------------------------------------------\n# Unicode Converter\n#----------------------------------------------------------------------------\nclass unicode_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'unicode'\n self.check_func = 'PyUnicode_Check'\n # This isn't supported by gcc 2.95.3 -- MSVC works fine with it. \n #self.c_type = 'std::wstring'\n #self.to_c_return = \"std::wstring(PyUnicode_AS_UNICODE(py_obj))\"\n self.c_type = 'Py_UNICODE*'\n self.return_type = self.c_type\n self.to_c_return = \"PyUnicode_AS_UNICODE(py_obj)\"\n self.matching_types = [UnicodeType]\n #self.headers.append('')\n \n def declaration_code(self,templatize = 0,inline=0):\n # since wstring doesn't seem to work everywhere, we need to provide\n # the length variable Nxxx for the unicode string xxx.\n code = '%(py_var)s = %(var_lookup)s;\\n' \\\n '%(c_type)s %(name)s = %(var_convert)s;\\n' \\\n 'int N%(name)s = PyUnicode_GET_SIZE(%(py_var)s);\\n' \\\n % self.template_vars(inline=inline)\n\n\n return code \n#----------------------------------------------------------------------------\n# File Converter\n#----------------------------------------------------------------------------\nclass file_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'file'\n self.check_func = 'PyFile_Check' \n self.c_type = 'FILE*'\n self.return_type = self.c_type\n self.to_c_return = \"PyFile_AsFile(py_obj)\"\n self.headers = ['']\n self.matching_types = [FileType]\n\n def c_to_py_code(self):\n # !! Need to dedent returned code.\n code = \"\"\"\n PyObject* file_to_py(FILE* file, char* name, char* mode)\n {\n PyObject* py_obj = NULL;\n //extern int fclose(FILE *);\n return (PyObject*) PyFile_FromFile(file, name, mode, fclose);\n }\n \"\"\"\n return code \n\n#----------------------------------------------------------------------------\n#\n# Scalar Number Conversions\n#\n#----------------------------------------------------------------------------\n\n# the following typemaps are for 32 bit platforms. A way to do this\n# general case? maybe ask numeric types how long they are and base\n# the decisions on that.\n\n#----------------------------------------------------------------------------\n# Standard Python numeric --> C type maps\n#----------------------------------------------------------------------------\nnum_to_c_types = {}\nnum_to_c_types[type(1)] = 'int'\nnum_to_c_types[type(1.)] = 'double'\nnum_to_c_types[type(1.+1.j)] = 'std::complex '\n# !! hmmm. The following is likely unsafe...\nnum_to_c_types[type(1L)] = 'int'\n\n#----------------------------------------------------------------------------\n# Numeric array Python numeric --> C type maps\n#----------------------------------------------------------------------------\nnum_to_c_types['T'] = 'T' # for templates\nnum_to_c_types['F'] = 'std::complex '\nnum_to_c_types['D'] = 'std::complex '\nnum_to_c_types['f'] = 'float'\nnum_to_c_types['d'] = 'double'\nnum_to_c_types['1'] = 'char'\nnum_to_c_types['b'] = 'unsigned char'\nnum_to_c_types['s'] = 'short'\nnum_to_c_types['w'] = 'unsigned short'\nnum_to_c_types['i'] = 'int'\nnum_to_c_types['u'] = 'unsigned int'\n\n# not strictly correct, but shoulld be fine fo numeric work.\n# add test somewhere to make sure long can be cast to int before using.\nnum_to_c_types['l'] = 'int'\n\nclass scalar_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.warnings = ['disable: 4275', 'disable: 4101']\n self.headers = ['','']\n self.use_ref_count = 0\n\nclass int_converter(scalar_converter):\n def init_info(self):\n scalar_converter.init_info(self)\n self.type_name = 'int'\n self.check_func = 'PyInt_Check' \n self.c_type = 'int'\n self.return_type = 'int'\n self.to_c_return = \"(int) PyInt_AsLong(py_obj)\"\n self.matching_types = [IntType]\n\nclass long_converter(scalar_converter):\n def init_info(self):\n scalar_converter.init_info(self)\n # !! long to int conversion isn't safe!\n self.type_name = 'long'\n self.check_func = 'PyLong_Check' \n self.c_type = 'int'\n self.return_type = 'int'\n self.to_c_return = \"(int) PyLong_AsLong(py_obj)\"\n self.matching_types = [LongType]\n\nclass float_converter(scalar_converter):\n def init_info(self):\n scalar_converter.init_info(self)\n # Not sure this is really that safe...\n self.type_name = 'float'\n self.check_func = 'PyFloat_Check' \n self.c_type = 'double'\n self.return_type = 'double'\n self.to_c_return = \"PyFloat_AsDouble(py_obj)\"\n self.matching_types = [FloatType]\n\nclass complex_converter(scalar_converter):\n def init_info(self):\n scalar_converter.init_info(self)\n self.type_name = 'complex'\n self.check_func = 'PyComplex_Check' \n self.c_type = 'std::complex'\n self.return_type = 'std::complex'\n self.to_c_return = \"std::complex(PyComplex_RealAsDouble(py_obj),\"\\\n \"PyComplex_ImagAsDouble(py_obj))\"\n self.matching_types = [ComplexType]\n\n#----------------------------------------------------------------------------\n#\n# List, Tuple, and Dict converters.\n#\n# Based on SCXX by Gordon McMillan\n#----------------------------------------------------------------------------\nimport os, c_spec # yes, I import myself to find out my __file__ location.\nlocal_dir,junk = os.path.split(os.path.abspath(c_spec.__file__)) \nscxx_dir = os.path.join(local_dir,'scxx')\n\nclass scxx_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.headers = ['\"scxx/object.h\"','\"scxx/list.h\"','\"scxx/tuple.h\"',\n '\"scxx/dict.h\"','']\n self.include_dirs = [local_dir,scxx_dir]\n self.sources = [os.path.join(scxx_dir,'weave_imp.cpp'),]\n\nclass list_converter(scxx_converter):\n def init_info(self):\n scxx_converter.init_info(self)\n self.type_name = 'list'\n self.check_func = 'PyList_Check' \n self.c_type = 'py::list'\n self.return_type = 'py::list'\n self.to_c_return = 'py::list(py_obj)'\n self.matching_types = [ListType]\n # ref counting handled by py::list\n self.use_ref_count = 0\n\nclass tuple_converter(scxx_converter):\n def init_info(self):\n scxx_converter.init_info(self)\n self.type_name = 'tuple'\n self.check_func = 'PyTuple_Check' \n self.c_type = 'py::tuple'\n self.return_type = 'py::tuple'\n self.to_c_return = 'py::tuple(py_obj)'\n self.matching_types = [TupleType]\n # ref counting handled by py::tuple\n self.use_ref_count = 0\n\nclass dict_converter(scxx_converter):\n def init_info(self):\n scxx_converter.init_info(self)\n self.type_name = 'dict'\n self.check_func = 'PyDict_Check' \n self.c_type = 'py::dict'\n self.return_type = 'py::dict'\n self.to_c_return = 'py::dict(py_obj)'\n self.matching_types = [DictType]\n # ref counting handled by py::dict\n self.use_ref_count = 0\n\n#----------------------------------------------------------------------------\n# Instance Converter\n#----------------------------------------------------------------------------\nclass instance_converter(scxx_converter):\n def init_info(self):\n scxx_converter.init_info(self)\n self.type_name = 'instance'\n self.check_func = 'PyInstance_Check' \n self.c_type = 'py::object'\n self.return_type = 'py::object'\n self.to_c_return = 'py::object(py_obj)'\n self.matching_types = [InstanceType]\n # ref counting handled by py::object\n self.use_ref_count = 0\n\n#----------------------------------------------------------------------------\n# Catchall Converter\n#\n# catch all now handles callable objects\n#----------------------------------------------------------------------------\nclass catchall_converter(scxx_converter):\n def init_info(self):\n scxx_converter.init_info(self)\n self.type_name = 'catchall'\n self.check_func = '' \n self.c_type = 'py::object'\n self.return_type = 'py::object'\n self.to_c_return = 'py::object(py_obj)'\n # ref counting handled by py::object\n self.use_ref_count = 0\n def type_match(self,value):\n return 1\n\nif __name__ == \"__main__\":\n x = list_converter().type_spec(\"x\",1)\n print x.py_to_c_code()\n print\n print x.c_to_py_code()\n print\n print x.declaration_code(inline=1)\n print\n print x.cleanup_code()\n", "methods": [ { "name": "__init__", "long_name": "__init__( self )", "filename": "c_spec.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 73, "end_line": 75, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 18, "complexity": 1, "token_count": 102, "parameters": [ "self" ], "start_line": 77, "end_line": 94, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 }, { "name": "info_object", "long_name": "info_object( self )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 96, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "generate_build_info", "long_name": "generate_build_info( self )", "filename": "c_spec.py", "nloc": 27, "complexity": 12, "token_count": 177, "parameters": [ "self" ], "start_line": 99, "end_line": 125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 127, "end_line": 128, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_var_type", "long_name": "get_var_type( self , value )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self", "value" ], "start_line": 130, "end_line": 131, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "c_spec.py", "nloc": 5, "complexity": 1, "token_count": 33, "parameters": [ "self", "name", "value" ], "start_line": 133, "end_line": 138, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "template_vars", "long_name": "template_vars( self , inline = 0 )", "filename": "c_spec.py", "nloc": 17, "complexity": 2, "token_count": 114, "parameters": [ "self", "inline" ], "start_line": 140, "end_line": 156, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "py_to_c_code", "long_name": "py_to_c_code( self )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 158, "end_line": 159, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "c_to_py_code", "long_name": "c_to_py_code( self )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 161, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , templatize = 0 , inline = 0 )", "filename": "c_spec.py", "nloc": 5, "complexity": 1, "token_count": 30, "parameters": [ "self", "templatize", "inline" ], "start_line": 164, "end_line": 168, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "cleanup_code", "long_name": "cleanup_code( self )", "filename": "c_spec.py", "nloc": 6, "complexity": 2, "token_count": 26, "parameters": [ "self" ], "start_line": 170, "end_line": 176, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "c_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 178, "end_line": 180, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "c_spec.py", "nloc": 8, "complexity": 3, "token_count": 43, "parameters": [ "self", "other" ], "start_line": 181, "end_line": 189, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "self" ], "start_line": 195, "end_line": 200, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 9, "complexity": 1, "token_count": 51, "parameters": [ "self" ], "start_line": 206, "end_line": 214, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "c_to_py_code", "long_name": "c_to_py_code( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 10, "parameters": [ "self" ], "start_line": 215, "end_line": 223, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 45, "parameters": [ "self" ], "start_line": 229, "end_line": 239, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , templatize = 0 , inline = 0 )", "filename": "c_spec.py", "nloc": 6, "complexity": 1, "token_count": 32, "parameters": [ "self", "templatize", "inline" ], "start_line": 242, "end_line": 251, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 9, "complexity": 1, "token_count": 52, "parameters": [ "self" ], "start_line": 256, "end_line": 264, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "c_to_py_code", "long_name": "c_to_py_code( self )", "filename": "c_spec.py", "nloc": 10, "complexity": 1, "token_count": 10, "parameters": [ "self" ], "start_line": 266, "end_line": 276, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 5, "complexity": 1, "token_count": 34, "parameters": [ "self" ], "start_line": 324, "end_line": 328, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 43, "parameters": [ "self" ], "start_line": 331, "end_line": 338, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 43, "parameters": [ "self" ], "start_line": 341, "end_line": 349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 43, "parameters": [ "self" ], "start_line": 352, "end_line": 360, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 9, "complexity": 1, "token_count": 45, "parameters": [ "self" ], "start_line": 363, "end_line": 371, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 6, "complexity": 1, "token_count": 52, "parameters": [ "self" ], "start_line": 384, "end_line": 389, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 9, "complexity": 1, "token_count": 48, "parameters": [ "self" ], "start_line": 392, "end_line": 401, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 9, "complexity": 1, "token_count": 48, "parameters": [ "self" ], "start_line": 404, "end_line": 413, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 9, "complexity": 1, "token_count": 48, "parameters": [ "self" ], "start_line": 416, "end_line": 425, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 9, "complexity": 1, "token_count": 48, "parameters": [ "self" ], "start_line": 431, "end_line": 440, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 41, "parameters": [ "self" ], "start_line": 448, "end_line": 456, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self", "value" ], "start_line": 457, "end_line": 458, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 } ], "methods_before": [ { "name": "__init__", "long_name": "__init__( self )", "filename": "c_spec.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 73, "end_line": 75, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 18, "complexity": 1, "token_count": 102, "parameters": [ "self" ], "start_line": 77, "end_line": 94, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 }, { "name": "info_object", "long_name": "info_object( self )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 96, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "generate_build_info", "long_name": "generate_build_info( self )", "filename": "c_spec.py", "nloc": 27, "complexity": 12, "token_count": 177, "parameters": [ "self" ], "start_line": 99, "end_line": 125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 127, "end_line": 128, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_var_type", "long_name": "get_var_type( self , value )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self", "value" ], "start_line": 130, "end_line": 131, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "c_spec.py", "nloc": 5, "complexity": 1, "token_count": 33, "parameters": [ "self", "name", "value" ], "start_line": 133, "end_line": 138, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "template_vars", "long_name": "template_vars( self , inline = 0 )", "filename": "c_spec.py", "nloc": 17, "complexity": 2, "token_count": 114, "parameters": [ "self", "inline" ], "start_line": 140, "end_line": 156, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "py_to_c_code", "long_name": "py_to_c_code( self )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 158, "end_line": 159, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "c_to_py_code", "long_name": "c_to_py_code( self )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 161, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , templatize = 0 , inline = 0 )", "filename": "c_spec.py", "nloc": 5, "complexity": 1, "token_count": 30, "parameters": [ "self", "templatize", "inline" ], "start_line": 164, "end_line": 168, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "cleanup_code", "long_name": "cleanup_code( self )", "filename": "c_spec.py", "nloc": 6, "complexity": 2, "token_count": 26, "parameters": [ "self" ], "start_line": 170, "end_line": 176, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "c_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 178, "end_line": 180, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "c_spec.py", "nloc": 8, "complexity": 3, "token_count": 43, "parameters": [ "self", "other" ], "start_line": 181, "end_line": 189, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "self" ], "start_line": 195, "end_line": 200, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 9, "complexity": 1, "token_count": 51, "parameters": [ "self" ], "start_line": 206, "end_line": 214, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "c_to_py_code", "long_name": "c_to_py_code( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 10, "parameters": [ "self" ], "start_line": 215, "end_line": 223, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 45, "parameters": [ "self" ], "start_line": 229, "end_line": 239, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , templatize = 0 , inline = 0 )", "filename": "c_spec.py", "nloc": 6, "complexity": 1, "token_count": 32, "parameters": [ "self", "templatize", "inline" ], "start_line": 242, "end_line": 251, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 9, "complexity": 1, "token_count": 52, "parameters": [ "self" ], "start_line": 256, "end_line": 264, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "c_to_py_code", "long_name": "c_to_py_code( self )", "filename": "c_spec.py", "nloc": 10, "complexity": 1, "token_count": 10, "parameters": [ "self" ], "start_line": 266, "end_line": 276, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 5, "complexity": 1, "token_count": 34, "parameters": [ "self" ], "start_line": 318, "end_line": 322, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 43, "parameters": [ "self" ], "start_line": 325, "end_line": 332, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 43, "parameters": [ "self" ], "start_line": 335, "end_line": 343, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 43, "parameters": [ "self" ], "start_line": 346, "end_line": 354, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 9, "complexity": 1, "token_count": 45, "parameters": [ "self" ], "start_line": 357, "end_line": 365, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 6, "complexity": 1, "token_count": 52, "parameters": [ "self" ], "start_line": 378, "end_line": 383, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 9, "complexity": 1, "token_count": 48, "parameters": [ "self" ], "start_line": 386, "end_line": 395, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 9, "complexity": 1, "token_count": 48, "parameters": [ "self" ], "start_line": 398, "end_line": 407, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 9, "complexity": 1, "token_count": 48, "parameters": [ "self" ], "start_line": 410, "end_line": 419, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 9, "complexity": 1, "token_count": 48, "parameters": [ "self" ], "start_line": 425, "end_line": 434, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 41, "parameters": [ "self" ], "start_line": 442, "end_line": 450, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self", "value" ], "start_line": 451, "end_line": 452, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 } ], "changed_methods": [], "nloc": 341, "complexity": 48, "token_count": 1734, "diff_parsed": { "added": [ "num_to_c_types['G'] = 'std::complex '", "num_to_c_types['g'] = 'longdouble'", "num_to_c_types['b'] = 'char'", "num_to_c_types['B'] = 'uchar'", "num_to_c_types['h'] = 'short'", "num_to_c_types['H'] = 'ushort'", "num_to_c_types['I'] = 'uint'", "num_to_c_types['l'] = 'long'", "num_to_c_types['L'] = 'ulong'", "", "num_to_c_types['q'] = 'longlong'", "num_to_c_types['Q'] = 'ulonglong'" ], "deleted": [ "num_to_c_types['1'] = 'char'", "num_to_c_types['b'] = 'unsigned char'", "num_to_c_types['s'] = 'short'", "num_to_c_types['w'] = 'unsigned short'", "num_to_c_types['u'] = 'unsigned int'", "num_to_c_types['l'] = 'int'" ] } }, { "old_path": "scipy/weave/standard_array_spec.py", "new_path": "scipy/weave/standard_array_spec.py", "filename": "standard_array_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -6,17 +6,23 @@\n \n \n num_typecode = {}\n-num_typecode['b'] = 'PyArray_SBYTE'\n+num_typecode['?'] = 'PyArray_BOOL'\n+num_typecode['b'] = 'PyArray_BYTE'\n num_typecode['B'] = 'PyArray_UBYTE'\n num_typecode['h'] = 'PyArray_SHORT'\n num_typecode['H'] = 'PyArray_USHORT'\n-num_typecode['i'] = 'PyArray_INT' # PyArray_INT has troubles ?? What does this note mean ??\n+num_typecode['i'] = 'PyArray_INT' \n num_typecode['I'] = 'PyArray_UINT'\n num_typecode['l'] = 'PyArray_LONG'\n+num_typecode['L'] = 'PyArray_ULONG'\n+num_typecode['q'] = 'PyArray_LONGLONG'\n+num_typecode['Q'] = 'PyArray_ULONGLONG'\n num_typecode['f'] = 'PyArray_FLOAT'\n num_typecode['d'] = 'PyArray_DOUBLE'\n+num_typecode['g'] = 'PyArray_LONGDOUBLE'\n num_typecode['F'] = 'PyArray_CFLOAT'\n num_typecode['D'] = 'PyArray_CDOUBLE'\n+num_typecode['G'] = 'PyArray_CLONGDOUBLE'\n \n type_check_code = \\\n \"\"\"\n@@ -27,24 +33,26 @@ class numpy_type_handler\n const char* name)\n {\n // Make sure input has correct numeric type.\n- // allow character and byte to match\n- // also allow int and long to match\n int arr_type = arr_obj->descr->type_num;\n- if ( arr_type != numeric_type &&\n- !(numeric_type == PyArray_CHAR && arr_type == PyArray_SBYTE) &&\n- !(numeric_type == PyArray_SBYTE && arr_type == PyArray_CHAR) &&\n- !(numeric_type == PyArray_INT && arr_type == PyArray_LONG) &&\n- !(numeric_type == PyArray_LONG && arr_type == PyArray_INT)) \n+ if (PyTypeNum_ISEXTENDED(numeric_type))\n {\n-\n- char* type_names[20] = {\"char\",\"unsigned byte\",\"byte\", \"short\", \"unsigned short\",\n- \"int\", \"unsigned int\", \"long\", \"float\", \"double\", \n- \"complex float\",\"complex double\", \"object\",\"ntype\",\n- \"unkown\"};\n- char msg[500];\n- sprintf(msg,\"Conversion Error: received '%s' typed array instead of '%s' typed array for variable '%s'\",\n- type_names[arr_type],type_names[numeric_type],name);\n- throw_error(PyExc_TypeError,msg); \n+ char msg[80];\n+ sprintf(msg, \"Conversion Error: extended types not supported for variable '%s'\",\n+ name);\n+ throw_error(PyExc_TypeError, msg);\n+ }\n+ if (!PyArray_EquivalentTypenums(arr_type, numeric_type))\n+ {\n+ \n+ char* type_names[23] = {\"bool\", \"byte\", \"ubyte\",\"short\", \"ushort\",\n+ \"int\", \"uint\", \"long\", \"ulong\", \"longlong\", \"ulonglong\",\n+ \"float\", \"double\", \"longdouble\", \"cfloat\", \"cdouble\",\n+ \"clongdouble\", \"object\", \"string\", \"unicode\", \"void\", \"ntype\",\n+ \"unkown\"};\n+ char msg[500];\n+ sprintf(msg,\"Conversion Error: received '%s' typed array instead of '%s' typed array for variable '%s'\",\n+ type_names[arr_type],type_names[numeric_type],name);\n+ throw_error(PyExc_TypeError,msg); \n }\n }\n \n@@ -52,17 +60,20 @@ class numpy_type_handler\n {\n // Make sure input has correct numeric type.\n int arr_type = arr_obj->descr->type_num;\n- if ( arr_type != numeric_type &&\n- !(numeric_type == PyArray_CHAR && arr_type == PyArray_SBYTE) &&\n- !(numeric_type == PyArray_SBYTE && arr_type == PyArray_CHAR) &&\n- !(numeric_type == PyArray_INT && arr_type == PyArray_LONG) &&\n- !(numeric_type == PyArray_LONG && arr_type == PyArray_INT)) \n+ if (PyTypeNum_ISEXTENDED(numeric_type))\n {\n- char* type_names[20] = {\"char\",\"unsigned byte\",\"byte\", \"short\", \n- \"unsigned short\", \"int\", \"unsigned int\",\n- \"long\", \"float\", \"double\", \n- \"complex float\", \"complex double\", \n- \"object\",\"ntype\",\"unkown\"};\n+ char msg[80];\n+ sprintf(msg, \"Conversion Error: extended types not supported for variable '%s'\",\n+ name);\n+ throw_error(PyExc_TypeError, msg);\n+ } \n+ if (!PyArray_EquivalentTypenums(arr_type, numeric_type))\n+ {\n+ char* type_names[23] = {\"bool\", \"byte\", \"ubyte\",\"short\", \"ushort\",\n+ \"int\", \"uint\", \"long\", \"ulong\", \"longlong\", \"ulonglong\",\n+ \"float\", \"double\", \"longdouble\", \"cfloat\", \"cdouble\",\n+ \"clongdouble\", \"object\", \"string\", \"unicode\", \"void\", \"ntype\",\n+ \"unkown\"};\n char msg[500];\n sprintf(msg,\"received '%s' typed array instead of '%s' typed array for variable '%s'\",\n type_names[arr_type],type_names[numeric_type],name);\n", "added_lines": 39, "deleted_lines": 28, "source_code": "from c_spec import common_base_converter\nfrom c_spec import num_to_c_types\nfrom scipy.base import *\nfrom types import *\nimport os\n\n\nnum_typecode = {}\nnum_typecode['?'] = 'PyArray_BOOL'\nnum_typecode['b'] = 'PyArray_BYTE'\nnum_typecode['B'] = 'PyArray_UBYTE'\nnum_typecode['h'] = 'PyArray_SHORT'\nnum_typecode['H'] = 'PyArray_USHORT'\nnum_typecode['i'] = 'PyArray_INT' \nnum_typecode['I'] = 'PyArray_UINT'\nnum_typecode['l'] = 'PyArray_LONG'\nnum_typecode['L'] = 'PyArray_ULONG'\nnum_typecode['q'] = 'PyArray_LONGLONG'\nnum_typecode['Q'] = 'PyArray_ULONGLONG'\nnum_typecode['f'] = 'PyArray_FLOAT'\nnum_typecode['d'] = 'PyArray_DOUBLE'\nnum_typecode['g'] = 'PyArray_LONGDOUBLE'\nnum_typecode['F'] = 'PyArray_CFLOAT'\nnum_typecode['D'] = 'PyArray_CDOUBLE'\nnum_typecode['G'] = 'PyArray_CLONGDOUBLE'\n\ntype_check_code = \\\n\"\"\"\nclass numpy_type_handler\n{\npublic:\n void conversion_numpy_check_type(PyArrayObject* arr_obj, int numeric_type,\n const char* name)\n {\n // Make sure input has correct numeric type.\n int arr_type = arr_obj->descr->type_num;\n if (PyTypeNum_ISEXTENDED(numeric_type))\n {\n char msg[80];\n sprintf(msg, \"Conversion Error: extended types not supported for variable '%s'\",\n name);\n throw_error(PyExc_TypeError, msg);\n }\n if (!PyArray_EquivalentTypenums(arr_type, numeric_type))\n {\n \n char* type_names[23] = {\"bool\", \"byte\", \"ubyte\",\"short\", \"ushort\",\n \"int\", \"uint\", \"long\", \"ulong\", \"longlong\", \"ulonglong\",\n \"float\", \"double\", \"longdouble\", \"cfloat\", \"cdouble\",\n \"clongdouble\", \"object\", \"string\", \"unicode\", \"void\", \"ntype\",\n \"unkown\"};\n char msg[500];\n sprintf(msg,\"Conversion Error: received '%s' typed array instead of '%s' typed array for variable '%s'\",\n type_names[arr_type],type_names[numeric_type],name);\n throw_error(PyExc_TypeError,msg); \n }\n }\n \n void numpy_check_type(PyArrayObject* arr_obj, int numeric_type, const char* name)\n {\n // Make sure input has correct numeric type.\n int arr_type = arr_obj->descr->type_num;\n if (PyTypeNum_ISEXTENDED(numeric_type))\n {\n char msg[80];\n sprintf(msg, \"Conversion Error: extended types not supported for variable '%s'\",\n name);\n throw_error(PyExc_TypeError, msg);\n } \n if (!PyArray_EquivalentTypenums(arr_type, numeric_type))\n {\n char* type_names[23] = {\"bool\", \"byte\", \"ubyte\",\"short\", \"ushort\",\n \"int\", \"uint\", \"long\", \"ulong\", \"longlong\", \"ulonglong\",\n \"float\", \"double\", \"longdouble\", \"cfloat\", \"cdouble\",\n \"clongdouble\", \"object\", \"string\", \"unicode\", \"void\", \"ntype\",\n \"unkown\"};\n char msg[500];\n sprintf(msg,\"received '%s' typed array instead of '%s' typed array for variable '%s'\",\n type_names[arr_type],type_names[numeric_type],name);\n throw_error(PyExc_TypeError,msg); \n }\n }\n};\n\nnumpy_type_handler x__numpy_type_handler = numpy_type_handler();\n#define conversion_numpy_check_type x__numpy_type_handler.conversion_numpy_check_type\n#define numpy_check_type x__numpy_type_handler.numpy_check_type\n\n\"\"\"\n\nsize_check_code = \\\n\"\"\"\nclass numpy_size_handler\n{\npublic:\n void conversion_numpy_check_size(PyArrayObject* arr_obj, int Ndims, \n const char* name)\n {\n if (arr_obj->nd != Ndims)\n {\n char msg[500];\n sprintf(msg,\"Conversion Error: received '%d' dimensional array instead of '%d' dimensional array for variable '%s'\",\n arr_obj->nd,Ndims,name);\n throw_error(PyExc_TypeError,msg);\n } \n }\n \n void numpy_check_size(PyArrayObject* arr_obj, int Ndims, const char* name)\n {\n if (arr_obj->nd != Ndims)\n {\n char msg[500];\n sprintf(msg,\"received '%d' dimensional array instead of '%d' dimensional array for variable '%s'\",\n arr_obj->nd,Ndims,name);\n throw_error(PyExc_TypeError,msg);\n } \n }\n};\n\nnumpy_size_handler x__numpy_size_handler = numpy_size_handler();\n#define conversion_numpy_check_size x__numpy_size_handler.conversion_numpy_check_size\n#define numpy_check_size x__numpy_size_handler.numpy_check_size\n\n\"\"\"\n\nnumeric_init_code = \\\n\"\"\"\nPy_Initialize();\nimport_array();\nPyImport_ImportModule(\"scipy\");\n\"\"\" \n \nclass array_converter(common_base_converter):\n\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'numpy'\n self.check_func = 'PyArray_Check' \n self.c_type = 'PyArrayObject*'\n self.return_type = 'PyArrayObject*'\n self.to_c_return = '(PyArrayObject*) py_obj'\n self.matching_types = [ArrayType]\n self.headers = ['\"scipy/arrayobject.h\"',\n '','']\n self.support_code = [size_check_code, type_check_code]\n self.module_init_code = [numeric_init_code] \n \n def get_var_type(self,value):\n return value.dtypechar\n \n def template_vars(self,inline=0):\n res = common_base_converter.template_vars(self,inline) \n if hasattr(self,'var_type'):\n res['num_type'] = num_to_c_types[self.var_type]\n res['num_typecode'] = num_typecode[self.var_type]\n res['array_name'] = self.name + \"_array\"\n return res\n \n def declaration_code(self,templatize = 0,inline=0):\n code = '%(py_var)s = %(var_lookup)s;\\n' \\\n '%(c_type)s %(array_name)s = %(var_convert)s;\\n' \\\n 'conversion_numpy_check_type(%(array_name)s,%(num_typecode)s,\"%(name)s\");\\n' \\\n 'int* N%(name)s = %(array_name)s->dimensions;\\n' \\\n 'int* S%(name)s = %(array_name)s->strides;\\n' \\\n 'int D%(name)s = %(array_name)s->nd;\\n' \\\n '%(num_type)s* %(name)s = (%(num_type)s*) %(array_name)s->data;\\n' \n code = code % self.template_vars(inline=inline)\n return code\n", "source_code_before": "from c_spec import common_base_converter\nfrom c_spec import num_to_c_types\nfrom scipy.base import *\nfrom types import *\nimport os\n\n\nnum_typecode = {}\nnum_typecode['b'] = 'PyArray_SBYTE'\nnum_typecode['B'] = 'PyArray_UBYTE'\nnum_typecode['h'] = 'PyArray_SHORT'\nnum_typecode['H'] = 'PyArray_USHORT'\nnum_typecode['i'] = 'PyArray_INT' # PyArray_INT has troubles ?? What does this note mean ??\nnum_typecode['I'] = 'PyArray_UINT'\nnum_typecode['l'] = 'PyArray_LONG'\nnum_typecode['f'] = 'PyArray_FLOAT'\nnum_typecode['d'] = 'PyArray_DOUBLE'\nnum_typecode['F'] = 'PyArray_CFLOAT'\nnum_typecode['D'] = 'PyArray_CDOUBLE'\n\ntype_check_code = \\\n\"\"\"\nclass numpy_type_handler\n{\npublic:\n void conversion_numpy_check_type(PyArrayObject* arr_obj, int numeric_type,\n const char* name)\n {\n // Make sure input has correct numeric type.\n // allow character and byte to match\n // also allow int and long to match\n int arr_type = arr_obj->descr->type_num;\n if ( arr_type != numeric_type &&\n !(numeric_type == PyArray_CHAR && arr_type == PyArray_SBYTE) &&\n !(numeric_type == PyArray_SBYTE && arr_type == PyArray_CHAR) &&\n !(numeric_type == PyArray_INT && arr_type == PyArray_LONG) &&\n !(numeric_type == PyArray_LONG && arr_type == PyArray_INT)) \n {\n\n char* type_names[20] = {\"char\",\"unsigned byte\",\"byte\", \"short\", \"unsigned short\",\n \"int\", \"unsigned int\", \"long\", \"float\", \"double\", \n \"complex float\",\"complex double\", \"object\",\"ntype\",\n \"unkown\"};\n char msg[500];\n sprintf(msg,\"Conversion Error: received '%s' typed array instead of '%s' typed array for variable '%s'\",\n type_names[arr_type],type_names[numeric_type],name);\n throw_error(PyExc_TypeError,msg); \n }\n }\n \n void numpy_check_type(PyArrayObject* arr_obj, int numeric_type, const char* name)\n {\n // Make sure input has correct numeric type.\n int arr_type = arr_obj->descr->type_num;\n if ( arr_type != numeric_type &&\n !(numeric_type == PyArray_CHAR && arr_type == PyArray_SBYTE) &&\n !(numeric_type == PyArray_SBYTE && arr_type == PyArray_CHAR) &&\n !(numeric_type == PyArray_INT && arr_type == PyArray_LONG) &&\n !(numeric_type == PyArray_LONG && arr_type == PyArray_INT)) \n {\n char* type_names[20] = {\"char\",\"unsigned byte\",\"byte\", \"short\", \n \"unsigned short\", \"int\", \"unsigned int\",\n \"long\", \"float\", \"double\", \n \"complex float\", \"complex double\", \n \"object\",\"ntype\",\"unkown\"};\n char msg[500];\n sprintf(msg,\"received '%s' typed array instead of '%s' typed array for variable '%s'\",\n type_names[arr_type],type_names[numeric_type],name);\n throw_error(PyExc_TypeError,msg); \n }\n }\n};\n\nnumpy_type_handler x__numpy_type_handler = numpy_type_handler();\n#define conversion_numpy_check_type x__numpy_type_handler.conversion_numpy_check_type\n#define numpy_check_type x__numpy_type_handler.numpy_check_type\n\n\"\"\"\n\nsize_check_code = \\\n\"\"\"\nclass numpy_size_handler\n{\npublic:\n void conversion_numpy_check_size(PyArrayObject* arr_obj, int Ndims, \n const char* name)\n {\n if (arr_obj->nd != Ndims)\n {\n char msg[500];\n sprintf(msg,\"Conversion Error: received '%d' dimensional array instead of '%d' dimensional array for variable '%s'\",\n arr_obj->nd,Ndims,name);\n throw_error(PyExc_TypeError,msg);\n } \n }\n \n void numpy_check_size(PyArrayObject* arr_obj, int Ndims, const char* name)\n {\n if (arr_obj->nd != Ndims)\n {\n char msg[500];\n sprintf(msg,\"received '%d' dimensional array instead of '%d' dimensional array for variable '%s'\",\n arr_obj->nd,Ndims,name);\n throw_error(PyExc_TypeError,msg);\n } \n }\n};\n\nnumpy_size_handler x__numpy_size_handler = numpy_size_handler();\n#define conversion_numpy_check_size x__numpy_size_handler.conversion_numpy_check_size\n#define numpy_check_size x__numpy_size_handler.numpy_check_size\n\n\"\"\"\n\nnumeric_init_code = \\\n\"\"\"\nPy_Initialize();\nimport_array();\nPyImport_ImportModule(\"scipy\");\n\"\"\" \n \nclass array_converter(common_base_converter):\n\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'numpy'\n self.check_func = 'PyArray_Check' \n self.c_type = 'PyArrayObject*'\n self.return_type = 'PyArrayObject*'\n self.to_c_return = '(PyArrayObject*) py_obj'\n self.matching_types = [ArrayType]\n self.headers = ['\"scipy/arrayobject.h\"',\n '','']\n self.support_code = [size_check_code, type_check_code]\n self.module_init_code = [numeric_init_code] \n \n def get_var_type(self,value):\n return value.dtypechar\n \n def template_vars(self,inline=0):\n res = common_base_converter.template_vars(self,inline) \n if hasattr(self,'var_type'):\n res['num_type'] = num_to_c_types[self.var_type]\n res['num_typecode'] = num_typecode[self.var_type]\n res['array_name'] = self.name + \"_array\"\n return res\n \n def declaration_code(self,templatize = 0,inline=0):\n code = '%(py_var)s = %(var_lookup)s;\\n' \\\n '%(c_type)s %(array_name)s = %(var_convert)s;\\n' \\\n 'conversion_numpy_check_type(%(array_name)s,%(num_typecode)s,\"%(name)s\");\\n' \\\n 'int* N%(name)s = %(array_name)s->dimensions;\\n' \\\n 'int* S%(name)s = %(array_name)s->strides;\\n' \\\n 'int D%(name)s = %(array_name)s->nd;\\n' \\\n '%(num_type)s* %(name)s = (%(num_type)s*) %(array_name)s->data;\\n' \n code = code % self.template_vars(inline=inline)\n return code\n", "methods": [ { "name": "init_info", "long_name": "init_info( self )", "filename": "standard_array_spec.py", "nloc": 12, "complexity": 1, "token_count": 70, "parameters": [ "self" ], "start_line": 135, "end_line": 146, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "get_var_type", "long_name": "get_var_type( self , value )", "filename": "standard_array_spec.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self", "value" ], "start_line": 148, "end_line": 149, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "template_vars", "long_name": "template_vars( self , inline = 0 )", "filename": "standard_array_spec.py", "nloc": 7, "complexity": 2, "token_count": 61, "parameters": [ "self", "inline" ], "start_line": 151, "end_line": 157, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , templatize = 0 , inline = 0 )", "filename": "standard_array_spec.py", "nloc": 10, "complexity": 1, "token_count": 42, "parameters": [ "self", "templatize", "inline" ], "start_line": 159, "end_line": 168, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 } ], "methods_before": [ { "name": "init_info", "long_name": "init_info( self )", "filename": "standard_array_spec.py", "nloc": 12, "complexity": 1, "token_count": 70, "parameters": [ "self" ], "start_line": 124, "end_line": 135, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "get_var_type", "long_name": "get_var_type( self , value )", "filename": "standard_array_spec.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self", "value" ], "start_line": 137, "end_line": 138, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "template_vars", "long_name": "template_vars( self , inline = 0 )", "filename": "standard_array_spec.py", "nloc": 7, "complexity": 2, "token_count": 61, "parameters": [ "self", "inline" ], "start_line": 140, "end_line": 146, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , templatize = 0 , inline = 0 )", "filename": "standard_array_spec.py", "nloc": 10, "complexity": 1, "token_count": 42, "parameters": [ "self", "templatize", "inline" ], "start_line": 148, "end_line": 157, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 } ], "changed_methods": [], "nloc": 158, "complexity": 5, "token_count": 332, "diff_parsed": { "added": [ "num_typecode['?'] = 'PyArray_BOOL'", "num_typecode['b'] = 'PyArray_BYTE'", "num_typecode['i'] = 'PyArray_INT'", "num_typecode['L'] = 'PyArray_ULONG'", "num_typecode['q'] = 'PyArray_LONGLONG'", "num_typecode['Q'] = 'PyArray_ULONGLONG'", "num_typecode['g'] = 'PyArray_LONGDOUBLE'", "num_typecode['G'] = 'PyArray_CLONGDOUBLE'", " if (PyTypeNum_ISEXTENDED(numeric_type))", " char msg[80];", " sprintf(msg, \"Conversion Error: extended types not supported for variable '%s'\",", " name);", " throw_error(PyExc_TypeError, msg);", " }", " if (!PyArray_EquivalentTypenums(arr_type, numeric_type))", " {", "", " char* type_names[23] = {\"bool\", \"byte\", \"ubyte\",\"short\", \"ushort\",", " \"int\", \"uint\", \"long\", \"ulong\", \"longlong\", \"ulonglong\",", " \"float\", \"double\", \"longdouble\", \"cfloat\", \"cdouble\",", " \"clongdouble\", \"object\", \"string\", \"unicode\", \"void\", \"ntype\",", " \"unkown\"};", " char msg[500];", " sprintf(msg,\"Conversion Error: received '%s' typed array instead of '%s' typed array for variable '%s'\",", " type_names[arr_type],type_names[numeric_type],name);", " throw_error(PyExc_TypeError,msg);", " if (PyTypeNum_ISEXTENDED(numeric_type))", " char msg[80];", " sprintf(msg, \"Conversion Error: extended types not supported for variable '%s'\",", " name);", " throw_error(PyExc_TypeError, msg);", " }", " if (!PyArray_EquivalentTypenums(arr_type, numeric_type))", " {", " char* type_names[23] = {\"bool\", \"byte\", \"ubyte\",\"short\", \"ushort\",", " \"int\", \"uint\", \"long\", \"ulong\", \"longlong\", \"ulonglong\",", " \"float\", \"double\", \"longdouble\", \"cfloat\", \"cdouble\",", " \"clongdouble\", \"object\", \"string\", \"unicode\", \"void\", \"ntype\",", " \"unkown\"};" ], "deleted": [ "num_typecode['b'] = 'PyArray_SBYTE'", "num_typecode['i'] = 'PyArray_INT' # PyArray_INT has troubles ?? What does this note mean ??", " // allow character and byte to match", " // also allow int and long to match", " if ( arr_type != numeric_type &&", " !(numeric_type == PyArray_CHAR && arr_type == PyArray_SBYTE) &&", " !(numeric_type == PyArray_SBYTE && arr_type == PyArray_CHAR) &&", " !(numeric_type == PyArray_INT && arr_type == PyArray_LONG) &&", " !(numeric_type == PyArray_LONG && arr_type == PyArray_INT))", "", " char* type_names[20] = {\"char\",\"unsigned byte\",\"byte\", \"short\", \"unsigned short\",", " \"int\", \"unsigned int\", \"long\", \"float\", \"double\",", " \"complex float\",\"complex double\", \"object\",\"ntype\",", " \"unkown\"};", " char msg[500];", " sprintf(msg,\"Conversion Error: received '%s' typed array instead of '%s' typed array for variable '%s'\",", " type_names[arr_type],type_names[numeric_type],name);", " throw_error(PyExc_TypeError,msg);", " if ( arr_type != numeric_type &&", " !(numeric_type == PyArray_CHAR && arr_type == PyArray_SBYTE) &&", " !(numeric_type == PyArray_SBYTE && arr_type == PyArray_CHAR) &&", " !(numeric_type == PyArray_INT && arr_type == PyArray_LONG) &&", " !(numeric_type == PyArray_LONG && arr_type == PyArray_INT))", " char* type_names[20] = {\"char\",\"unsigned byte\",\"byte\", \"short\",", " \"unsigned short\", \"int\", \"unsigned int\",", " \"long\", \"float\", \"double\",", " \"complex float\", \"complex double\",", " \"object\",\"ntype\",\"unkown\"};" ] } } ] }, { "hash": "60cfb6ab21b92c0d90b69750b279b5c2f3b68563", "msg": "More weave fixes.", "author": { "name": "Travis Oliphant", "email": "oliphant@enthought.com" }, "committer": { "name": "Travis Oliphant", "email": "oliphant@enthought.com" }, "author_date": "2005-10-26T04:55:06+00:00", "author_timezone": 0, "committer_date": "2005-10-26T04:55:06+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "146140cce09b455477d56c06df22aafe647ae6c6" ], "project_name": "repo_copy", "project_path": "/tmp/tmpn4cqam_6/repo_copy", "deletions": 8, "insertions": 8, "lines": 16, "files": 1, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "scipy/weave/c_spec.py", "new_path": "scipy/weave/c_spec.py", "filename": "c_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -289,11 +289,11 @@ def c_to_py_code(self):\n # Standard Python numeric --> C type maps\n #----------------------------------------------------------------------------\n num_to_c_types = {}\n-num_to_c_types[type(1)] = 'int'\n+num_to_c_types[type(1)] = 'long'\n num_to_c_types[type(1.)] = 'double'\n num_to_c_types[type(1.+1.j)] = 'std::complex '\n # !! hmmm. The following is likely unsafe...\n-num_to_c_types[type(1L)] = 'int'\n+num_to_c_types[type(1L)] = 'longlong'\n \n #----------------------------------------------------------------------------\n # Numeric array Python numeric --> C type maps\n@@ -332,9 +332,9 @@ def init_info(self):\n scalar_converter.init_info(self)\n self.type_name = 'int'\n self.check_func = 'PyInt_Check' \n- self.c_type = 'int'\n- self.return_type = 'int'\n- self.to_c_return = \"(int) PyInt_AsLong(py_obj)\"\n+ self.c_type = 'long'\n+ self.return_type = 'long'\n+ self.to_c_return = \"PyInt_AsLong(py_obj)\"\n self.matching_types = [IntType]\n \n class long_converter(scalar_converter):\n@@ -343,9 +343,9 @@ def init_info(self):\n # !! long to int conversion isn't safe!\n self.type_name = 'long'\n self.check_func = 'PyLong_Check' \n- self.c_type = 'int'\n- self.return_type = 'int'\n- self.to_c_return = \"(int) PyLong_AsLong(py_obj)\"\n+ self.c_type = 'longlong'\n+ self.return_type = 'longlong'\n+ self.to_c_return = \"(longlong) PyLong_AsLongLong(py_obj)\"\n self.matching_types = [LongType]\n \n class float_converter(scalar_converter):\n", "added_lines": 8, "deleted_lines": 8, "source_code": "from types import *\nfrom base_spec import base_converter\nimport base_info\n\n#----------------------------------------------------------------------------\n# C++ code template for converting code from python objects to C++ objects\n#\n# This is silly code. There is absolutely no reason why these simple\n# conversion functions should be classes. However, some versions of \n# Mandrake Linux ship with broken C++ compilers (or libraries) that do not\n# handle exceptions correctly when they are thrown from functions. However,\n# exceptions thrown from class methods always work, so we make everything\n# a class method to solve this error.\n#----------------------------------------------------------------------------\n\n#----------------------------------------------------------------------------\n# speed note\n# the convert_to_int macro below takes about 25 ns per conversion on my\n# 850 MHz PIII. A slightly more sophisticated macro version can trim this\n# to 20 ns, but this savings is dang near useless because the other \n# overhead swamps it...\n#----------------------------------------------------------------------------\npy_to_c_template = \\\n\"\"\"\nclass %(type_name)s_handler\n{\npublic: \n %(return_type)s convert_to_%(type_name)s(PyObject* py_obj, const char* name)\n {\n // Incref occurs even if conversion fails so that\n // the decref in cleanup_code has a matching incref.\n %(inc_ref_count)s\n if (!py_obj || !%(check_func)s(py_obj))\n handle_conversion_error(py_obj,\"%(type_name)s\", name); \n return %(to_c_return)s;\n }\n \n %(return_type)s py_to_%(type_name)s(PyObject* py_obj, const char* name)\n {\n // !! Pretty sure INCREF should only be called on success since\n // !! py_to_xxx is used by the user -- not the code generator.\n if (!py_obj || !%(check_func)s(py_obj))\n handle_bad_type(py_obj,\"%(type_name)s\", name); \n %(inc_ref_count)s\n return %(to_c_return)s;\n }\n};\n\n%(type_name)s_handler x__%(type_name)s_handler = %(type_name)s_handler();\n#define convert_to_%(type_name)s(py_obj,name) \\\\\n x__%(type_name)s_handler.convert_to_%(type_name)s(py_obj,name)\n#define py_to_%(type_name)s(py_obj,name) \\\\\n x__%(type_name)s_handler.py_to_%(type_name)s(py_obj,name)\n\n\"\"\"\n\n#----------------------------------------------------------------------------\n# C++ code template for converting code from C++ objects to Python objects\n#\n#----------------------------------------------------------------------------\n\nsimple_c_to_py_template = \\\n\"\"\"\nPyObject* %(type_name)s_to_py(PyObject* obj)\n{\n return (PyObject*) obj;\n}\n\n\"\"\"\n\nclass common_base_converter(base_converter):\n \n def __init__(self):\n self.init_info()\n self._build_information = [self.generate_build_info()]\n \n def init_info(self):\n self.matching_types = []\n self.headers = []\n self.include_dirs = []\n self.libraries = []\n self.library_dirs = []\n self.sources = []\n self.support_code = []\n self.module_init_code = []\n self.warnings = []\n self.define_macros = []\n self.extra_compile_args = []\n self.extra_link_args = []\n self.use_ref_count = 1\n self.name = \"no_name\"\n self.c_type = 'PyObject*'\n self.return_type = 'PyObject*'\n self.to_c_return = 'py_obj'\n \n def info_object(self):\n return base_info.custom_info()\n \n def generate_build_info(self):\n info = self.info_object()\n for header in self.headers:\n info.add_header(header)\n for d in self.include_dirs:\n info.add_include_dir(d)\n for lib in self.libraries:\n info.add_library(lib)\n for d in self.library_dirs:\n info.add_library_dir(d)\n for source in self.sources:\n info.add_source(source)\n for code in self.support_code:\n info.add_support_code(code)\n info.add_support_code(self.py_to_c_code())\n info.add_support_code(self.c_to_py_code())\n for init_code in self.module_init_code:\n info.add_module_init_code(init_code)\n for macro in self.define_macros:\n info.add_define_macro(macro)\n for warning in self.warnings:\n info.add_warning(warning)\n for arg in self.extra_compile_args:\n info.add_extra_compile_arg(arg)\n for arg in self.extra_link_args:\n info.add_extra_link_arg(arg)\n return info\n\n def type_match(self,value):\n return type(value) in self.matching_types\n\n def get_var_type(self,value):\n return type(value)\n \n def type_spec(self,name,value):\n # factory\n new_spec = self.__class__()\n new_spec.name = name \n new_spec.var_type = self.get_var_type(value)\n return new_spec\n\n def template_vars(self,inline=0):\n d = {}\n d['type_name'] = self.type_name\n d['check_func'] = self.check_func\n d['c_type'] = self.c_type\n d['return_type'] = self.return_type\n d['to_c_return'] = self.to_c_return\n d['name'] = self.name\n d['py_var'] = self.py_variable()\n d['var_lookup'] = self.retrieve_py_variable(inline)\n code = 'convert_to_%(type_name)s(%(py_var)s,\"%(name)s\")' % d\n d['var_convert'] = code\n if self.use_ref_count:\n d['inc_ref_count'] = \"Py_XINCREF(py_obj);\"\n else:\n d['inc_ref_count'] = \"\"\n return d\n\n def py_to_c_code(self):\n return py_to_c_template % self.template_vars()\n\n def c_to_py_code(self):\n return simple_c_to_py_template % self.template_vars()\n \n def declaration_code(self,templatize = 0,inline=0):\n code = '%(py_var)s = %(var_lookup)s;\\n' \\\n '%(c_type)s %(name)s = %(var_convert)s;\\n' % \\\n self.template_vars(inline=inline)\n return code \n\n def cleanup_code(self):\n if self.use_ref_count:\n code = 'Py_XDECREF(%(py_var)s);\\n' % self.template_vars()\n #code += 'printf(\"cleaning up %(py_var)s\\\\n\");\\n' % self.template_vars()\n else:\n code = \"\" \n return code\n \n def __repr__(self):\n msg = \"(file:: name: %s)\" % self.name\n return msg\n def __cmp__(self,other):\n #only works for equal\n result = -1\n try:\n result = cmp(self.name,other.name) or \\\n cmp(self.__class__, other.__class__)\n except AttributeError:\n pass\n return result \n\n#----------------------------------------------------------------------------\n# Module Converter\n#----------------------------------------------------------------------------\nclass module_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'module'\n self.check_func = 'PyModule_Check' \n # probably should test for callable classes here also.\n self.matching_types = [ModuleType]\n\n#----------------------------------------------------------------------------\n# String Converter\n#----------------------------------------------------------------------------\nclass string_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'string'\n self.check_func = 'PyString_Check' \n self.c_type = 'std::string'\n self.return_type = 'std::string'\n self.to_c_return = \"std::string(PyString_AsString(py_obj))\"\n self.matching_types = [StringType]\n self.headers.append('')\n def c_to_py_code(self):\n # !! Need to dedent returned code.\n code = \"\"\"\n PyObject* string_to_py(std::string s)\n {\n return PyString_FromString(s.c_str());\n }\n \"\"\"\n return code \n\n#----------------------------------------------------------------------------\n# Unicode Converter\n#----------------------------------------------------------------------------\nclass unicode_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'unicode'\n self.check_func = 'PyUnicode_Check'\n # This isn't supported by gcc 2.95.3 -- MSVC works fine with it. \n #self.c_type = 'std::wstring'\n #self.to_c_return = \"std::wstring(PyUnicode_AS_UNICODE(py_obj))\"\n self.c_type = 'Py_UNICODE*'\n self.return_type = self.c_type\n self.to_c_return = \"PyUnicode_AS_UNICODE(py_obj)\"\n self.matching_types = [UnicodeType]\n #self.headers.append('')\n \n def declaration_code(self,templatize = 0,inline=0):\n # since wstring doesn't seem to work everywhere, we need to provide\n # the length variable Nxxx for the unicode string xxx.\n code = '%(py_var)s = %(var_lookup)s;\\n' \\\n '%(c_type)s %(name)s = %(var_convert)s;\\n' \\\n 'int N%(name)s = PyUnicode_GET_SIZE(%(py_var)s);\\n' \\\n % self.template_vars(inline=inline)\n\n\n return code \n#----------------------------------------------------------------------------\n# File Converter\n#----------------------------------------------------------------------------\nclass file_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'file'\n self.check_func = 'PyFile_Check' \n self.c_type = 'FILE*'\n self.return_type = self.c_type\n self.to_c_return = \"PyFile_AsFile(py_obj)\"\n self.headers = ['']\n self.matching_types = [FileType]\n\n def c_to_py_code(self):\n # !! Need to dedent returned code.\n code = \"\"\"\n PyObject* file_to_py(FILE* file, char* name, char* mode)\n {\n PyObject* py_obj = NULL;\n //extern int fclose(FILE *);\n return (PyObject*) PyFile_FromFile(file, name, mode, fclose);\n }\n \"\"\"\n return code \n\n#----------------------------------------------------------------------------\n#\n# Scalar Number Conversions\n#\n#----------------------------------------------------------------------------\n\n# the following typemaps are for 32 bit platforms. A way to do this\n# general case? maybe ask numeric types how long they are and base\n# the decisions on that.\n\n#----------------------------------------------------------------------------\n# Standard Python numeric --> C type maps\n#----------------------------------------------------------------------------\nnum_to_c_types = {}\nnum_to_c_types[type(1)] = 'long'\nnum_to_c_types[type(1.)] = 'double'\nnum_to_c_types[type(1.+1.j)] = 'std::complex '\n# !! hmmm. The following is likely unsafe...\nnum_to_c_types[type(1L)] = 'longlong'\n\n#----------------------------------------------------------------------------\n# Numeric array Python numeric --> C type maps\n#----------------------------------------------------------------------------\nnum_to_c_types['T'] = 'T' # for templates\nnum_to_c_types['G'] = 'std::complex '\nnum_to_c_types['F'] = 'std::complex '\nnum_to_c_types['D'] = 'std::complex '\nnum_to_c_types['g'] = 'longdouble'\nnum_to_c_types['f'] = 'float'\nnum_to_c_types['d'] = 'double'\nnum_to_c_types['b'] = 'char'\nnum_to_c_types['B'] = 'uchar'\nnum_to_c_types['h'] = 'short'\nnum_to_c_types['H'] = 'ushort'\nnum_to_c_types['i'] = 'int'\nnum_to_c_types['I'] = 'uint'\n\n# not strictly correct, but shoulld be fine fo numeric work.\n# add test somewhere to make sure long can be cast to int before using.\nnum_to_c_types['l'] = 'long'\nnum_to_c_types['L'] = 'ulong'\n\nnum_to_c_types['q'] = 'longlong'\nnum_to_c_types['Q'] = 'ulonglong'\n\nclass scalar_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.warnings = ['disable: 4275', 'disable: 4101']\n self.headers = ['','']\n self.use_ref_count = 0\n\nclass int_converter(scalar_converter):\n def init_info(self):\n scalar_converter.init_info(self)\n self.type_name = 'int'\n self.check_func = 'PyInt_Check' \n self.c_type = 'long'\n self.return_type = 'long'\n self.to_c_return = \"PyInt_AsLong(py_obj)\"\n self.matching_types = [IntType]\n\nclass long_converter(scalar_converter):\n def init_info(self):\n scalar_converter.init_info(self)\n # !! long to int conversion isn't safe!\n self.type_name = 'long'\n self.check_func = 'PyLong_Check' \n self.c_type = 'longlong'\n self.return_type = 'longlong'\n self.to_c_return = \"(longlong) PyLong_AsLongLong(py_obj)\"\n self.matching_types = [LongType]\n\nclass float_converter(scalar_converter):\n def init_info(self):\n scalar_converter.init_info(self)\n # Not sure this is really that safe...\n self.type_name = 'float'\n self.check_func = 'PyFloat_Check' \n self.c_type = 'double'\n self.return_type = 'double'\n self.to_c_return = \"PyFloat_AsDouble(py_obj)\"\n self.matching_types = [FloatType]\n\nclass complex_converter(scalar_converter):\n def init_info(self):\n scalar_converter.init_info(self)\n self.type_name = 'complex'\n self.check_func = 'PyComplex_Check' \n self.c_type = 'std::complex'\n self.return_type = 'std::complex'\n self.to_c_return = \"std::complex(PyComplex_RealAsDouble(py_obj),\"\\\n \"PyComplex_ImagAsDouble(py_obj))\"\n self.matching_types = [ComplexType]\n\n#----------------------------------------------------------------------------\n#\n# List, Tuple, and Dict converters.\n#\n# Based on SCXX by Gordon McMillan\n#----------------------------------------------------------------------------\nimport os, c_spec # yes, I import myself to find out my __file__ location.\nlocal_dir,junk = os.path.split(os.path.abspath(c_spec.__file__)) \nscxx_dir = os.path.join(local_dir,'scxx')\n\nclass scxx_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.headers = ['\"scxx/object.h\"','\"scxx/list.h\"','\"scxx/tuple.h\"',\n '\"scxx/dict.h\"','']\n self.include_dirs = [local_dir,scxx_dir]\n self.sources = [os.path.join(scxx_dir,'weave_imp.cpp'),]\n\nclass list_converter(scxx_converter):\n def init_info(self):\n scxx_converter.init_info(self)\n self.type_name = 'list'\n self.check_func = 'PyList_Check' \n self.c_type = 'py::list'\n self.return_type = 'py::list'\n self.to_c_return = 'py::list(py_obj)'\n self.matching_types = [ListType]\n # ref counting handled by py::list\n self.use_ref_count = 0\n\nclass tuple_converter(scxx_converter):\n def init_info(self):\n scxx_converter.init_info(self)\n self.type_name = 'tuple'\n self.check_func = 'PyTuple_Check' \n self.c_type = 'py::tuple'\n self.return_type = 'py::tuple'\n self.to_c_return = 'py::tuple(py_obj)'\n self.matching_types = [TupleType]\n # ref counting handled by py::tuple\n self.use_ref_count = 0\n\nclass dict_converter(scxx_converter):\n def init_info(self):\n scxx_converter.init_info(self)\n self.type_name = 'dict'\n self.check_func = 'PyDict_Check' \n self.c_type = 'py::dict'\n self.return_type = 'py::dict'\n self.to_c_return = 'py::dict(py_obj)'\n self.matching_types = [DictType]\n # ref counting handled by py::dict\n self.use_ref_count = 0\n\n#----------------------------------------------------------------------------\n# Instance Converter\n#----------------------------------------------------------------------------\nclass instance_converter(scxx_converter):\n def init_info(self):\n scxx_converter.init_info(self)\n self.type_name = 'instance'\n self.check_func = 'PyInstance_Check' \n self.c_type = 'py::object'\n self.return_type = 'py::object'\n self.to_c_return = 'py::object(py_obj)'\n self.matching_types = [InstanceType]\n # ref counting handled by py::object\n self.use_ref_count = 0\n\n#----------------------------------------------------------------------------\n# Catchall Converter\n#\n# catch all now handles callable objects\n#----------------------------------------------------------------------------\nclass catchall_converter(scxx_converter):\n def init_info(self):\n scxx_converter.init_info(self)\n self.type_name = 'catchall'\n self.check_func = '' \n self.c_type = 'py::object'\n self.return_type = 'py::object'\n self.to_c_return = 'py::object(py_obj)'\n # ref counting handled by py::object\n self.use_ref_count = 0\n def type_match(self,value):\n return 1\n\nif __name__ == \"__main__\":\n x = list_converter().type_spec(\"x\",1)\n print x.py_to_c_code()\n print\n print x.c_to_py_code()\n print\n print x.declaration_code(inline=1)\n print\n print x.cleanup_code()\n", "source_code_before": "from types import *\nfrom base_spec import base_converter\nimport base_info\n\n#----------------------------------------------------------------------------\n# C++ code template for converting code from python objects to C++ objects\n#\n# This is silly code. There is absolutely no reason why these simple\n# conversion functions should be classes. However, some versions of \n# Mandrake Linux ship with broken C++ compilers (or libraries) that do not\n# handle exceptions correctly when they are thrown from functions. However,\n# exceptions thrown from class methods always work, so we make everything\n# a class method to solve this error.\n#----------------------------------------------------------------------------\n\n#----------------------------------------------------------------------------\n# speed note\n# the convert_to_int macro below takes about 25 ns per conversion on my\n# 850 MHz PIII. A slightly more sophisticated macro version can trim this\n# to 20 ns, but this savings is dang near useless because the other \n# overhead swamps it...\n#----------------------------------------------------------------------------\npy_to_c_template = \\\n\"\"\"\nclass %(type_name)s_handler\n{\npublic: \n %(return_type)s convert_to_%(type_name)s(PyObject* py_obj, const char* name)\n {\n // Incref occurs even if conversion fails so that\n // the decref in cleanup_code has a matching incref.\n %(inc_ref_count)s\n if (!py_obj || !%(check_func)s(py_obj))\n handle_conversion_error(py_obj,\"%(type_name)s\", name); \n return %(to_c_return)s;\n }\n \n %(return_type)s py_to_%(type_name)s(PyObject* py_obj, const char* name)\n {\n // !! Pretty sure INCREF should only be called on success since\n // !! py_to_xxx is used by the user -- not the code generator.\n if (!py_obj || !%(check_func)s(py_obj))\n handle_bad_type(py_obj,\"%(type_name)s\", name); \n %(inc_ref_count)s\n return %(to_c_return)s;\n }\n};\n\n%(type_name)s_handler x__%(type_name)s_handler = %(type_name)s_handler();\n#define convert_to_%(type_name)s(py_obj,name) \\\\\n x__%(type_name)s_handler.convert_to_%(type_name)s(py_obj,name)\n#define py_to_%(type_name)s(py_obj,name) \\\\\n x__%(type_name)s_handler.py_to_%(type_name)s(py_obj,name)\n\n\"\"\"\n\n#----------------------------------------------------------------------------\n# C++ code template for converting code from C++ objects to Python objects\n#\n#----------------------------------------------------------------------------\n\nsimple_c_to_py_template = \\\n\"\"\"\nPyObject* %(type_name)s_to_py(PyObject* obj)\n{\n return (PyObject*) obj;\n}\n\n\"\"\"\n\nclass common_base_converter(base_converter):\n \n def __init__(self):\n self.init_info()\n self._build_information = [self.generate_build_info()]\n \n def init_info(self):\n self.matching_types = []\n self.headers = []\n self.include_dirs = []\n self.libraries = []\n self.library_dirs = []\n self.sources = []\n self.support_code = []\n self.module_init_code = []\n self.warnings = []\n self.define_macros = []\n self.extra_compile_args = []\n self.extra_link_args = []\n self.use_ref_count = 1\n self.name = \"no_name\"\n self.c_type = 'PyObject*'\n self.return_type = 'PyObject*'\n self.to_c_return = 'py_obj'\n \n def info_object(self):\n return base_info.custom_info()\n \n def generate_build_info(self):\n info = self.info_object()\n for header in self.headers:\n info.add_header(header)\n for d in self.include_dirs:\n info.add_include_dir(d)\n for lib in self.libraries:\n info.add_library(lib)\n for d in self.library_dirs:\n info.add_library_dir(d)\n for source in self.sources:\n info.add_source(source)\n for code in self.support_code:\n info.add_support_code(code)\n info.add_support_code(self.py_to_c_code())\n info.add_support_code(self.c_to_py_code())\n for init_code in self.module_init_code:\n info.add_module_init_code(init_code)\n for macro in self.define_macros:\n info.add_define_macro(macro)\n for warning in self.warnings:\n info.add_warning(warning)\n for arg in self.extra_compile_args:\n info.add_extra_compile_arg(arg)\n for arg in self.extra_link_args:\n info.add_extra_link_arg(arg)\n return info\n\n def type_match(self,value):\n return type(value) in self.matching_types\n\n def get_var_type(self,value):\n return type(value)\n \n def type_spec(self,name,value):\n # factory\n new_spec = self.__class__()\n new_spec.name = name \n new_spec.var_type = self.get_var_type(value)\n return new_spec\n\n def template_vars(self,inline=0):\n d = {}\n d['type_name'] = self.type_name\n d['check_func'] = self.check_func\n d['c_type'] = self.c_type\n d['return_type'] = self.return_type\n d['to_c_return'] = self.to_c_return\n d['name'] = self.name\n d['py_var'] = self.py_variable()\n d['var_lookup'] = self.retrieve_py_variable(inline)\n code = 'convert_to_%(type_name)s(%(py_var)s,\"%(name)s\")' % d\n d['var_convert'] = code\n if self.use_ref_count:\n d['inc_ref_count'] = \"Py_XINCREF(py_obj);\"\n else:\n d['inc_ref_count'] = \"\"\n return d\n\n def py_to_c_code(self):\n return py_to_c_template % self.template_vars()\n\n def c_to_py_code(self):\n return simple_c_to_py_template % self.template_vars()\n \n def declaration_code(self,templatize = 0,inline=0):\n code = '%(py_var)s = %(var_lookup)s;\\n' \\\n '%(c_type)s %(name)s = %(var_convert)s;\\n' % \\\n self.template_vars(inline=inline)\n return code \n\n def cleanup_code(self):\n if self.use_ref_count:\n code = 'Py_XDECREF(%(py_var)s);\\n' % self.template_vars()\n #code += 'printf(\"cleaning up %(py_var)s\\\\n\");\\n' % self.template_vars()\n else:\n code = \"\" \n return code\n \n def __repr__(self):\n msg = \"(file:: name: %s)\" % self.name\n return msg\n def __cmp__(self,other):\n #only works for equal\n result = -1\n try:\n result = cmp(self.name,other.name) or \\\n cmp(self.__class__, other.__class__)\n except AttributeError:\n pass\n return result \n\n#----------------------------------------------------------------------------\n# Module Converter\n#----------------------------------------------------------------------------\nclass module_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'module'\n self.check_func = 'PyModule_Check' \n # probably should test for callable classes here also.\n self.matching_types = [ModuleType]\n\n#----------------------------------------------------------------------------\n# String Converter\n#----------------------------------------------------------------------------\nclass string_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'string'\n self.check_func = 'PyString_Check' \n self.c_type = 'std::string'\n self.return_type = 'std::string'\n self.to_c_return = \"std::string(PyString_AsString(py_obj))\"\n self.matching_types = [StringType]\n self.headers.append('')\n def c_to_py_code(self):\n # !! Need to dedent returned code.\n code = \"\"\"\n PyObject* string_to_py(std::string s)\n {\n return PyString_FromString(s.c_str());\n }\n \"\"\"\n return code \n\n#----------------------------------------------------------------------------\n# Unicode Converter\n#----------------------------------------------------------------------------\nclass unicode_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'unicode'\n self.check_func = 'PyUnicode_Check'\n # This isn't supported by gcc 2.95.3 -- MSVC works fine with it. \n #self.c_type = 'std::wstring'\n #self.to_c_return = \"std::wstring(PyUnicode_AS_UNICODE(py_obj))\"\n self.c_type = 'Py_UNICODE*'\n self.return_type = self.c_type\n self.to_c_return = \"PyUnicode_AS_UNICODE(py_obj)\"\n self.matching_types = [UnicodeType]\n #self.headers.append('')\n \n def declaration_code(self,templatize = 0,inline=0):\n # since wstring doesn't seem to work everywhere, we need to provide\n # the length variable Nxxx for the unicode string xxx.\n code = '%(py_var)s = %(var_lookup)s;\\n' \\\n '%(c_type)s %(name)s = %(var_convert)s;\\n' \\\n 'int N%(name)s = PyUnicode_GET_SIZE(%(py_var)s);\\n' \\\n % self.template_vars(inline=inline)\n\n\n return code \n#----------------------------------------------------------------------------\n# File Converter\n#----------------------------------------------------------------------------\nclass file_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'file'\n self.check_func = 'PyFile_Check' \n self.c_type = 'FILE*'\n self.return_type = self.c_type\n self.to_c_return = \"PyFile_AsFile(py_obj)\"\n self.headers = ['']\n self.matching_types = [FileType]\n\n def c_to_py_code(self):\n # !! Need to dedent returned code.\n code = \"\"\"\n PyObject* file_to_py(FILE* file, char* name, char* mode)\n {\n PyObject* py_obj = NULL;\n //extern int fclose(FILE *);\n return (PyObject*) PyFile_FromFile(file, name, mode, fclose);\n }\n \"\"\"\n return code \n\n#----------------------------------------------------------------------------\n#\n# Scalar Number Conversions\n#\n#----------------------------------------------------------------------------\n\n# the following typemaps are for 32 bit platforms. A way to do this\n# general case? maybe ask numeric types how long they are and base\n# the decisions on that.\n\n#----------------------------------------------------------------------------\n# Standard Python numeric --> C type maps\n#----------------------------------------------------------------------------\nnum_to_c_types = {}\nnum_to_c_types[type(1)] = 'int'\nnum_to_c_types[type(1.)] = 'double'\nnum_to_c_types[type(1.+1.j)] = 'std::complex '\n# !! hmmm. The following is likely unsafe...\nnum_to_c_types[type(1L)] = 'int'\n\n#----------------------------------------------------------------------------\n# Numeric array Python numeric --> C type maps\n#----------------------------------------------------------------------------\nnum_to_c_types['T'] = 'T' # for templates\nnum_to_c_types['G'] = 'std::complex '\nnum_to_c_types['F'] = 'std::complex '\nnum_to_c_types['D'] = 'std::complex '\nnum_to_c_types['g'] = 'longdouble'\nnum_to_c_types['f'] = 'float'\nnum_to_c_types['d'] = 'double'\nnum_to_c_types['b'] = 'char'\nnum_to_c_types['B'] = 'uchar'\nnum_to_c_types['h'] = 'short'\nnum_to_c_types['H'] = 'ushort'\nnum_to_c_types['i'] = 'int'\nnum_to_c_types['I'] = 'uint'\n\n# not strictly correct, but shoulld be fine fo numeric work.\n# add test somewhere to make sure long can be cast to int before using.\nnum_to_c_types['l'] = 'long'\nnum_to_c_types['L'] = 'ulong'\n\nnum_to_c_types['q'] = 'longlong'\nnum_to_c_types['Q'] = 'ulonglong'\n\nclass scalar_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.warnings = ['disable: 4275', 'disable: 4101']\n self.headers = ['','']\n self.use_ref_count = 0\n\nclass int_converter(scalar_converter):\n def init_info(self):\n scalar_converter.init_info(self)\n self.type_name = 'int'\n self.check_func = 'PyInt_Check' \n self.c_type = 'int'\n self.return_type = 'int'\n self.to_c_return = \"(int) PyInt_AsLong(py_obj)\"\n self.matching_types = [IntType]\n\nclass long_converter(scalar_converter):\n def init_info(self):\n scalar_converter.init_info(self)\n # !! long to int conversion isn't safe!\n self.type_name = 'long'\n self.check_func = 'PyLong_Check' \n self.c_type = 'int'\n self.return_type = 'int'\n self.to_c_return = \"(int) PyLong_AsLong(py_obj)\"\n self.matching_types = [LongType]\n\nclass float_converter(scalar_converter):\n def init_info(self):\n scalar_converter.init_info(self)\n # Not sure this is really that safe...\n self.type_name = 'float'\n self.check_func = 'PyFloat_Check' \n self.c_type = 'double'\n self.return_type = 'double'\n self.to_c_return = \"PyFloat_AsDouble(py_obj)\"\n self.matching_types = [FloatType]\n\nclass complex_converter(scalar_converter):\n def init_info(self):\n scalar_converter.init_info(self)\n self.type_name = 'complex'\n self.check_func = 'PyComplex_Check' \n self.c_type = 'std::complex'\n self.return_type = 'std::complex'\n self.to_c_return = \"std::complex(PyComplex_RealAsDouble(py_obj),\"\\\n \"PyComplex_ImagAsDouble(py_obj))\"\n self.matching_types = [ComplexType]\n\n#----------------------------------------------------------------------------\n#\n# List, Tuple, and Dict converters.\n#\n# Based on SCXX by Gordon McMillan\n#----------------------------------------------------------------------------\nimport os, c_spec # yes, I import myself to find out my __file__ location.\nlocal_dir,junk = os.path.split(os.path.abspath(c_spec.__file__)) \nscxx_dir = os.path.join(local_dir,'scxx')\n\nclass scxx_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.headers = ['\"scxx/object.h\"','\"scxx/list.h\"','\"scxx/tuple.h\"',\n '\"scxx/dict.h\"','']\n self.include_dirs = [local_dir,scxx_dir]\n self.sources = [os.path.join(scxx_dir,'weave_imp.cpp'),]\n\nclass list_converter(scxx_converter):\n def init_info(self):\n scxx_converter.init_info(self)\n self.type_name = 'list'\n self.check_func = 'PyList_Check' \n self.c_type = 'py::list'\n self.return_type = 'py::list'\n self.to_c_return = 'py::list(py_obj)'\n self.matching_types = [ListType]\n # ref counting handled by py::list\n self.use_ref_count = 0\n\nclass tuple_converter(scxx_converter):\n def init_info(self):\n scxx_converter.init_info(self)\n self.type_name = 'tuple'\n self.check_func = 'PyTuple_Check' \n self.c_type = 'py::tuple'\n self.return_type = 'py::tuple'\n self.to_c_return = 'py::tuple(py_obj)'\n self.matching_types = [TupleType]\n # ref counting handled by py::tuple\n self.use_ref_count = 0\n\nclass dict_converter(scxx_converter):\n def init_info(self):\n scxx_converter.init_info(self)\n self.type_name = 'dict'\n self.check_func = 'PyDict_Check' \n self.c_type = 'py::dict'\n self.return_type = 'py::dict'\n self.to_c_return = 'py::dict(py_obj)'\n self.matching_types = [DictType]\n # ref counting handled by py::dict\n self.use_ref_count = 0\n\n#----------------------------------------------------------------------------\n# Instance Converter\n#----------------------------------------------------------------------------\nclass instance_converter(scxx_converter):\n def init_info(self):\n scxx_converter.init_info(self)\n self.type_name = 'instance'\n self.check_func = 'PyInstance_Check' \n self.c_type = 'py::object'\n self.return_type = 'py::object'\n self.to_c_return = 'py::object(py_obj)'\n self.matching_types = [InstanceType]\n # ref counting handled by py::object\n self.use_ref_count = 0\n\n#----------------------------------------------------------------------------\n# Catchall Converter\n#\n# catch all now handles callable objects\n#----------------------------------------------------------------------------\nclass catchall_converter(scxx_converter):\n def init_info(self):\n scxx_converter.init_info(self)\n self.type_name = 'catchall'\n self.check_func = '' \n self.c_type = 'py::object'\n self.return_type = 'py::object'\n self.to_c_return = 'py::object(py_obj)'\n # ref counting handled by py::object\n self.use_ref_count = 0\n def type_match(self,value):\n return 1\n\nif __name__ == \"__main__\":\n x = list_converter().type_spec(\"x\",1)\n print x.py_to_c_code()\n print\n print x.c_to_py_code()\n print\n print x.declaration_code(inline=1)\n print\n print x.cleanup_code()\n", "methods": [ { "name": "__init__", "long_name": "__init__( self )", "filename": "c_spec.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 73, "end_line": 75, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 18, "complexity": 1, "token_count": 102, "parameters": [ "self" ], "start_line": 77, "end_line": 94, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 }, { "name": "info_object", "long_name": "info_object( self )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 96, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "generate_build_info", "long_name": "generate_build_info( self )", "filename": "c_spec.py", "nloc": 27, "complexity": 12, "token_count": 177, "parameters": [ "self" ], "start_line": 99, "end_line": 125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 127, "end_line": 128, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_var_type", "long_name": "get_var_type( self , value )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self", "value" ], "start_line": 130, "end_line": 131, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "c_spec.py", "nloc": 5, "complexity": 1, "token_count": 33, "parameters": [ "self", "name", "value" ], "start_line": 133, "end_line": 138, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "template_vars", "long_name": "template_vars( self , inline = 0 )", "filename": "c_spec.py", "nloc": 17, "complexity": 2, "token_count": 114, "parameters": [ "self", "inline" ], "start_line": 140, "end_line": 156, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "py_to_c_code", "long_name": "py_to_c_code( self )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 158, "end_line": 159, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "c_to_py_code", "long_name": "c_to_py_code( self )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 161, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , templatize = 0 , inline = 0 )", "filename": "c_spec.py", "nloc": 5, "complexity": 1, "token_count": 30, "parameters": [ "self", "templatize", "inline" ], "start_line": 164, "end_line": 168, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "cleanup_code", "long_name": "cleanup_code( self )", "filename": "c_spec.py", "nloc": 6, "complexity": 2, "token_count": 26, "parameters": [ "self" ], "start_line": 170, "end_line": 176, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "c_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 178, "end_line": 180, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "c_spec.py", "nloc": 8, "complexity": 3, "token_count": 43, "parameters": [ "self", "other" ], "start_line": 181, "end_line": 189, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "self" ], "start_line": 195, "end_line": 200, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 9, "complexity": 1, "token_count": 51, "parameters": [ "self" ], "start_line": 206, "end_line": 214, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "c_to_py_code", "long_name": "c_to_py_code( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 10, "parameters": [ "self" ], "start_line": 215, "end_line": 223, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 45, "parameters": [ "self" ], "start_line": 229, "end_line": 239, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , templatize = 0 , inline = 0 )", "filename": "c_spec.py", "nloc": 6, "complexity": 1, "token_count": 32, "parameters": [ "self", "templatize", "inline" ], "start_line": 242, "end_line": 251, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 9, "complexity": 1, "token_count": 52, "parameters": [ "self" ], "start_line": 256, "end_line": 264, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "c_to_py_code", "long_name": "c_to_py_code( self )", "filename": "c_spec.py", "nloc": 10, "complexity": 1, "token_count": 10, "parameters": [ "self" ], "start_line": 266, "end_line": 276, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 5, "complexity": 1, "token_count": 34, "parameters": [ "self" ], "start_line": 324, "end_line": 328, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 43, "parameters": [ "self" ], "start_line": 331, "end_line": 338, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 43, "parameters": [ "self" ], "start_line": 341, "end_line": 349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 43, "parameters": [ "self" ], "start_line": 352, "end_line": 360, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 9, "complexity": 1, "token_count": 45, "parameters": [ "self" ], "start_line": 363, "end_line": 371, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 6, "complexity": 1, "token_count": 52, "parameters": [ "self" ], "start_line": 384, "end_line": 389, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 9, "complexity": 1, "token_count": 48, "parameters": [ "self" ], "start_line": 392, "end_line": 401, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 9, "complexity": 1, "token_count": 48, "parameters": [ "self" ], "start_line": 404, "end_line": 413, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 9, "complexity": 1, "token_count": 48, "parameters": [ "self" ], "start_line": 416, "end_line": 425, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 9, "complexity": 1, "token_count": 48, "parameters": [ "self" ], "start_line": 431, "end_line": 440, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 41, "parameters": [ "self" ], "start_line": 448, "end_line": 456, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self", "value" ], "start_line": 457, "end_line": 458, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 } ], "methods_before": [ { "name": "__init__", "long_name": "__init__( self )", "filename": "c_spec.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 73, "end_line": 75, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 18, "complexity": 1, "token_count": 102, "parameters": [ "self" ], "start_line": 77, "end_line": 94, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 }, { "name": "info_object", "long_name": "info_object( self )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 96, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "generate_build_info", "long_name": "generate_build_info( self )", "filename": "c_spec.py", "nloc": 27, "complexity": 12, "token_count": 177, "parameters": [ "self" ], "start_line": 99, "end_line": 125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 127, "end_line": 128, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_var_type", "long_name": "get_var_type( self , value )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self", "value" ], "start_line": 130, "end_line": 131, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "c_spec.py", "nloc": 5, "complexity": 1, "token_count": 33, "parameters": [ "self", "name", "value" ], "start_line": 133, "end_line": 138, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "template_vars", "long_name": "template_vars( self , inline = 0 )", "filename": "c_spec.py", "nloc": 17, "complexity": 2, "token_count": 114, "parameters": [ "self", "inline" ], "start_line": 140, "end_line": 156, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "py_to_c_code", "long_name": "py_to_c_code( self )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 158, "end_line": 159, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "c_to_py_code", "long_name": "c_to_py_code( self )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 161, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , templatize = 0 , inline = 0 )", "filename": "c_spec.py", "nloc": 5, "complexity": 1, "token_count": 30, "parameters": [ "self", "templatize", "inline" ], "start_line": 164, "end_line": 168, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "cleanup_code", "long_name": "cleanup_code( self )", "filename": "c_spec.py", "nloc": 6, "complexity": 2, "token_count": 26, "parameters": [ "self" ], "start_line": 170, "end_line": 176, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "c_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 178, "end_line": 180, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "c_spec.py", "nloc": 8, "complexity": 3, "token_count": 43, "parameters": [ "self", "other" ], "start_line": 181, "end_line": 189, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "self" ], "start_line": 195, "end_line": 200, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 9, "complexity": 1, "token_count": 51, "parameters": [ "self" ], "start_line": 206, "end_line": 214, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "c_to_py_code", "long_name": "c_to_py_code( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 10, "parameters": [ "self" ], "start_line": 215, "end_line": 223, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 45, "parameters": [ "self" ], "start_line": 229, "end_line": 239, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , templatize = 0 , inline = 0 )", "filename": "c_spec.py", "nloc": 6, "complexity": 1, "token_count": 32, "parameters": [ "self", "templatize", "inline" ], "start_line": 242, "end_line": 251, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 9, "complexity": 1, "token_count": 52, "parameters": [ "self" ], "start_line": 256, "end_line": 264, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "c_to_py_code", "long_name": "c_to_py_code( self )", "filename": "c_spec.py", "nloc": 10, "complexity": 1, "token_count": 10, "parameters": [ "self" ], "start_line": 266, "end_line": 276, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 5, "complexity": 1, "token_count": 34, "parameters": [ "self" ], "start_line": 324, "end_line": 328, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 43, "parameters": [ "self" ], "start_line": 331, "end_line": 338, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 43, "parameters": [ "self" ], "start_line": 341, "end_line": 349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 43, "parameters": [ "self" ], "start_line": 352, "end_line": 360, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 9, "complexity": 1, "token_count": 45, "parameters": [ "self" ], "start_line": 363, "end_line": 371, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 6, "complexity": 1, "token_count": 52, "parameters": [ "self" ], "start_line": 384, "end_line": 389, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 9, "complexity": 1, "token_count": 48, "parameters": [ "self" ], "start_line": 392, "end_line": 401, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 9, "complexity": 1, "token_count": 48, "parameters": [ "self" ], "start_line": 404, "end_line": 413, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 9, "complexity": 1, "token_count": 48, "parameters": [ "self" ], "start_line": 416, "end_line": 425, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 9, "complexity": 1, "token_count": 48, "parameters": [ "self" ], "start_line": 431, "end_line": 440, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 41, "parameters": [ "self" ], "start_line": 448, "end_line": 456, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self", "value" ], "start_line": 457, "end_line": 458, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 43, "parameters": [ "self" ], "start_line": 331, "end_line": 338, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 } ], "nloc": 341, "complexity": 48, "token_count": 1734, "diff_parsed": { "added": [ "num_to_c_types[type(1)] = 'long'", "num_to_c_types[type(1L)] = 'longlong'", " self.c_type = 'long'", " self.return_type = 'long'", " self.to_c_return = \"PyInt_AsLong(py_obj)\"", " self.c_type = 'longlong'", " self.return_type = 'longlong'", " self.to_c_return = \"(longlong) PyLong_AsLongLong(py_obj)\"" ], "deleted": [ "num_to_c_types[type(1)] = 'int'", "num_to_c_types[type(1L)] = 'int'", " self.c_type = 'int'", " self.return_type = 'int'", " self.to_c_return = \"(int) PyInt_AsLong(py_obj)\"", " self.c_type = 'int'", " self.return_type = 'int'", " self.to_c_return = \"(int) PyLong_AsLong(py_obj)\"" ] } } ] }, { "hash": "c001bbef5637bdf8f625cf4ab5f32521aa7dac17", "msg": "Cosmetic fixes.", "author": { "name": "Travis Oliphant", "email": "oliphant@enthought.com" }, "committer": { "name": "Travis Oliphant", "email": "oliphant@enthought.com" }, "author_date": "2005-10-26T05:05:10+00:00", "author_timezone": 0, "committer_date": "2005-10-26T05:05:10+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "60cfb6ab21b92c0d90b69750b279b5c2f3b68563" ], "project_name": "repo_copy", "project_path": "/tmp/tmpn4cqam_6/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": "scipy/base/src/arrayobject.c", "new_path": "scipy/base/src/arrayobject.c", "filename": "arrayobject.c", "extension": "c", "change_type": "MODIFY", "diff": "@@ -3885,7 +3885,7 @@ array_size_get(PyArrayObject *self)\n {\n \tlonglong size=PyArray_SIZE(self);\n \tif (size > MAX_INT || size < MIN_INT)\n-\t\treturn PyLong_FromLongLong((longlong) size);\n+\t\treturn PyLong_FromLongLong(size);\n \telse \n \t\treturn PyInt_FromLong((long) size);\n }\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\n/* $Id: arrayobject.c,v 1.59 2005/09/14 00:14:00 teoliphant Exp $ */\n\n/*\n#include \"Python.h\"\n#include \"structmember.h\"\n\n#define _MULTIARRAYMODULE\n#include \"Numeric3/arrayobject.h\"\n*/\n\n/* Helper functions */\n\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\n\nstatic intp\nPyArray_PyIntAsIntp(PyObject *o)\n{\n\tlonglong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr=NULL;\n\tPyArray_Typecode typecode = {PyArray_INTP, 0, 0};\n\tintp ret;\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\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\tarr = PyArray_CastToType((PyArrayObject *)o, &typecode);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tarr = PyArray_FromScalar(o, &typecode);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((intp *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\t\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONGLONG != SIZEOF_PY_INTPTR_T)\n\tif ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C intp\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (intp) long_value;\n}\n\n\nstatic PyObject *array_int(PyArrayObject *v);\n\nstatic int\nPyArray_PyIntAsInt(PyObject *o)\n{\n\tlong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr=NULL;\n\tPyArray_Typecode typecode = {PyArray_INT, 0, 0};\n\tint ret;\n\t\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\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\tarr = PyArray_CastToType((PyArrayObject *)o, &typecode);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tarr = PyArray_FromScalar(o, &typecode);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((int *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONG != SIZEOF_INT)\n\tif ((long_value < INT_MIN) || (long_value > INT_MAX)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C int\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (int) long_value;\n}\n\n\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\nstatic char *\nPyArray_Zero(PyArrayObject *arr)\n{\n char *zeroval;\n char *buf;\n int buf_len;\n PyObject *obj, *ret;\n\n zeroval = PyDataMem_NEW(arr->itemsize);\n if (zeroval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n if (PyArray_ISOBJECT(arr)) {\n obj=PyInt_FromLong((long) 0);\n memcpy(zeroval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return zeroval;\n }\n ret = PyObject_GetAttrString((PyObject *)arr, \"_zero\");\n if (ret != NULL) {\n if (PyObject_AsReadBuffer(ret, (const void **)&buf, \n &buf_len) < 0) {\n PyErr_SetString(PyExc_ValueError, \n \"_zero not returning \" \\\n \"writeable buffer\");\n Py_DECREF(ret);\n return NULL;\n }\n memcpy(zeroval, buf, buf_len);\n Py_DECREF(ret);\n }\n if (PyErr_Occurred()) PyErr_Clear();\n memset(zeroval, 0, arr->itemsize);\n return zeroval;\n}\n\nstatic char *\nPyArray_One(PyArrayObject *arr)\n{\n char *oneval;\n char *buf;\n int buf_len, ret2;\n PyObject *obj, *ret;\n\n oneval = PyDataMem_NEW(arr->itemsize);\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 ret = PyObject_GetAttrString((PyObject *)arr, \"_one\");\n if (ret != NULL) {\n if (PyObject_AsReadBuffer(ret, (const void **)&buf, \n &buf_len) < 0) {\n PyErr_SetString(PyExc_ValueError, \n \"_one not returning \" \\\n \"writeable buffer\");\n Py_DECREF(ret);\n PyDataMem_FREE(oneval);\n return NULL;\n }\n memcpy(oneval, buf, buf_len);\n Py_DECREF(ret);\n }\n if (PyErr_Occurred()) PyErr_Clear();\n\n ret2 = arr->descr->setitem(obj, oneval, arr);\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->itemsize;\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 *)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 { free(new_data); return NULL; }\n}\n\n/* end Helper functions */\n\n\nstatic PyObject *PyArray_New(PyTypeObject *, int nd, intp *, \n int, intp *, char *, 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. */\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/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\n\nstatic char *\nindex2ptr(PyArrayObject *mp, int i) \n{\n\tif (i==0 && (mp->nd == 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\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\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->copyswap;\n\tcopyswapn = dest->descr->copyswapn;\n\n elsize = dest->itemsize;\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->itemsize;\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\tPyArray_Typecode typecode;\n\n\n\ttypecode.type_num = dest->descr->type_num;\n\ttypecode.itemsize = dest->itemsize;\n\ttypecode.fortran = PyArray_ISFORTRAN(dest);\n\t\t\t\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n\t\t\t\t\t &typecode, 0,\n\t\t\t\t\t dest->nd, 0);\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\nstatic PyObject *\nPyArray_FromDimsAndDataAndDescr(int nd, int *d, \n PyArray_Descr *descr,\n char *data) {\n\tPyObject *ret;\n\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\n\tintp newd[MAX_DIMS];\n\t\n\tfor (i=0; itype_num, NULL, data, descr->elsize, \n\t\t\t CARRAY_FLAGS, NULL);\n#else\n\tret = PyArray_New(&PyArray_Type, nd, (intp *)d, \n descr->type_num, NULL, data, descr->elsize, \n\t\t\t CARRAY_FLAGS, NULL);\n#endif\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_FromDimsAndData(int nd, int *d, int type, char *data) \n{\n\tPyObject *ret;\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\t\n\tintp newd[MAX_DIMS];\n\n\tfor (i=0; iob_type, m1->nd, \n\t\t\t\t\t m1->dimensions,\n\t\t\t\t\t m1->descr->type_num,\n\t\t\t\t\t NULL, NULL, m1->itemsize,\n\t\t\t\t\t 0, (PyObject *)m1);\n\t\n if (PyArray_CopyInto(ret, m1) == -1) return NULL;\n\t\n return (PyObject *)ret;\n}\n\n\nstatic PyObject *array_item(PyArrayObject *, int);\n\nstatic PyObject *\nPyArray_Scalar(char *data, int type_num, int itemsize, int swap)\n{\n PyArray_Descr *descr;\n\tPyTypeObject *type;\n\tPyObject *obj;\t\n\tchar *destptr;\n PyArray_CopySwapFunc *copyswap;\n\n descr = PyArray_DescrFromType(type_num);\n if (descr == NULL) return NULL;\n type = descr->typeobj;\n copyswap = descr->copyswap;\n\tif (type_num == PyArray_STRING) \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_ISFLEXIBLE(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 {\n\t\t\tdestptr = PyDataMem_NEW(itemsize);\n\t\t\tif (destptr == NULL) {\n\t\t\t\tPyObject_Del(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tif (type_num == PyArray_UNICODE) {\n\t\t\t\tPyUnicode_AS_UNICODE(obj) = \\\n\t\t\t\t\t(Py_UNICODE *)destptr;\n\t\t\t\t((PyUnicodeObject*)obj)->length = itemsize / \\\n\t\t\t\t\tsizeof(Py_UNICODE);\n\t\t\t\t((PyUnicodeObject*)obj)->hash = -1;\n\t\t\t}\n\t\t\telse {\n\t\t\t\t((PyVoidScalarObject *)obj)->obval = destptr;\n\t\t\t\t((PyVoidScalarObject *)obj)->ob_size = itemsize;\n\t\t\t}\n\t\t}\n\t}\n\telse {\n\t\tdestptr = &(((PyScalarObject*)obj)->obval);\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*/\nstatic PyObject *\nPyArray_ToScalar(char *data, PyArrayObject *arr)\n{\n\tint type_num = arr->descr->type_num;\n\tint itemsize = arr->itemsize;\n int swap = !(PyArray_ISNOTSWAPPED(arr));\n\n\treturn PyArray_Scalar(data, type_num, itemsize, swap);\n}\n\n\n/* Return Python scalar if 0-d array object is encountered */\n\nstatic PyObject *\nPyArray_Return(PyArrayObject *mp) \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((PyObject *)mp) && 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*/\nstatic int \nPyArray_RegisterDataType(PyTypeObject *type)\n{\n\tPyArray_Descr *descr;\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 = malloc(sizeof(PyArray_Descr));\n\tmemcpy(descr, PyArray_DescrFromType(PyArray_VOID), \n\t sizeof(PyArray_Descr));\n\ttypenum = PyArray_USERDEF + PyArray_NUMUSERTYPES;\n\tdescr->type_num = typenum;\n\tdescr->typeobj = 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 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 frees the copy of the Descr_table already there.\n places a pointer to the new one into the slot.\n*/\nstatic int\nPyArray_RegisterDescrForType(int typenum, PyArray_Descr *descr)\n{\n\tPyArray_Descr *old;\n\tint i;\n\n\tif (!PyTypeNum_ISUSERDEF(typenum)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"data type not registered\");\n\t\treturn -1;\n\t}\n\told = userdescrs[typenum-PyArray_USERDEF];\n\tdescr->typeobj = old->typeobj;\n\tdescr->type_num = typenum;\n\n#define _NULL_CHECK(member) \\\n\tif (descr->member == NULL) descr->member = old->member\n\n\tfor (i=0; imember == 0) descr->member = old->member\n\n\t_ZERO_CHECK(kind);\n\t_ZERO_CHECK(type);\n\t_ZERO_CHECK(elsize);\n\t_ZERO_CHECK(alignment);\n#undef _ZERO_CHECK\n\n\tfree(old);\n\tuserdescrs[typenum-PyArray_USERDEF] = descr;\n\treturn 0;\n}\n\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 n3 = strlen((const char *)sep);\n if (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 \"\\\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->itemsize,\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->itemsize,\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 = strlen((const char *)format);\n while(it->index < it->size) {\n obj = self->descr->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\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->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\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 if (PyArray_TYPE(self) == PyArray_OBJECT) {\n PyErr_SetString(PyExc_ValueError, \"a string for the data\"\\\n\t\t\t\t\"in an object array is not appropriate\");\n return NULL;\n }\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->itemsize;\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 != NULL)) {\n\t\t/* Free internal references if an Object array */\n\t\tPyArray_XDECREF(self);\n\n PyDataMem_FREE(self->data);\n }\n\t\n if (self->dimensions != NULL) {\n PyDimMem_FREE(self->dimensions); \n\t}\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\n\nstatic PyObject *\narray_item(PyArrayObject *self, int i) \n{\n char *item;\n PyArrayObject *r;\n\n\n\tif(self->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n if ((item = index2ptr(self, i)) == NULL) return NULL;\n\n\tr = (PyArrayObject *)PyArray_New(self->ob_type, \n\t\t\t\t\t self->nd-1, self->dimensions+1, \n\t\t\t\t\t self->descr->type_num, \n\t\t\t\t\t self->strides+1, item, \n\t\t\t\t\t self->itemsize, self->flags,\n\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_item(self, i));\n}\n\n\nstatic int \narray_ass_item(PyArrayObject *self, int 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\n if (i < 0) i = i+self->dimensions[0];\n\n if (self->nd > 1) {\n if((tmp = (PyArrayObject *)array_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->setitem(v, item, self) == -1) return -1;\n return 0;\n}\n\n/* -------------------------------------------------------------- */\nstatic int\nslice_coerce_index(PyObject *o, int *v)\n{\n\t*v = PyArray_PyIntAsInt(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, int length,\n int *start, int *stop, int *step,\n intp *slicelength)\n{\n\tint 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 int\nparse_subindex(PyObject *op, int *step_size, intp *n_steps, int max)\n{\n\tint 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\tint 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_PyIntAsInt(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, start, offset, n_add, n_pseudo;\n int step_size;\n\tintp n_steps;\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, *tup;\n\tint n1, n2, n3, val;\n\tint i;\n\n\ttup = PyTuple_New(mit->nd);\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\tPyTuple_SET_ITEM(tup, i++, PyInt_FromLong((long)val++));\n\tval = 0;\n\twhile(val < n1)\n\t\tPyTuple_SET_ITEM(tup, i++, PyInt_FromLong((long)val++));\n\tval = n1+n2;\n\twhile(val < n3)\n\t\tPyTuple_SET_ITEM(tup, i++, PyInt_FromLong((long)val++));\n\n\tnew = PyArray_Transpose(*ret, tup);\n\tPy_DECREF(tup);\n\tPy_DECREF(*ret);\n\t*ret = (PyArrayObject *)new;\n}\n\n\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\tret = (PyArrayObject *)\\\n\t\tPyArray_New(temp->ob_type, mit->nd, mit->dimensions, \n\t\t\t temp->descr->type_num, NULL, NULL, \n\t\t\t temp->itemsize, \n\t\t\t PyArray_ISFORTRAN(temp),\n\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\treturn NULL;\n\tindex = it->size;\n\tswap = ((temp->flags & NOTSWAPPED) != (ret->flags & NOTSWAPPED));\n copyswap = ret->descr->copyswap;\n\tPyArray_MapIterReset(mit);\n\twhile (index--) {\n copyswap(it->dataptr, mit->dataptr, swap, ret->itemsize);\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\tPyArray_Typecode typecode = {0, 0, 0};\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Unbound Map Iterator */\n\tif (mit->ait == NULL) return -1;\n\n\ttypecode.type_num = mit->ait->ao->descr->type_num;\n\ttypecode.itemsize = mit->ait->ao->itemsize;\n\n\tarr = PyArray_FromAny(op, &typecode, \n\t\t\t 0, 0, FORCECAST);\n\tif (arr == NULL) return -1;\n\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, (PyArrayObject **)&arr);\n\t\t}\n\t}\n\t\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) \n\t\treturn -1;\n\n\tindex = mit->size;\n\tswap = ((mit->ait->ao->flags & NOTSWAPPED) != \\\n\t\t(PyArray_FLAGS(arr) & NOTSWAPPED));\n\n copyswap = PyArray_DESCR(arr)->copyswap;\n\tPyArray_MapIterReset(mit);\n /* Need to decref OBJECT arrays */\n if (PyTypeNum_ISOBJECT(typecode.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 copyswap(mit->dataptr, NULL, swap, \n sizeof(PyObject *));\n PyArray_MapIterNext(mit);\n PyArray_ITER_NEXT(it);\n if (it->index == it->size)\n PyArray_ITER_RESET(it);\n }\n return 0;\n }\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\treturn 0;\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 0-dimensional arrays */\n\nstatic PyObject *\narray_subscript(PyArrayObject *self, PyObject *op) \n{\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n\tintp offset;\n int nd, i;\n PyArrayObject *other;\n\tPyArrayMapIterObject *mit;\n\n if (PyArray_IsScalar(op, Integer) || PyInt_Check(op) || \\\n PyLong_Check(op)) {\n intp value;\n value = PyArray_PyIntAsIntp(op);\n if (PyErr_Occurred())\n PyErr_Clear();\n else if (value >= 0) {\n if (value <= MAX_INT)\n return array_item(self, (int) value);\n }\n else if (value < 0) {\n if (value >= -MAX_INT) {\n if (self->nd > 0) value += self->dimensions[0];\n return array_item(self, (int) value);\n }\n }\n }\n\n\tif (PyArrayMapIter_Check(op)) {\n\t\tmit = (PyArrayMapIterObject *)op;\n\t\t/* bind to current array */\n\t\tPyArray_MapIterBind(mit, self);\n\t\t\n\t\t/* If the mapiterator was created with standard indexing\n\t\t behavior, fall through to view-based code */\n\t\tif (!mit->view) return PyArray_GetMap(mit);\n\t\top = mit->indexobj;\n\t}\n\telse { /* wrap arguments into a mapiter object */\n\t\tmit = (PyArrayMapIterObject *)PyArray_MapIterNew(op);\n\t\tif (mit == NULL) return NULL;\n\t\tif (!mit->view) { /* fancy indexing */\n\t\t\tPyArray_MapIterBind(mit, self);\n\t\t\tother = (PyArrayObject *)PyArray_GetMap(mit);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn (PyObject *)other;\n\t\t}\n\t\tPy_DECREF(mit);\n\t}\n\n\ti = PyArray_PyIntAsInt(op);\n\tif (!error_converting(i)) {\n\t\tif (i < 0 && self->nd > 0) i = i+self->dimensions[0];\n\t\treturn array_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\tif ((other = (PyArrayObject *)\t\t\t\t\t\\\n\t PyArray_New(self->ob_type, nd, dimensions, self->descr->type_num,\n\t\t\t strides, self->data+offset, \n\t\t\t self->itemsize, self->flags,\n\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 \narray_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op) \n{\n int ret, 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\n\tif (PyArrayMapIter_Check(index)) {\n\t\tmit = (PyArrayMapIterObject *)index;\n\t\t/* bind behavior to current array */\n\t\tPyArray_MapIterBind(mit, self);\n\t\t\t\n\t\t/* fall through if standard view-based map iterator */\n\t\tif (!mit->view) return PyArray_SetMap(mit, op);\n\t\tindex = mit->indexobj;\n\t}\n\telse {\n\t\tmit = (PyArrayMapIterObject *)PyArray_MapIterNew(index);\n\t\tif (mit == NULL) return -1;\n\t\tif (!mit->view) {\n\t\t\tPyArray_MapIterBind(mit, self);\n\t\t\tret = PyArray_SetMap(mit, op);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn ret;\n\t\t}\n\t\tPy_DECREF((PyObject*)mit);\n\t}\n\n\ti = PyArray_PyIntAsInt(index);\n\tif (!error_converting(i)) {\n\t\treturn array_ass_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 ret = PyArray_CopyObject(tmp, op);\n Py_DECREF(tmp);\n\t\n return ret;\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 \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\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}\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}\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 PyObject *args, *ret;\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n args = Py_BuildValue(\"(OO)\", m1, m2);\n ret = PyObject_Call(op, args, NULL);\n Py_DECREF(args);\n return ret;\n}\n\nstatic PyObject *\nPyArray_GenericUnaryFunction(PyArrayObject *m1, PyObject *op) \n{\n PyObject *args, *ret;\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n args = Py_BuildValue(\"(O)\", m1);\n ret = PyObject_Call(op, args, NULL);\n Py_DECREF(args);\n return ret;\n}\n\nstatic PyObject *\nPyArray_GenericInplaceBinaryFunction(PyArrayObject *m1, \n\t\t\t\t PyObject *m2, PyObject *op) \n{\n PyObject *args, *ret;\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n args = Py_BuildValue(\"(OOO)\", m1, m2, m1);\n ret = PyObject_Call(op, args, NULL);\n Py_DECREF(args);\n return ret;\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_all_nonzero(PyArrayObject *mp) \n{\n\tintp index;\n\tPyArrayIterObject *it;\n\tBool anyTRUE = 0;\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->nonzero(it->dataptr, mp)) {\n\t\t\tanyTRUE = 1;\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 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->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->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->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->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->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_all_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 r = (PyArrayObject *)\\\n\t\tPyArray_New(self->ob_type, self->nd, self->dimensions, \n\t\t\t self->descr->type_num, self->strides, data,\n\t\t\t self->itemsize, 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 any(self == el) */\n\n return PyObject_RichCompareBool((PyObject *)self, el, Py_EQ);\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 *)realloc(*string, *max_n); }\n\t\n if (nd == 0) {\n\t\t\n if ((op = descr->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\tfree(string); return NULL; \n\t}\n\t\n\tif (PyArray_ISFLEXIBLE(self)) {\n\t\tchar buf[100];\n\t\tsnprintf(buf, sizeof(buf), \"%d\", self->itemsize);\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 free(string);\n return ret;\n}\n\nstatic PyObject *PyArray_StrFunction=NULL;\nstatic PyObject *PyArray_ReprFunction=NULL;\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\n\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) \n{\n PyObject *array_other, *result;\n\n switch (cmp_op) \n {\n case Py_LT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less);\n case Py_LE:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less_equal);\n case Py_EQ:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then return the integer\n\t\t\t object 0. This fixes code that used to\n\t\t\t allow equality comparisons between arrays\n\t\t\t and other objects which would give a result\n\t\t\t of 0\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n result = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.equal);\n /* If the comparison results in NULL, then the \n\t\t\t two array objects can not be compared together so \n\t\t\t return zero \n */\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n return result;\n case Py_NE:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then objects cannot be \n\t\t\t compared and cannot be equal, therefore, \n\t\t\t return True;\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n result = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.not_equal);\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n return result;\n case Py_GT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.greater);\n case Py_GE:\n return PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t other, \n\t\t\t\t\t \t n_ops.greater_equal);\n }\n return NULL;\n}\n\nstatic PyObject *\n_check_axis(PyArrayObject *arr, int *axis, int flags)\n{\n\tPyObject *temp;\n\tint n = arr->nd;\n\n\tif ((*axis >= MAX_DIMS) || (n==0)) {\n\t\ttemp = PyArray_Ravel(arr,0);\n\t\t*axis = 0;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_FromAny((PyObject *)arr, NULL, \n\t\t\t\t\t 0, 0, flags);\n\t\t\tif (temp == NULL) return NULL;\n\t\t}\n\t\telse {\n\t\t\tPy_INCREF(arr);\n\t\t\ttemp = (PyObject *)arr;\n\t\t}\n\t}\n\tif (*axis < 0) *axis += n;\n\tif ((*axis < 0) || (*axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", *axis);\n\t\tPy_DECREF(temp);\n\t\treturn NULL;\n\t}\n\treturn temp;\n}\n\n#include \"arraymethods.c\"\n\n/* Lifted from numarray */\nstatic PyObject *\nPyArray_IntTupleFromIntp(int len, intp *vals)\n{\n\tint i;\n PyObject *intTuple = PyTuple_New(len);\n if (!intTuple) goto fail;\n for(i=0; ind == 0) return 1;\n\tsd = ap->itemsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\n\t}\n\treturn 1;\n}\n\n\nstatic int \n_IsFortranContiguous(PyArrayObject *ap) \n{\n\tint sd;\n\tint i;\n\t\n\tif (ap->nd == 0) return 1;\n\tsd = ap->itemsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i=0; i< ap->nd; ++i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\n\t}\n\treturn 1;\n}\n\nstatic int\n_IsAligned(PyArrayObject *ap) \n{\n\tint i, alignment, aligned=1;\n\tintp ptr;\n\tint type = ap->descr->type_num;\n\n\tif ((type == PyArray_STRING) || (type == PyArray_VOID))\n\t\treturn 1;\n\n\talignment = ap->descr->alignment;\n\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\tPyBufferProcs *pb;\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\tpb = base->ob_type->tp_as_buffer;\n\tif (pb == NULL || pb->bf_getwritebuffer == NULL)\n\t\treturn FALSE;\n\t\n\treturn TRUE;\n}\n\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\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not \n walk outside of the memory implied by either numbytes or\n a single segment array of the provided dimensions and element size if\n numbytes is 0 */\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, \n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\t\n\tif (numbytes == 0) \n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\t\n\tfor (i=0; i numbytes) {\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\treturn TRUE;\n\t\n}\n\n\n/* This is the main array creation routine. */\n\n/* Flags argument has multiple related meanings \n depending on data and strides: \n\n If data is given, then flags is flags associated with data. \n If strides is not given, then a contiguous strides array will be created\n and the CONTIGUOUS bit will be set. If the flags argument \n has the FORTRAN bit set, then a FORTRAN-style strides array will be\n created (and of course the FORTRAN flag bit will be set). \n\n If data is not given but created here, then flags will be DEFAULT_FLAGS\n and a non-zero flags argument can be used to indicate a FORTRAN style\n array is desired. \n*/\n\nstatic intp\n_array_fill_strides(intp *strides, intp *dims, int nd, intp itemsize, \n\t\t int inflag, int *objflags) \n{\n\tint i;\n\t/* Only make Fortran strides if not contiguous as well */\n\tif ((inflag & FORTRAN) && !(inflag & CONTIGUOUS)) {\n\t\tfor (i=0; i 1) *objflags &= ~CONTIGUOUS;\n\t\telse *objflags |= CONTIGUOUS;\n\t}\n\telse {\n\t\tfor (i=nd-1;i>=0;i--) {\n\t\t\tstrides[i] = itemsize;\n\t\t\titemsize *= dims[i] ? dims[i] : 1;\n\t\t}\n\t\t*objflags |= CONTIGUOUS;\n\t\tif (nd > 1) *objflags &= ~FORTRAN;\n\t\telse *objflags |= FORTRAN;\n\t}\n\treturn itemsize;\n}\n\n\t\nstatic PyObject *\nPyArray_New(PyTypeObject *subtype, int nd, intp *dims, int type_num,\n intp *strides, char *data, int itemsize, int flags,\n\t PyObject *obj)\n{\n\tPyArrayObject *self;\n\tPyArray_Descr *descr;\n\tregister int i;\n\tintp sd, temp=-1;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\tif (descr == NULL) return NULL;\n\n\tif (nd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"number of dimensions must be >=0\");\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 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\treturn NULL;\n\t\t}\n\t}\n\t\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) return NULL;\t\n\tself->descr = descr;\n\tself->dimensions = 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\n\tif (PyTypeNum_ISFLEXIBLE(type_num)) {\n\t\tif (itemsize < 1) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"type must provide an itemsize\");\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn NULL;\n\t\t}\n\t\tself->itemsize = itemsize;\n\t\t/* Guarantee that these kind of arrays are never byteswapped\n\t\t unknowingly. \n\t\t*/\n\t\tif (type_num != PyArray_UNICODE)\n\t\t\tself->flags |= NOTSWAPPED;\n\t}\n\telse self->itemsize = descr->elsize; \n\t\t\n\tsd = self->itemsize;\n\t\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn PyErr_NoMemory();\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\tPyDimMem_FREE(self->dimensions);\n\t\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\t\treturn NULL;\n\t\t\t}\t\t\t\t\n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t}\n \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 (a.data) doesn't work\n\t\t as it should. */\n\n\t\tif (sd==0) sd = sizeof(intp);\n\n\t\tif ((data = PyDataMem_NEW(sd))==NULL) {\n\t\t\tPyDimMem_FREE(self->dimensions);\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn PyErr_NoMemory();\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\n\t\t/* It is bad to have unitialized OBJECT pointers */\n\t\t/* We shouldn't need to check for the OBJECT Letter\n\t\t but perhaps it's best. */\n\t\tif (type_num == PyArray_OBJECT || \\\n\t\t type_num == PyArray_OBJECTLTR) {\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\tself->nd = nd;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\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;\n\t\tif (temp==-1) { /* 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\tres = PyObject_CallMethod((PyObject *)self, \n\t\t\t\t\t \"__array_finalize__\",\n\t\t\t\t\t \"O\", obj);\n\t\tif (res == NULL) {\n\t\t\tPyDimMem_FREE(self->dimensions);\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn NULL;\n\t\t}\n\t\telse Py_DECREF(res);\n\t}\n\n\treturn (PyObject *)self;\n}\n\n\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\n newsize = PyArray_MultiplyList(new_dimensions, new_nd);\n\n if (newsize == 0) {\n PyErr_SetString(PyExc_ValueError, \n \"newsize is zero; cannot delete an array \"\\\n \"in this way\");\n return NULL;\n }\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 = (((PyObject *)self)->ob_refcnt);\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\n\t\t/* Reallocate space if needed */\n\t\tnew_data = PyDataMem_RENEW(self->data, \n\t\t\t\t\t newsize*(self->itemsize));\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->itemsize;\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->itemsize;\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 */\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; idataptr, fromptr, itemsize);\n\t\t\tPyArray_ITER_NEXT(iter);\n\t\t}\n\n\t\tPy_DECREF(iter);\n\t\tPy_DECREF(behaved);\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\", \"strides\", \n \"swap\", \"fortran\", NULL};\n\tint itemsize = 0;\n\tPyArray_Typecode typecode = {PyArray_NOTYPE, 0, 0};\n\tint type_num = PyArray_NOTYPE;\n PyArray_Dims dims = {NULL, 0};\n PyArray_Dims strides = {NULL, 0};\n PyArray_Chunk buffer;\n\tint fortran = 0;\n int swapped = 0;\n\tPyArrayObject *ret;\n\n\tbuffer.ptr = NULL; \n /* Usually called with shape and type\n but can also be called with buffer, strides, and swapped info\n */\n\n\t/* For now, let's just use this to create an empty, contiguous \n\t array of a specific type and shape. \n\t*/\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&O&ii\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &dims, \n PyArray_TypecodeConverter,\n\t\t\t\t\t &typecode, \n PyArray_BufferConverter,\n &buffer,\n &PyArray_IntpConverter, \n &strides,\n &swapped, &fortran)) \n\t\treturn NULL;\n\t\n if (typecode.type_num ==PyArray_NOTYPE) {\n\t\ttypecode.type_num = PyArray_DOUBLE;\n\t\ttypecode.itemsize = sizeof(double);\n\t}\n\ttype_num = typecode.type_num;\n\titemsize = typecode.itemsize;\n\n\n if (dims.ptr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"need to give a \"\\\n \"valid shape as the first argument\");\n goto fail;\n }\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)PyArray_New(subtype, (int)dims.len, \n dims.ptr, type_num,\n NULL, NULL, itemsize, \n fortran, NULL);\n \n if (ret == NULL) goto fail;\n if (type_num == PyArray_OBJECT) { /* place Py_None */\n PyArray_FillObjectArray(ret, Py_None);\n }\n }\n else { /* buffer given -- use it */\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = buffer.len / itemsize;\n }\n else if (buffer.len < itemsize* \\\n PyArray_MultiplyList(dims.ptr, dims.len)) {\n PyErr_SetString(PyExc_TypeError, \n \"buffer is too small for \" \\\n \"requested array\");\n goto fail;\n }\n if (strides.ptr != NULL) {\n\t\t\tif (strides.len != dims.len) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides, if given, must be \"\\\n\t\t\t\t\t\t\"the same length as shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CheckStrides(itemsize, strides.len, \n\t\t\t\t\t\t buffer.len,\n\t\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides is incompatible \"\\\n\t\t\t\t\t\t\"with shape of requested\"\\\n\t\t\t\t\t\t\"array and size of buffer\");\n\t\t\t\tgoto fail;\n\t\t\t}\n }\n if (type_num == PyArray_OBJECT) {\n PyErr_SetString(PyExc_TypeError, \"cannot construct \"\\\n \"an object array from buffer data\");\n goto fail;\n }\n /* get writeable and aligned */\n if (fortran) buffer.flags |= FORTRAN;\n if (!(swapped)) buffer.flags |= NOTSWAPPED;\n ret = (PyArrayObject *)PyArray_New(subtype, dims.len, \n dims.ptr, type_num,\n strides.ptr,\n (char *)buffer.ptr, \n itemsize, \n buffer.flags, NULL); \n if (ret == 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 PyArray_Return(ret);\n \n fail:\n if (dims.ptr) PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return NULL;\n}\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 static PyObject *module=NULL;\n\n if (module==NULL) {\n module = PyImport_ImportModule(\"scipy.base._internal\");\n if (module == NULL) return NULL;\n }\n return PyObject_CallMethod(module, \"flagsobj\", \"Oii\", \n self, self->flags, 0);\n}\n\n/*\nstatic int\narray_flags_set(PyArrayObject *self, PyObject *obj) \n{\n\tint flagback = self->flags;\n\n if (PyDict_Check(obj)) {\n PyObject *new;\n\t\tnew = PyDict_GetItemString(obj, \"ALIGNED\");\n\t\tif (new) {\n\t\t\tif (PyObject_Not(new)) self->flags &= ~ALIGNED;\n\t\t\telse if (_IsAligned(self)) self->flags |= ALIGNED;\n\t\t\telse {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"cannot set aligned flag of \" \\\n\t\t\t\t\t\t\"mis-aligned array to True\");\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t}\n new = PyDict_GetItemString(obj, \"UPDATEIFCOPY\");\n if (new) {\n if (PyObject_Not(new)) {\n self->flags &= ~UPDATEIFCOPY;\n Py_DECREF(self->base);\n self->base = NULL;\n }\n else {\n\t\t\t\tself->flags = flagback;\n PyErr_SetString(PyExc_ValueError, \n \"cannot set UPDATEIFCOPY \" \\\n \"flag to True\");\n return -1;\n }\n }\n new = PyDict_GetItemString(obj, \"WRITEABLE\");\n if (new) {\n\t\t\tif (PyObject_IsTrue(new)) {\n\t\t\t\tif (_IsWriteable(self)) {\n\t\t\t\t\tself->flags |= WRITEABLE;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tself->flags = flagback;\n\t\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\t\"cannot set \"\t\\\n\t\t\t\t\t\t\t\"WRITEABLE \"\t\\\n\t\t\t\t\t\t\t\"flag to True of \"\\\n\t\t\t\t\t\t\t\"this array \");\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n else\n self->flags &= ~WRITEABLE;\n }\n new = PyDict_GetItemString(obj, \"NOTSWAPPED\");\n if (new) {\n if (PyObject_IsTrue(new))\n self->flags |= NOTSWAPPED;\n else {\n self->flags &= ~NOTSWAPPED;\n\t\t\t}\n\t\t}\n return 0;\n }\n PyErr_SetString(PyExc_ValueError, \n \"object must be a dictionary\");\n return -1;\n}\n*/\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\tif (!PyTuple_Check(val)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"shape must be a tuple\");\n\t\treturn -1;\n\t}\n\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\n\t\n\tif (self->nd > 0) { /* Free old dimensions and strides */\n\t\tPyDimMem_FREE(self->dimensions);\n\t}\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;\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\treturn -1;\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->itemsize;\n\t\n\tif (!PyArray_CheckStrides(self->itemsize, self->nd, numbytes, \n\t\t\t\t self->dimensions, newstrides.ptr)) {\n\t\tPyErr_SetString(PyExc_ValueError, \"strides is not \"\\\n\t\t\t\t\"compatible with available memory\");\n\t\treturn -1;\n\t}\n\tmemcpy(self->strides, newstrides.ptr, sizeof(intp)*newstrides.len);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\treturn 0;\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->itemsize);\n}\n\nstatic PyObject *\narray_size_get(PyArrayObject *self)\n{\n\tlonglong size=PyArray_SIZE(self);\n\tif (size > MAX_INT || size < MIN_INT)\n\t\treturn PyLong_FromLongLong(size);\n\telse \n\t\treturn PyInt_FromLong((long) size);\n}\n\n\nstatic PyObject *\narray_typechar_get(PyArrayObject *self)\n{\n\tif PyArray_ISFLEXIBLE(self) \n\t\treturn PyString_FromFormat(\"%c%d\", (self->descr->type),\n\t\t\t\t\t self->itemsize);\n\telse \n\t\treturn PyString_FromStringAndSize(&(self->descr->type), 1);\n}\n\nstatic PyObject *\narray_typestr_get(PyArrayObject *self)\n{\n\tstatic char endians[] = \"<>\";\n\tchar endian;\n\tint which;\n\tunsigned long val = 1;\n\tchar *s;\n\tchar basic_=self->descr->kind;\n\n\ts = (char *)&val; /* s[0] == 0 implies big-endian */\n\twhich = (PyArray_ISNOTSWAPPED(self) ? 0 : 1);\n\tif (s[0] == 0) which = 1 - which;\n\tendian = endians[which]; \n\t\n\tif ((basic_==PyArray_VOIDLTR) || (basic_==PyArray_STRINGLTR) || \\\n\t (basic_==PyArray_OBJECTLTR) || (self->itemsize == 1))\n\t\treturn PyString_FromFormat(\"|%c%d\", basic_, self->itemsize);\n\telse\n\t\treturn PyString_FromFormat(\"%c%c%d\", endian, basic_,\n\t\t\t\t\t self->itemsize);\n}\n\nstatic PyObject *\narray_descr_get(PyArrayObject *self)\n{\n\tPyObject *res;\n\tPyObject *dobj;\n\n\t/* hand this off to the typeobject */\n\t/* or give default */\n\tif (PyArray_ISUSERDEF(self)) {\n\t\tres = PyObject_GetAttrString((PyObject *)self->descr->typeobj, \n\t\t\t\t\t \"__array_descr__\");\n\t\tif (res) return res;\n\t\tPyErr_Clear();\n\t}\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\n\nstatic PyObject *\narray_type_get(PyArrayObject *self)\n{\n\treturn PyArray_TypeObjectFromType(self->descr->type_num);\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*/\n\nstatic int\narray_type_set(PyArrayObject *self, PyObject *arg)\n{\n PyArray_Typecode newtype = {PyArray_NOTYPE, 0, 0};\n intp newdim;\n int index;\n char *msg = \"new type not compatible with array.\";\n\n if ((PyArray_TypecodeConverter(arg, &newtype) < 0) ||\n newtype.type_num == PyArray_NOTYPE) {\n PyErr_SetString(PyExc_TypeError, \"invalid type for array\");\n return -1;\n }\n if (!(PyArray_ISONESEGMENT(self) ||\t\t\\\n\t (newtype.itemsize != self->itemsize))) {\n PyErr_SetString(PyExc_ValueError, msg);\n return -1; \n }\n\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\n if (newtype.itemsize < self->itemsize) {\n /* if it is compatible increase the size of the dimension\n at end (or at the front for FORTRAN)\n */\n if (self->itemsize % newtype.itemsize != 0) {\n PyErr_SetString(PyExc_ValueError, msg);\n return -1;\n }\n newdim = self->itemsize / newtype.itemsize;\n\t\tself->dimensions[index] *= newdim;\n self->strides[index] = newtype.itemsize;\n\t}\n \n else if (newtype.itemsize > self->itemsize) {\n \n /* Determine if last (or first if FORTRAN) dimension\n is compatible */\n\n\t\tnewdim = self->dimensions[index] * self->itemsize;\n if ((newdim % newtype.itemsize) != 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, msg);\n return -1;\n }\n\t\t\n self->dimensions[index] = newdim / newtype.itemsize;\n self->strides[index] = newtype.itemsize;\n\t\t\n }\n\t\n \n /* fall through -- adjust type*/\n\n self->descr = PyArray_DescrFromType(newtype.type_num);\n self->itemsize = newtype.itemsize;\n PyArray_UpdateFlags(self, ALIGNED);\n return 0;\n\n}\n\n\n\nstatic PyObject *\narray_base_get(PyArrayObject *self)\n{\n\tif (self->base == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\telse {\n\t\tPy_INCREF(self->base);\n\t\treturn self->base;\n\t}\n}\n\n\nstatic PyObject *\narray_real_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *)ret;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n}\n\n\nstatic int\narray_real_set(PyArrayObject *self, PyObject *val)\n{\n\tPyArrayObject *ret;\n\tPyArrayObject *new;\n\tint rint;\n\n\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0);\n\tif (new == NULL) return -1;\n\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) 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\treturn rint;\n}\n\nstatic PyObject *\narray_imag_get(PyArrayObject *self)\n{\t\n\tPyArrayObject *ret;\n\tint itemsize;\n\tint typenum;\n PyArray_Typecode type;\n\t\n\ttype.type_num = self->descr->type_num;\n\ttype.itemsize = self->itemsize;\n\ttype.fortran = PyArray_ISFORTRAN(self);\n\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\titemsize = self->itemsize >> 1;\n\t\ttypenum = self->descr->type_num - PyArray_NUM_FLOATTYPE;\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 typenum,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data + itemsize,\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\tret = (PyArrayObject *)PyArray_Zeros(self->nd, \n\t\t\t\t\t\t self->dimensions, &type);\n\t\tret->flags &= ~WRITEABLE;\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic int\narray_imag_set(PyArrayObject *self, PyObject *val)\n{\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyArrayObject *ret;\n\t\tPyArrayObject *new;\n\t\tint rint;\n\n\t\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0); \n\t\tif (new == NULL) return -1;\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides+ \\\n\t\t\t\t\t\t (self->itemsize >> 1) ,\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) {\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_Typecode typecode;\n int swap;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode.type_num = self->descr->type_num;\n\ttypecode.itemsize = self->itemsize;\n\ttypecode.fortran = PyArray_ISFORTRAN(self);\n\t\n\tarr = PyArray_FromAny(val, &typecode, \n\t\t\t 0, 0, FORCECAST);\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->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 copyswap(selfit->dataptr, NULL, swap, \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->itemsize);\n copyswap(selfit->dataptr, NULL, swap, self->itemsize);\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\t{\"base\",\n\t (getter)array_base_get,\n\t NULL,\n\t \"base object\"},\n {\"dtype\", \n\t (getter)array_type_get, \n\t (setter)array_type_set,\n\t \"get array type class\"},\n\t{\"dtypechar\",\n\t (getter)array_typechar_get,\n\t NULL,\n\t \"get array type character code\"},\n\t{\"dtypestr\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"get array type string\"},\n {\"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_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\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\n\nstatic char Arraytype__doc__[] = \n \"A array object represents a multidimensional, homogeneous array\\n\"\n\t\" of basic values. Arrays are sequence, mapping and numeric\\n\"\n\t\" objects. More information is available in the scipy module and\\n\"\n\t\" by looking at the methods and attributes of an array.\";\n\nstatic PyTypeObject PyBigArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"scipy.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 \n offsetof(PyArrayObject, weakreflist), /*tp_weaklistoffset */\n\n /* Iterator support (use standard) */\n\n (getiterfunc)0, \t\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 0,\t /* tp_alloc */ \n (newfunc)array_new,\t\t /* tp_new */\n 0,\t \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 \"scipy.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) \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 if (PySequence_Length(s) == 0) \n\t\treturn 1;\n\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);\n\t\tif(d >= 0) d++;\n\t}\n Py_DECREF(e);\n return d;\n}\n\nstatic int\ndiscover_itemsize(PyObject *s, int nd, int *itemsize) \n{\n\tint n, r, i;\n\tPyObject *e;\n\t\n\tn = PyObject_Length(s);\n\n\tif ((nd == 0) || PyString_Check(s) ||\t\t\\\n\t PyUnicode_Check(s) || PyBuffer_Check(s)) {\n\t\tif PyUnicode_Check(s) \n\t\t\t*itemsize = MAX(*itemsize, sizeof(Py_UNICODE)*n);\n\t\telse\n\t\t\t*itemsize = MAX(*itemsize, n);\n\t\treturn 0;\n\t}\n\tfor (i=0; i n_lower) n_lower = d[1];\n }\n d[1] = n_lower;\n\t\n return 0;\n}\n\nstatic void\n_array_small_type(int chktype, int mintype, int chksize, int minsize, \n\t\t PyArray_Typecode *outtype)\n{\n\touttype->type_num = MAX(chktype, mintype);\n\tif (PyTypeNum_ISFLEXIBLE(outtype->type_num) &&\t\\\n\t PyTypeNum_ISFLEXIBLE(mintype)) {\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 == PyArray_STRING) {\n\t\t\touttype->itemsize = MAX(chksize, 2*minsize);\n\t\t}\n\t\telse {\n\t\t\touttype->itemsize = MAX(chksize, minsize);\n\t\t}\n\t}\n\telse {\n\t\touttype->itemsize = chksize;\n\t}\n\treturn;\t\n}\n\nstatic void\n_array_find_type(PyObject *op, PyArray_Typecode *minitype, \n\t\t PyArray_Typecode *outtype, int max)\n{\n int l;\n PyObject *ip;\n\tint chktype=0;\n\tint chksize=0;\n\tint mintype, minsize;\n\n\tif (minitype == NULL) {\n\t\tmintype = PyArray_BOOL;\n\t\tminsize = sizeof(Bool);\n\t}\n\telse {\n\t\tmintype = minitype->type_num;\n\t\tminsize = minitype->itemsize;\n\t}\n\n \n if (max < 0 || mintype == -1) goto deflt;\n\t\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_TYPE(op);\n\t\tchksize = PyArray_ITEMSIZE(op);\n\t\tgoto finish;\n\t}\n\t\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tPyArray_TypecodeFromScalar(op, outtype);\n\t\tchktype = outtype->type_num;\n\t\tchksize = outtype->itemsize;\n\t\tgoto finish;\n\t}\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_TYPE(ip);\n\t\t\tchksize = PyArray_ITEMSIZE(ip);\n\t\t\tgoto finish;\n\t\t}\n } \n\t\n\tif (PyObject_HasAttrString(op, \"__array_typestr__\")) {\n\t\tint swap=0, res;\n\t\tip = PyObject_GetAttrString(op, \"__array_typestr__\");\n\t\tif (ip && PyString_Check(ip)) {\n\t\t\tres = _array_typecode_fromstr(PyString_AS_STRING(ip), \n\t\t\t\t\t\t &swap, outtype); \n\t\t\tif (res >= 0) {\n\t\t\t\tPy_DECREF(ip);\n\t\t\t\tchktype = outtype->type_num;\n\t\t\t\tchksize = outtype->itemsize;\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t}\n\t\tPy_XDECREF(ip);\n\t}\n\n if (PyString_Check(op)) {\n\t\tchktype = PyArray_STRING;\n\t\tchksize = PyString_GET_SIZE(op);\n\t\tgoto finish;\n }\n\n\tif (PyUnicode_Check(op)) {\n\t\tchktype = PyArray_UNICODE;\n\t\tchksize = PyUnicode_GET_DATA_SIZE(op);\n\t\tgoto finish;\n\t}\n\n\tif (PyBuffer_Check(op)) {\n\t\tchktype = PyArray_VOID;\n\t\tchksize = op->ob_type->tp_as_sequence->sq_length(op);\n\t\tPyErr_Clear();\n\t\tgoto finish;\n\t}\n\n\tif (PyInstance_Check(op)) goto deflt;\n\t\n if (PySequence_Check(op)) {\n\t\tPyArray_Typecode newtype;\n\t\tnewtype.type_num = mintype;\n\t\tnewtype.itemsize = minsize;\n\t\tnewtype.fortran = 0;\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 && mintype == 0) {\n\t\t\tnewtype.type_num = PyArray_INTP;\n\t\t\tnewtype.itemsize = sizeof(intp);\n\t\t}\n while (--l >= 0) {\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\t_array_find_type(ip, &newtype, outtype, max-1);\n\t\t\t_array_small_type(outtype->type_num,\n\t\t\t\t\t newtype.type_num, \n\t\t\t\t\t outtype->itemsize,\n\t\t\t\t\t newtype.itemsize,\n\t\t\t\t\t &newtype);\n Py_DECREF(ip);\n }\n\t\tchktype = newtype.type_num;\n\t\tchksize = newtype.itemsize;\n\t\tgoto finish;\n }\n\t\n\tif (PyBool_Check(op)) {\n\t\tchktype = PyArray_BOOL;\n\t\tchksize = sizeof(Bool);\n\t\tgoto finish;\t\t\n\t}\n else if (PyInt_Check(op)) {\n\t\tchktype = PyArray_LONG;\n\t\tchksize = sizeof(long);\n\t\tgoto finish;\n } else if (PyFloat_Check(op)) {\n\t\tchktype = PyArray_DOUBLE;\n\t\tchksize = sizeof(double);\n\t\tgoto finish;\n\t} else if (PyComplex_Check(op)) {\n\t\tchktype = PyArray_CDOUBLE;\n\t\tchksize = sizeof(cdouble);\n\t\tgoto finish;\n\t}\n\n deflt:\n\tchktype = PyArray_OBJECT;\n\tchksize = sizeof(void *);\n\n finish:\n\t_array_small_type(chktype, mintype, chksize, minsize, \n\t\t\t outtype);\n\treturn;\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\" */ \nstatic PyObject *\nArray_FromScalar(PyObject *op, PyArray_Typecode *typecode) \n{\n PyArrayObject *ret;\n\tint itemsize; \n\tint type;\n\t\n\titemsize = typecode->itemsize;\n\ttype = typecode->type_num;\n\n\tif (itemsize == 0 && PyTypeNum_ISFLEXIBLE(type)) {\n\t\titemsize = PyObject_Length(op);\n\t}\n\n\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, 0, NULL, type,\n\t\t\t\t\t NULL, NULL, itemsize, 0, NULL);\n\n\tif (ret == NULL) return NULL;\n\n ret->descr->setitem(op, ret->data, ret);\n\t\n if (PyErr_Occurred()) {\n array_dealloc(ret);\n return NULL;\n } else {\n return (PyObject *)ret;\n }\n}\n\n\nstatic PyObject *\nArray_FromSequence(PyObject *s, PyArray_Typecode *typecode, int min_depth, \n\t\t int max_depth)\n{\n PyArrayObject *r;\n int nd;\n\tintp *d;\n\tint stop_at_string;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->itemsize;\n\t\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 if (!((nd=discover_depth(s, MAX_DIMS+1, stop_at_string)) > 0)) {\n\t\tif (nd==0)\n\t\t\treturn Array_FromScalar(s, typecode);\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid input sequence\");\n return NULL;\n }\n\t\n if ((max_depth && nd > max_depth) ||\t\\\n\t (min_depth && nd < min_depth)) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid number of dimensions\");\n return NULL;\n }\n\t\n\tif ((d=PyDimMem_NEW(nd)) == NULL) {\n\t\treturn PyErr_NoMemory();\n }\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) {\n\t\tPyDimMem_FREE(d);\n\t\treturn NULL;\n\t}\n\tif (itemsize == 0 && PyTypeNum_ISFLEXIBLE(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) {\n\t\t\tPyDimMem_FREE(d);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n r=(PyArrayObject*)PyArray_New(&PyArray_Type, nd, d, \n\t\t\t\t type, NULL, NULL,\n\t\t\t\t itemsize, \n\t\t\t\t typecode->fortran, NULL);\n\n PyDimMem_FREE(d);\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\n\nstatic int \nPyArray_ValidType(int type) \n{\n\tPyArray_Descr *descr;\n\t\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr==NULL) return 0;\n\treturn 1;\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->itemsize;\n\tint nels = PyArray_BUFSIZE;\n\tint el;\n\tint inswap, outswap=0;\n\tint obuf=!PyArray_ISCARRAY(out);\n\tint oelsize = out->itemsize;\n\tPyArray_VectorUnaryFunc *castfunc;\n PyArray_CopySwapFunc *in_csn;\n PyArray_CopySwapFunc *out_csn;\n\tint retval = -1;\n\n\tcastfunc = in->descr->cast[out->descr->type_num];\n in_csn = in->descr->copyswap;\n out_csn = out->descr->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\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\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->itemsize * 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\n/* For backward compatibility */\n\nstatic PyObject *\nPyArray_Cast(PyArrayObject *mp, int type_num) \n{\n\tPyArray_Typecode type;\n\tPyArray_Descr *descr;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\ttype.itemsize = descr->elsize;\n\ttype.type_num = descr->type_num;\n\ttype.fortran = 0;\n\t\n\treturn PyArray_CastToType(mp, &type);\n}\n\nstatic PyObject * \nPyArray_CastToType(PyArrayObject *mp, PyArray_Typecode *at) \n{\n\tPyObject *out;\n\tint ret;\n\n\tif ((mp->descr->type_num == at->type_num) && \\\n\t (at->itemsize==0 || mp->itemsize == at->itemsize) &&\n\t PyArray_ISBEHAVED_RO(mp)) {\n\t\tPy_INCREF(mp);\n\t\treturn (PyObject *)mp;\n\t}\n\t\t\n\tif (at->itemsize == 0) {\n\t\tif (mp->descr->type_num == PyArray_STRING &&\t\\\n\t\t at->type_num == PyArray_UNICODE)\n\t\t\tat->itemsize = mp->itemsize*sizeof(Py_UNICODE);\n\t\tif (mp->descr->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING) \n\t\t\tat->itemsize = mp->itemsize/sizeof(Py_UNICODE);\n\t\tif (at->type_num == PyArray_VOID)\n\t\t\tat->itemsize = mp->itemsize;\n\t}\n\n\tout = PyArray_New(mp->ob_type, mp->nd, \n\t\t\t mp->dimensions, \n\t\t\t at->type_num,\n\t\t\t NULL, NULL, at->itemsize, \n\t\t\t at->fortran, (PyObject *)mp);\n\tif (out == NULL) return NULL;\n\tret = PyArray_CastTo((PyArrayObject *)out, mp);\n\tif (ret != -1) return out;\n\n\tPy_DECREF(out);\n\treturn NULL;\n\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\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\tsimple = ((PyArray_ISCARRAY(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY(mp) && PyArray_ISFARRAY(out)));\n\t\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->itemsize * outsize;\n\t\tintp ncopies = outsize / mpsize;\n\n\t\twhile(ncopies--) {\n\t\t\tinptr = mp->data;\n\t\t\tmp->descr->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\nstatic PyObject *\narray_fromarray(PyArrayObject *arr, PyArray_Typecode *typecode, int flags) \n{\n\t\n\tPyArrayObject *ret=NULL;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->itemsize;\n\tint copy = 0;\n\tint arrflags;\n\tPyArray_Typecode oldtype;\n\tchar *msg = \"cannot copy back to a read-only array\";\n PyTypeObject *subtype;\n\n\toldtype.type_num = PyArray_TYPE(arr);\n\toldtype.itemsize = PyArray_ITEMSIZE(arr);\n\toldtype.fortran = 0;\n\n subtype = arr->ob_type;\n\n\tif (type == PyArray_NOTYPE) type = arr->descr->type_num;\n\tif (itemsize == 0) itemsize = arr->itemsize;\n\ttypecode->type_num = type;\n\ttypecode->itemsize = itemsize;\n\n\t/* Don't copy if sizes are compatible */\n\tif (PyArray_EquivalentTypes(&oldtype, typecode)) {\n\t\tarrflags = arr->flags;\n\n\t\tcopy = (flags & ENSURECOPY) || \\\n\t\t\t((flags & CONTIGUOUS) && (!(arrflags & CONTIGUOUS))) \\\n\t\t\t|| (PyArray_ITEMSIZE(arr) != itemsize) || \\\n\t\t\t((flags & ALIGNED) && (!(arrflags & ALIGNED))) || \\\n\t\t\t((flags & NOTSWAPPED) && (!(arrflags & NOTSWAPPED))) \\\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 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_New(subtype, \n\t\t\t\t\t arr->nd, \n\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t type,\n\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t itemsize,\n\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t (PyObject *)arr);\n\t\t\tif (PyArray_CopyInto(ret, arr) == -1) 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 ret = (PyArrayObject *) \\\n PyArray_New(&PyArray_Type,\n arr->nd,\n arr->dimensions,\n arr->descr->type_num,\n arr->strides,\n arr->data,\n arr->itemsize,\n arr->flags,NULL);\n if (ret == NULL) return NULL;\n ret->base = (PyObject *)arr;\n ret->flags &= ~UPDATEIFCOPY;\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_CanCastSafely(PyArray_TYPE(arr), type)) {\n if ((flags & UPDATEIFCOPY) && \\\n (!PyArray_ISWRITEABLE(arr))) {\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_New(subtype, arr->nd,\n arr->dimensions, typecode->type_num,\n NULL, NULL, typecode->itemsize,\n typecode->fortran, \n (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\nstatic int\n_array_typecode_fromstr(char *str, int *swap, PyArray_Typecode *type)\n{\n int type_num;\n char typechar;\n int size;\n unsigned long number = 1;\n char *s;\n char msg[] = \"unsupported typestring\";\n \n s = (char *)&number; /* s[0] == 0 implies big-endian */\n\n *swap = 0;\n\n if (str[0] == '<' || str[0] == '>') {\n\tif ((str[0] == '<') && (s[0] == 0)) *swap = 1;\n\telse if ((str[0] == '>') && (s[0] != 0)) *swap = 1;\n }\n str += 1;\n \n#define _MY_FAIL {\t\t\t\t \\\n\t PyErr_SetString(PyExc_ValueError, msg); \\\n\t return -1;\t\t\t \\\n }\t\t\n\n typechar = str[0];\n size = atoi(str + 1);\n switch (typechar) {\n case 'b':\n\t if (size == sizeof(Bool))\n\t\t type_num = PyArray_BOOL;\t \n\t else _MY_FAIL \n\t break;\t\t \n case 'u':\n if (size == sizeof(uintp))\n type_num = PyArray_UINTP;\n\t else if (size == sizeof(char))\n\t\t type_num = PyArray_UBYTE;\n\t else if (size == sizeof(short)) \n\t\t type_num = PyArray_USHORT;\n\t else if (size == sizeof(int)) \n\t\t type_num = PyArray_UINT;\n\t else if (size == sizeof(ulong)) \n\t\t type_num = PyArray_ULONG;\n\t else if (size == sizeof(ulonglong))\n\t\t type_num = PyArray_ULONGLONG;\n\t else _MY_FAIL\n\t break;\t\t \n case 'i':\n if (size == sizeof(intp))\n type_num = PyArray_INTP;\n\t else if (size == sizeof(char)) \n\t\t type_num = PyArray_BYTE;\n\t else if (size == sizeof(short)) \n\t\t type_num = PyArray_SHORT;\n\t else if (size == sizeof(int))\n\t\t type_num = PyArray_INT;\n\t else if (size == sizeof(long)) \n\t\t type_num = PyArray_LONG;\n\t else if (size == sizeof(longlong))\n\t\t type_num = PyArray_LONGLONG;\n\t else _MY_FAIL\n\t break;\t\t \n case 'f':\n\t if (size == sizeof(float))\n\t\t type_num = PyArray_FLOAT;\n\t else if (size == sizeof(double))\n\t\t type_num = PyArray_DOUBLE;\n\t else if (size == sizeof(longdouble))\n\t\t type_num = PyArray_LONGDOUBLE;\n\t else _MY_FAIL\n\t break;\n case 'c':\n\t if (size == sizeof(float)*2)\n\t\t type_num = PyArray_CFLOAT;\n\t else if (size == sizeof(double)*2)\n\t\t type_num = PyArray_CDOUBLE;\n\t else if (size == sizeof(longdouble)*2)\n\t\t type_num = PyArray_CLONGDOUBLE;\n\t else _MY_FAIL\n\t break;\n case 'O':\n\t if (size == sizeof(PyObject *))\n\t\t type_num = PyArray_OBJECT;\n\t else _MY_FAIL\n\t break;\n case 'S':\n\t type_num = PyArray_STRING;\n\t break;\n case 'U':\n\t type_num = PyArray_UNICODE;\n\t size *= sizeof(Py_UNICODE);\n\t break;\t \n case 'V':\n\t type_num = PyArray_VOID;\n\t break;\n default:\n\t _MY_FAIL\n }\n\n#undef _MY_FAIL\n\n type->type_num = type_num;\n type->itemsize = size;\n type->fortran = 0;\n return 0;\n}\n\nstatic PyObject *\narray_frominterface(PyObject *input, PyArray_Typecode *intype, int flags)\n{\n\tPyObject *attr=NULL, *item=NULL, *r;\n\tPyArrayObject *ret=NULL;\n\tPyArray_Typecode type;\n\tchar *data;\n\tint buffer_len;\n\tint res, i, n;\n\tintp dims[MAX_DIMS], strides[MAX_DIMS];\n\tint swap;\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\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) {Py_XDECREF(attr); return NULL;}\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t}\n\telse {\n\t\tif (PyTuple_GET_SIZE(attr) != 2) {\n\t\t\tPy_DECREF(attr);\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\treturn NULL;\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\tPy_DECREF(attr);\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\treturn NULL;\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 = PyObject_GetAttrString(input, \"__array_typestr__\");\n\tif (!PyString_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_typestr__ must be a string\");\n\t\tPy_DECREF(attr);\n\t\treturn NULL;\t\n\t}\n\tres = _array_typecode_fromstr(PyString_AS_STRING(attr), &swap, &type);\n\tPy_DECREF(attr);\n\tif (res < 0) return NULL;\n \n\tattr = PyObject_GetAttrString(input, \"__array_shape__\");\n\tif (!PyTuple_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_shape__ must be a tuple\");\n\t\tPy_DECREF(attr);\n\t\treturn NULL;\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\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\treturn NULL;\n\t\t}\n\t\tfor (i=0; istrides, strides, n*sizeof(intp));\n\t}\n\n\tif (swap) {\n\t\tPyObject *tmp;\n tmp = PyArray_Byteswap(ret, TRUE);\n\t\tPy_DECREF(tmp);\n\t}\n\n\tPyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n\tr = array_fromarray(ret, intype, flags);\n\tPy_DECREF(ret);\n\treturn r;\n}\n\nstatic PyObject *\narray_fromattr(PyObject *op, PyArray_Typecode *typecode, int flags) \n{\n PyObject *new, *r;\n\t \n if (typecode->type_num == PyArray_NOTYPE) {\n new = PyObject_CallMethod(op, \"__array__\", NULL);\n } else {\n\t\tPyArray_Descr *descr;\n\t\tPyObject *obj;\n\n\t\tdescr = PyArray_DescrFromType(typecode->type_num);\n\t\tif (PyTypeNum_ISFLEXIBLE(typecode->type_num)) {\n\t\t\tobj = PyString_FromFormat(\"%c%d\", descr->type,\n\t\t\t\t\t\t typecode->itemsize);\n\t\t}\n\t\telse { \n\t\t\tobj = (PyObject *)(descr->typeobj); Py_INCREF(obj);\n\t\t}\n\t\tnew = PyObject_CallMethod(op, \"__array__\", \"N\", obj);\n }\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 r = array_fromarray((PyArrayObject *)new, typecode, flags);\n Py_DECREF(new);\n return r;\n} \n\n\nstatic PyObject *\narray_fromobject(PyObject *op, PyArray_Typecode *typecode, int min_depth, \n\t\t int max_depth, int flags) \n{\n /* This is the main code to make a NumPy array from a Python\n Object. It is called from lot's of different places which\n is why there are so many checks. The comments try to\n explain some of the checks. */\n\n\tint type = typecode->type_num;\n PyObject *r=NULL;\n\n\t/* Is input object already an array? */\n\t/* This is where the flags are used */\n if (PyArray_Check(op)) \n\t\tr = array_fromarray((PyArrayObject *)op, typecode, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, typecode);\n\t}\n\telse if (PyObject_HasAttrString(op, \"__array__\")) {\n\t\t/* Code that returns the object to convert for a non\n\t\t multiarray input object from the __array__ attribute of the\n\t\t object. */\n r = array_fromattr(op, typecode, flags);\n\t}\n\telse if (PyObject_HasAttrString(op, \"__array_shape__\") &&\n\t\t PyObject_HasAttrString(op, \"__array_typestr__\")) {\n\t\tr = array_frominterface(op, typecode, flags);\n\t}\n\telse {\n\t\tif (type == PyArray_NOTYPE) {\n\t\t\t_array_find_type(op, NULL, typecode, MAX_DIMS);\n\t\t}\n\t\tif (PySequence_Check(op))\n\t\t\tr = Array_FromSequence(op, typecode, \n\t\t\t\t\t min_depth, max_depth);\n\t\telse\n\t\t\tr = Array_FromScalar(op, typecode);\n\t}\n\n /* If we didn't succed return NULL */\n if (r == NULL) return NULL;\n\t\n\t/* Be sure we succeed here */\n\t\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"internal error: array_fromobject \"\\\n\t\t\t\t\"not producing an array\");\n\t\tPy_DECREF(r);\n return NULL;\n }\n\n if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {\n Py_DECREF(r);\n PyErr_SetString(PyExc_ValueError, \n \"object of too small depth for desired array\");\n return NULL;\n }\n if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {\n Py_DECREF(r);\n PyErr_SetString(PyExc_ValueError, \n \"object too deep for desired array\");\n return NULL;\n }\n return r;\n}\n\nstatic void\nPyArray_ArrayType(PyObject *op, PyArray_Typecode *intype, \n\t\t PyArray_Typecode *outtype) \n{\n\t_array_find_type(op, intype, outtype, MAX_DIMS);\n\treturn;\n}\n\nstatic int \nPyArray_ObjectType(PyObject *op, int minimum_type) \n{\n\tPyArray_Typecode intype, outtype;\n\tintype.type_num = minimum_type;\n\t_array_find_type(op, &intype, &outtype, MAX_DIMS);\n\treturn outtype.type_num;\n}\n\n\n\n/* flags is any of \n CONTIGUOUS, \n FORTRAN, (or set typecode->fortran=1)\n ALIGNED, \n NOTSWAPPED, \n WRITEABLE, \n ENSURECOPY, \n UPDATEIFCOPY,\n FORCECAST,\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, NOTSWAPPED, and WRITEABLE\n and therefore it is redundant to include those as well. \n\n BEHAVED_FLAGS == ALIGNED | NOTSWAPPED | WRITEABLE\n BEHAVED_FLAGS_RO == ALIGNED | NOTSWAPPED\n CARRAY_FLAGS = CONTIGUOUS | BEHAVED_FLAGS\n FARRAY_FLAGS = FORTRAN | BEHAVED_FLAGS\n \n By default, the returned array will be a copy of the object, \n (C) contiguous in memory, aligned, notswapped, and writeable.\n \n So CONTIGUOUS | ENSURECOPY passed in means that the returned\n array does not have to be CONTIGUOUS or a COPY but should be\n ALIGNED, NOTSWAPPED and WRITEABLE. \n\n typecode->fortran can be set to request a\n fortran-contiguous array. Fortran arrays are always behaved (aligned, \n notswapped, and writeable) and not (C) CONTIGUOUS. Note that either\n FORTRAN in the flag or typecode->fortran = 1 is enough to request\n a FORTRAN-style array. \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\nstatic PyObject *\nPyArray_FromAny(PyObject *op, PyArray_Typecode *typecode, int min_depth, \n\t\tint max_depth, int requires) \n{\n \tPyArray_Typecode mine = {PyArray_NOTYPE, 0, 0};\n\tPyArray_Typecode *type;\n\t\n\tif (typecode == NULL) type = &mine;\n\telse type = typecode;\n\t\t\n\tif (requires & ENSURECOPY) {\n\t\trequires |= DEFAULT_FLAGS;\n\t}\n\t/* Ensure that type->fortran and flags & FORTRAN are the\n\t same */\n\tif (requires & FORTRAN) typecode->fortran = 1;\n\tif (type->fortran == 1) {\n\t\trequires |= FARRAY_FLAGS;\n\t\tif (min_depth > 2) requires &= ~CONTIGUOUS;\n\t}\n\n\t/* make sure itemsize is not 0 unless warranted. */\n\tif ((type->itemsize == 0) && (type->type_num != PyArray_NOTYPE)) {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(type->type_num);\n\t\tif (descr != NULL) type->itemsize = descr->elsize;\n\t\telse return NULL;\n\t}\n\t\n\treturn array_fromobject(op, type, min_depth, max_depth, \n\t\t\t\trequires);\t\n}\n\n/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0, 0) */\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\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);\n Py_DECREF(op);\n return new;\n}\n\n/* These are all compressed into a single API */\n/* Deprecated calls -- Use PyArray_FromAny */\n\nstatic PyObject *\nPyArray_FromObject(PyObject *op, int type, int min_depth, int max_depth) \n{\n\tPyArray_Typecode typecode = {0, 0, 0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth,\n\t\t\t max_depth, BEHAVED_FLAGS | ENSUREARRAY);\n}\n\nstatic PyObject *\nPyArray_ContiguousFromObject(PyObject *op, int type, int min_depth, \n\t\t\t int max_depth) \n{\n\tPyArray_Typecode typecode = {0, 0, 0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth,\n\t\t\t max_depth, DEFAULT_FLAGS | ENSUREARRAY);\n}\n\nstatic PyObject *\nPyArray_CopyFromObject(PyObject *op, int type, int min_depth, \n\t\t int max_depth) \n{\n\tPyArray_Typecode typecode = {0, 0, 0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth, max_depth,\n\t\t\t ENSURECOPY | ENSUREARRAY);\n}\n\n/* End of deprecated */\n\nstatic PyObject *\nPyArray_ContiguousFromAny(PyObject *op, int type, int min_depth, \n\t\t\t int max_depth)\n{\n\tPyArray_Typecode typecode = {0,0,0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth,\n\t\t\t max_depth, DEFAULT_FLAGS);\n}\t\n\nstatic int \nPyArray_CanCastSafely(int fromtype, int totype) \n{\n\tPyArray_Descr *from, *to;\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\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 (to->elsize > from->elsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (to->elsize >= from->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (from->elsize < 8)\n return (to->elsize > from->elsize);\n else\n return (to->elsize >= from->elsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (from->elsize < 8)\n return ((to->elsize >> 1) > from->elsize);\n else\n return ((to->elsize >> 1) >= from->elsize);\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 (to->elsize > from->elsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (to->elsize >= from->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (from->elsize < 8)\n return (to->elsize > from->elsize);\n else\n return (to->elsize >= from->elsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (from->elsize < 8)\n return ((to->elsize >> 1) > from->elsize);\n else\n return ((to->elsize >> 1) >= from->elsize);\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 ((to->elsize >> 1) >= from->elsize);\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\nstatic Bool\nPyArray_CanCastTo(PyArray_Typecode *from, PyArray_Typecode *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->itemsize <= to->itemsize);\n\t\t\t}\n\t\t\telse if (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->itemsize * sizeof(Py_UNICODE)\\\n\t\t\t\t <= to->itemsize);\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->itemsize <= to->itemsize);\n\t\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 scipy's arraymap ****/\n/* and Python's array iterator ***/\n \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 = PyObject_GC_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 PyObject_GC_Track(it);\n return (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 PyObject_GC_UnTrack(it);\n Py_XDECREF(it->ao);\n PyObject_GC_Del(it);\n }\n\nstatic int\narrayiter_traverse(PyArrayIterObject *it, visitproc visit, void *arg)\n{\n if (it->ao != NULL)\n return visit((PyObject *)(it->ao), arg);\n return 0;\n}\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->itemsize;\n\tr = PyArray_New(self->ao->ob_type, 1, &count, \n\t\t\tself->ao->descr->type_num, NULL, NULL,\n\t\t\titemsize, 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->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->itemsize;\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\tr = PyArray_New(self->ao->ob_type, ind->nd, ind->dimensions,\n\t\t\tself->ao->descr->type_num, NULL, \n\t\t\tNULL, self->ao->itemsize, \n\t\t\t0, (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)->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\tint i;\n\tPyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tint 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\t\t\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\n\t/* Tuples 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\tr = PyArray_New(self->ao->ob_type, 1, &ii, \n\t\t\t\t\tself->ao->descr->type_num, NULL, \n\t\t\t\t\tNULL, self->ao->itemsize, 0,\n\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 */\n\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->itemsize;\n\t\tr = PyArray_New(self->ao->ob_type, 1, &n_steps, \n\t\t\t\tself->ao->descr->type_num, NULL, NULL,\n\t\t\t\tsize, 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)->copyswap;\n\t\twhile(n_steps--) {\n copyswap(dptr, self->dataptr, swap, size);\n\t\t\tfor(i=0; i< step_size; i++) \n\t\t\t\tPyArray_ITER_NEXT(self);\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\tif (PyArray_IsScalar(ind, Integer) || PyList_Check(ind)) {\n\t\tobj = PyArray_FromAny(ind, &indtype, 0, 0, FORCECAST);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tr = iter_subscript_Bool(self, (PyArrayObject *)obj);\n\t\t} \n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, &indtype, 0, 0, \n\t\t\t\t\t FORCECAST | BEHAVED_FLAGS);\n\t\t\tif (new==NULL) goto fail;\n\t\t\tobj = new;\n\t\t\tr = iter_subscript_int(self, (PyArrayObject *)obj);\n\t\t}\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\t\"unsupported iterator index\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPy_DECREF(obj);\n\t\treturn r;\n\t}\n\n\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\n fail:\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->itemsize;\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->copyswap;\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(self->dataptr, val->dataptr, swap,\n itemsize);\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t\tPyArray_ITER_NEXT(val);\n\t\tif (val->index==val->size) \n\t\t\tPyArray_ITER_RESET(val);\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_Typecode typecode;\n\tintp num;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\titemsize = typecode.itemsize = self->ao->itemsize;\n\ttypecode.type_num = self->ao->descr->type_num;\n copyswap = self->ao->descr->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\n\nstatic int\niter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val) \n{\n\tint i;\n\tPyObject *arrval=NULL;\n\tPyArrayIterObject *val_it=NULL;\n\tPyArray_Typecode type;\n\tPyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tint swap;\n\tint itemsize;\n\tint start, step_size;\n\tintp n_steps;\n\tPyObject *obj;\n PyArray_CopySwapFunc *copyswap;\n\t\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\ti = iter_ass_subscript(self, ind, val);\n\t\tPy_DECREF(ind);\n\t\treturn i;\n\t}\n\t\n\ttype.type_num = self->ao->descr->type_num;\n\titemsize = type.itemsize = self->ao->itemsize;\n\t\n\tarrval = PyArray_FromAny(val, &type, 0, 0, 0);\n\tif (arrval==NULL) return -1;\n\tval_it = (PyArrayIterObject *)PyArray_IterNew(arrval);\n\tif (val_it==NULL) goto fail;\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\n copyswap = PyArray_DESCR(arrval)->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\tgoto succeed;\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 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 copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, itemsize);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\tgoto succeed;\n\t\t}\n\t\twhile(n_steps--) {\n copyswap(self->dataptr, val_it->dataptr,\n swap, itemsize);\n\t\t\tfor(i=0; i < step_size; i++) \n\t\t\t\tPyArray_ITER_NEXT(self);\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\tgoto succeed;\n\t} \n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tif (PyArray_IsScalar(ind, Integer))\n\t\tobj = PyArray_FromScalar(ind, &indtype);\n\telse if (PyList_Check(ind)) {\n\t\tobj = PyArray_FromAny(ind, &indtype, 0, 0, FORCECAST);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tif (iter_ass_sub_Bool(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto fail;\n\t\t} \n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, &indtype, 0, 0, \n\t\t\t\t\t FORCECAST | BEHAVED_FLAGS);\n\t\t\tif (new==NULL) goto fail;\n\t\t\tPy_DECREF(obj);\n\t\t\tobj = new;\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 fail;\n\t\t}\n\t\telse goto fail;\n\t\tPy_DECREF(obj);\n\t\tgoto succeed;\n\t}\n\n\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\tgoto fail;\n\n succeed:\n\tPy_DECREF(val_it);\n\tPy_DECREF(arrval);\n\treturn 0;\n\n fail:\n\tPy_XDECREF(val_it);\n\tPy_XDECREF(arrval);\n\treturn -1;\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 if (PyArray_ISCONTIGUOUS(it->ao)) {\n r = PyArray_New(it->ao->ob_type, 1, &size, \n\t\t\t\tit->ao->descr->type_num,\n NULL, it->ao->data, it->ao->itemsize, \n\t\t\t\tit->ao->flags,\n (PyObject *)it->ao); \n\t\tif (r==NULL) return NULL;\n }\n else {\n r = PyArray_New(it->ao->ob_type, 1, &size, \n\t\t\t\tit->ao->descr->type_num,\n NULL, NULL, it->ao->itemsize, 0, \n (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\n\nstatic PyTypeObject PyArrayIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"scipy.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 | Py_TPFLAGS_HAVE_GC,/* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)arrayiter_traverse,\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)arrayiter_next,\t\t/* tp_iternext */\n iter_methods,\t\t\t\t/* tp_methods */\n};\n\n/** END of Array Iterator **/\n\n\n\n/*********************** Subscript Array Iterator *************************\n * *\n * This object handles subscript behavior for array objects. *\n * It is an iterator object with a next method *\n * It abstracts the n-dimensional mapping behavior to make the looping *\n * code more understandable (maybe) *\n * and so that indexing can be set up ahead of time *\n */ \n\n/* This checks the args for any fancy indexing objects */\n\n#define SOBJ_NOTFANCY 0 \n#define SOBJ_ISFANCY 1\n#define SOBJ_BADARRAY 2\n#define SOBJ_TOOMANY 3\n#define SOBJ_LISTTUP 4\n\nstatic int\nfancy_indexing_check(PyObject *args)\n{\n\tint i, n;\n\tPyObject *obj;\n\tint retval = SOBJ_NOTFANCY;\n\n\tif (PyTuple_Check(args)) {\n\t\tn = PyTuple_GET_SIZE(args);\n\t\tif (n >= MAX_DIMS) return SOBJ_TOOMANY;\n\t\tfor (i=0; i=MAX_DIMS) return SOBJ_ISFANCY;\n\t\tfor (i=0; i SOBJ_ISFANCY) return retval;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* convert an indexing object to an INTP indexing array iterator\n if possible -- otherwise, it is a Slice or Ellipsis object\n and has to be interpreted on bind to a particular \n array so leave it NULL for now.\n */\nstatic int\n_convert_obj(PyObject *obj, PyArrayIterObject **iter)\n{\n\tPyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tPyObject *arr;\n\n\tif (PySlice_Check(obj) || (obj == Py_Ellipsis))\n\t\t*iter = NULL;\n\telse {\n\t\tarr = PyArray_FromAny(obj, &indtype, 0, 0, FORCECAST);\n\t\tif (arr == NULL) return -1;\n\t\t*iter = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (*iter == NULL) return -1;\n\t}\n\treturn 0;\n}\n\n/* Adjust dimensionality and strides for index object iterators \n --- i.e. broadcast\n */\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->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->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=NULL, *obj=NULL;\n\tint i, j, n, curraxis, ellipexp, noellip;\n\tPyArrayIterObject *it;\n\tintp dimsize;\n\tintp *indptr;\n\n\t/* Remove old binding if any */\n\tPy_XDECREF(mit->ait);\n\tmit->ait = NULL;\n\n\tPy_XDECREF(mit->subspace);\n\tmit->subspace = NULL;\n\t\n\tsubnd = arr->nd - mit->numiter;\n\tif (subnd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"too many indices for array\");\n\t\treturn;\n\t}\n\n\tmit->ait = (PyArrayIterObject *)PyArray_IterNew((PyObject *)arr);\n\tif (mit->ait == NULL) return;\n\n\t/* If this is just a view, then do nothing more */\n\t/* views are handled by just adjusting the strides\n\t and dimensions of the object.\n\t*/\n\t \n\tif (mit->view) return;\n\n\t/* no subspace iteration needed. 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\tif (mit->subspace == NULL) goto fail;\n\tPy_DECREF(sub);\n\n\t/* Expand dimensions of result */\n\tn = mit->subspace->ao->nd;\n\tfor (i=0; idimensions[mit->nd+i] = mit->subspace->ao->dimensions[i];\n\tmit->nd += n;\n\n\t/* Now, we still need to interpret the ellipsis and slice objects \n\t to determine which axes the indexing arrays are referring to\n\t*/\n\tn = PyTuple_GET_SIZE(mit->indexobj);\n\n\t/* The number of dimensions an ellipsis takes up */\n\tellipexp = arr->nd - n + 1;\n\t/* Now fill in iteraxes -- remember indexing arrays have been \n converted to 0's in mit->indexobj */\n\tcurraxis = 0;\n\tj = 0;\n\tnoellip = 1; /* Only expand the first ellipsis */\n\tmemset(mit->bscoord, 0, sizeof(intp)*arr->nd);\n\tfor (i=0; iindexobj, i);\n\t\tif (PyInt_Check(obj) || PyLong_Check(obj)) \n\t\t\tmit->iteraxes[j++] = curraxis++;\n\t\telse if (noellip && obj == Py_Ellipsis) {\n\t\t\tcurraxis += ellipexp;\n\t\t\tnoellip = 0;\n\t\t}\n\t\telse {\n\t\t\tint start=0;\n\t\t\tint 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}\t\t\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn;\n\n fail:\n\tPy_XDECREF(sub);\n\tPy_XDECREF(mit->ait);\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_Typecode typecode = {PyArray_BOOL, 0, 0};\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\tba = (PyArrayObject *)PyArray_FromAny(myBool, &typecode, 0, 0, \n\t\t\t\t\t CARRAY_FLAGS);\n\tif (ba == NULL) return -1;\n\tnd = ba->nd;\n\tfor (j=0; jdata;\n\tcount = 0;\n\n\t/* pre-determine how many nonzero entries there are */\n\tfor (i=0; iao->data;\n\t\tcoords[j] = 0;\n\t\tdims_m1[j] = ba->dimensions[j]-1;\n\t}\n\n\tptr = (Bool *)ba->data;\n\n\tif (count == 0) return nd;\n\n\t/* Loop through the Boolean array and copy coordinates\n\t for non-zero entries */\n\tfor (i=0; i=0; j--) {\n\t\t\tif (coords[j] < dims_m1[j]) {\n\t\t\t\tcoords[j]++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcoords[j] = 0;\n\t\t\t}\n\t\t}\n\t}\n\treturn nd;\n\n fail:\n\tfor (j=0; jiters[i] = NULL;\n \tmit->view = 0;\n \tmit->index = 0;\n \tmit->ait = NULL;\n \tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tfancy = fancy_indexing_check(indexobj);\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\tif (fancy == SOBJ_NOTFANCY) { /* bail out */\n\t\tmit->view = 1;\n\t\tgoto ret;\n\t}\n\n\tif (fancy == SOBJ_BADARRAY) {\n\t\tPyErr_SetString(PyExc_TypeError,\t\t\t\\\n\t\t\t\t\"arrays used as indexes must be of \" \\\n\t\t\t\t\"integer type\");\n\t\tgoto fail;\n\t}\n\tif (fancy == SOBJ_TOOMANY) {\n\t\tPyErr_SetString(PyExc_TypeError, \"too many indicies\");\n\t\tgoto fail;\n\t}\n\n\tif (fancy == SOBJ_LISTTUP) {\n\t\tPyObject *newobj;\n\t\tnewobj = PySequence_Tuple(indexobj);\n\t\tif (newobj == NULL) goto fail;\n\t\tPy_DECREF(indexobj);\n\t\tindexobj = newobj;\n\t\tmit->indexobj = indexobj;\n\t}\n\n#undef SOBJ_NOTFANCY \n#undef SOBJ_ISFANCY \n#undef SOBJ_BADARRAY \n#undef SOBJ_TOOMANY \n#undef SOBJ_LISTTUP \n\n\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\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 (PyList_Check(indexobj) || PyArray_Check(indexobj)) {\n\t\tmit->numiter = 1;\n\t\tarr = PyArray_FromAny(indexobj, &indtype, 0, 0, FORCECAST);\n\t\tif (arr == NULL) goto fail;\n\t\tmit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (mit->iters[0] == NULL) 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(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\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = new;\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\t/* Store the number of iterators actually converted */\n\t\t/* These will be mapped to actual axes at bind time */\n\t\tif (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)\n\t\t\tgoto fail;\n\t}\n\n ret:\n PyObject_GC_Track(mit);\n return (PyObject *)mit;\n \n fail:\n\tPy_XDECREF(arr);\n\tPy_XDECREF(mit->indexobj);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n PyObject_GC_Del(mit);\n\treturn NULL;\n}\n\n\n/* return unbound mapiter object */\n\nstatic PyObject *\narraymapiter_new(PyTypeObject *type, PyObject *args, PyObject *kwds) \n{\n\tPyObject *newtup, *res;\n\tint n;\n\n\tif (!PyTuple_Check(args)) {\n\t\tPyErr_BadInternalCall();\n\t\treturn NULL;\n\t}\n\n\tn = PyTuple_GET_SIZE(args);\n\t\n\tif (n < 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"must be initialized with >= 1 argument\");\n\t\treturn NULL;\n\t}\n\t\n\tif (n > 1) {\n\t\tnewtup = PyTuple_GetSlice(args, 0, n);\n\t\tif (newtup == NULL) return NULL;\n\t\tres = PyArray_MapIterNew(newtup);\n\t\tPy_DECREF(newtup);\n\t}\n\telse { /* n == 1 */\n\t\tnewtup = PyTuple_GET_ITEM(args, 0);\n\t\tres = PyArray_MapIterNew(newtup);\n\t}\n\n\treturn res; \t\n}\n\n\n/* Returns a 0-dim array holding the element desired */\n/*\nstatic PyObject *\narraymapiter_next(PyArrayMapIterObject *mit)\n{\n\tPyObject *ret;\n\tif (mit->ait == NULL) return NULL;\n\tif (mit->view) return NULL;\n\tif (mit->index < mit->size) {\n\t\tret = PyArray_ToScalar(mit->dataptr, mit->ait->ao);\n\t\tPyArray_MapIterNext(mit);\n\t\treturn ret;\n\t}\n return NULL;\n}\n*/\n\nstatic void\narraymapiter_dealloc(PyArrayMapIterObject *mit)\n{\n\tint i;\n PyObject_GC_UnTrack(mit);\n Py_XDECREF(mit->ait);\n\tPy_XDECREF(mit->indexobj);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n PyObject_GC_Del(mit);\n}\n\nstatic int\narraymapiter_traverse(PyArrayMapIterObject *mit, visitproc visit, void *arg)\n{\n\tint ret, i;\n if (mit->ait != NULL)\n if ((ret = visit((PyObject *)(mit->ait), arg)) != 0) \n\t\t\treturn ret;\t\n\n\tif (mit->iters != NULL) \n\t\tfor (i=0; inumiter; i++) \n\t\t\tif (mit->iters[i] != NULL) \n\t\t\t\tif ((ret=visit((PyObject *)mit->iters[i], \n\t\t\t\t\t arg)) != 0)\n\t\t\t\t\treturn ret;\n\n\tif (mit->indexobj != NULL)\n\t\tif ((ret = visit(mit->indexobj, arg)) != 0) return ret;\n\t\n return 0;\n}\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 MapIterNew must be \n that does not work. 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 char doc_mapiter_bind[] = \"obj.bind(a)\\n Bind an array to the \"\\\n\t\"mapiter object\";\n\nstatic PyObject *\nmapiter_bind(PyArrayMapIterObject *mit, PyObject *args)\n{\n\tPyArrayObject *arr;\n\n if (!PyArg_ParseTuple(args, \"O!\", &PyArray_Type, &arr)) return NULL;\n\n \tPyArray_MapIterBind(mit, arr);\n\n\tif (mit->ait == NULL) return NULL;\n\t\n \tPyArray_MapIterReset(mit);\n\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyMethodDef mapiter_methods[] = {\n\t{\"bind\", (PyCFunction)mapiter_bind, 1, doc_mapiter_bind},\n {NULL,\t\tNULL}\t\t\n};\n*/\n\n\nstatic PyTypeObject PyArrayMapIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"scipy.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 | Py_TPFLAGS_HAVE_GC,/* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)arraymapiter_traverse,\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, /*arraymapiter_next,*/\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 (newfunc)arraymapiter_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n\n};\n\n/** END of Subscript Iterator **/\n\n\n\n", "source_code_before": " /*\n Provide multidimensional arrays as a basic object type in python. \n\nBased on Original Numeric implementation\nCopyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\nwith contributions from many Numeric Python developers 1995-2004 *\n\nHeavily modified in 2005 with inspiration from Numarray \n\nby\n\nTravis Oliphant\nAssistant Professor at\nBrigham Young University \n\nmaintainer email: oliphant.travis@ieee.org\n\nNumarray design (which provided guidance) by \nSpace Science Telescope Institute \n (J. Todd Miller, Perry Greenfield, Rick White)\n\n*/\n\n/* $Id: arrayobject.c,v 1.59 2005/09/14 00:14:00 teoliphant Exp $ */\n\n/*\n#include \"Python.h\"\n#include \"structmember.h\"\n\n#define _MULTIARRAYMODULE\n#include \"Numeric3/arrayobject.h\"\n*/\n\n/* Helper functions */\n\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\n\nstatic intp\nPyArray_PyIntAsIntp(PyObject *o)\n{\n\tlonglong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr=NULL;\n\tPyArray_Typecode typecode = {PyArray_INTP, 0, 0};\n\tintp ret;\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\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\tarr = PyArray_CastToType((PyArrayObject *)o, &typecode);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tarr = PyArray_FromScalar(o, &typecode);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((intp *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\t\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONGLONG != SIZEOF_PY_INTPTR_T)\n\tif ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C intp\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (intp) long_value;\n}\n\n\nstatic PyObject *array_int(PyArrayObject *v);\n\nstatic int\nPyArray_PyIntAsInt(PyObject *o)\n{\n\tlong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr=NULL;\n\tPyArray_Typecode typecode = {PyArray_INT, 0, 0};\n\tint ret;\n\t\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\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\tarr = PyArray_CastToType((PyArrayObject *)o, &typecode);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tarr = PyArray_FromScalar(o, &typecode);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((int *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONG != SIZEOF_INT)\n\tif ((long_value < INT_MIN) || (long_value > INT_MAX)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C int\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (int) long_value;\n}\n\n\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\nstatic char *\nPyArray_Zero(PyArrayObject *arr)\n{\n char *zeroval;\n char *buf;\n int buf_len;\n PyObject *obj, *ret;\n\n zeroval = PyDataMem_NEW(arr->itemsize);\n if (zeroval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n if (PyArray_ISOBJECT(arr)) {\n obj=PyInt_FromLong((long) 0);\n memcpy(zeroval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return zeroval;\n }\n ret = PyObject_GetAttrString((PyObject *)arr, \"_zero\");\n if (ret != NULL) {\n if (PyObject_AsReadBuffer(ret, (const void **)&buf, \n &buf_len) < 0) {\n PyErr_SetString(PyExc_ValueError, \n \"_zero not returning \" \\\n \"writeable buffer\");\n Py_DECREF(ret);\n return NULL;\n }\n memcpy(zeroval, buf, buf_len);\n Py_DECREF(ret);\n }\n if (PyErr_Occurred()) PyErr_Clear();\n memset(zeroval, 0, arr->itemsize);\n return zeroval;\n}\n\nstatic char *\nPyArray_One(PyArrayObject *arr)\n{\n char *oneval;\n char *buf;\n int buf_len, ret2;\n PyObject *obj, *ret;\n\n oneval = PyDataMem_NEW(arr->itemsize);\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 ret = PyObject_GetAttrString((PyObject *)arr, \"_one\");\n if (ret != NULL) {\n if (PyObject_AsReadBuffer(ret, (const void **)&buf, \n &buf_len) < 0) {\n PyErr_SetString(PyExc_ValueError, \n \"_one not returning \" \\\n \"writeable buffer\");\n Py_DECREF(ret);\n PyDataMem_FREE(oneval);\n return NULL;\n }\n memcpy(oneval, buf, buf_len);\n Py_DECREF(ret);\n }\n if (PyErr_Occurred()) PyErr_Clear();\n\n ret2 = arr->descr->setitem(obj, oneval, arr);\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->itemsize;\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 *)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 { free(new_data); return NULL; }\n}\n\n/* end Helper functions */\n\n\nstatic PyObject *PyArray_New(PyTypeObject *, int nd, intp *, \n int, intp *, char *, 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. */\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/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\n\nstatic char *\nindex2ptr(PyArrayObject *mp, int i) \n{\n\tif (i==0 && (mp->nd == 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\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\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->copyswap;\n\tcopyswapn = dest->descr->copyswapn;\n\n elsize = dest->itemsize;\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->itemsize;\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\tPyArray_Typecode typecode;\n\n\n\ttypecode.type_num = dest->descr->type_num;\n\ttypecode.itemsize = dest->itemsize;\n\ttypecode.fortran = PyArray_ISFORTRAN(dest);\n\t\t\t\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n\t\t\t\t\t &typecode, 0,\n\t\t\t\t\t dest->nd, 0);\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\nstatic PyObject *\nPyArray_FromDimsAndDataAndDescr(int nd, int *d, \n PyArray_Descr *descr,\n char *data) {\n\tPyObject *ret;\n\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\n\tintp newd[MAX_DIMS];\n\t\n\tfor (i=0; itype_num, NULL, data, descr->elsize, \n\t\t\t CARRAY_FLAGS, NULL);\n#else\n\tret = PyArray_New(&PyArray_Type, nd, (intp *)d, \n descr->type_num, NULL, data, descr->elsize, \n\t\t\t CARRAY_FLAGS, NULL);\n#endif\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_FromDimsAndData(int nd, int *d, int type, char *data) \n{\n\tPyObject *ret;\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\t\n\tintp newd[MAX_DIMS];\n\n\tfor (i=0; iob_type, m1->nd, \n\t\t\t\t\t m1->dimensions,\n\t\t\t\t\t m1->descr->type_num,\n\t\t\t\t\t NULL, NULL, m1->itemsize,\n\t\t\t\t\t 0, (PyObject *)m1);\n\t\n if (PyArray_CopyInto(ret, m1) == -1) return NULL;\n\t\n return (PyObject *)ret;\n}\n\n\nstatic PyObject *array_item(PyArrayObject *, int);\n\nstatic PyObject *\nPyArray_Scalar(char *data, int type_num, int itemsize, int swap)\n{\n PyArray_Descr *descr;\n\tPyTypeObject *type;\n\tPyObject *obj;\t\n\tchar *destptr;\n PyArray_CopySwapFunc *copyswap;\n\n descr = PyArray_DescrFromType(type_num);\n if (descr == NULL) return NULL;\n type = descr->typeobj;\n copyswap = descr->copyswap;\n\tif (type_num == PyArray_STRING) \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_ISFLEXIBLE(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 {\n\t\t\tdestptr = PyDataMem_NEW(itemsize);\n\t\t\tif (destptr == NULL) {\n\t\t\t\tPyObject_Del(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tif (type_num == PyArray_UNICODE) {\n\t\t\t\tPyUnicode_AS_UNICODE(obj) = \\\n\t\t\t\t\t(Py_UNICODE *)destptr;\n\t\t\t\t((PyUnicodeObject*)obj)->length = itemsize / \\\n\t\t\t\t\tsizeof(Py_UNICODE);\n\t\t\t\t((PyUnicodeObject*)obj)->hash = -1;\n\t\t\t}\n\t\t\telse {\n\t\t\t\t((PyVoidScalarObject *)obj)->obval = destptr;\n\t\t\t\t((PyVoidScalarObject *)obj)->ob_size = itemsize;\n\t\t\t}\n\t\t}\n\t}\n\telse {\n\t\tdestptr = &(((PyScalarObject*)obj)->obval);\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*/\nstatic PyObject *\nPyArray_ToScalar(char *data, PyArrayObject *arr)\n{\n\tint type_num = arr->descr->type_num;\n\tint itemsize = arr->itemsize;\n int swap = !(PyArray_ISNOTSWAPPED(arr));\n\n\treturn PyArray_Scalar(data, type_num, itemsize, swap);\n}\n\n\n/* Return Python scalar if 0-d array object is encountered */\n\nstatic PyObject *\nPyArray_Return(PyArrayObject *mp) \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((PyObject *)mp) && 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*/\nstatic int \nPyArray_RegisterDataType(PyTypeObject *type)\n{\n\tPyArray_Descr *descr;\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 = malloc(sizeof(PyArray_Descr));\n\tmemcpy(descr, PyArray_DescrFromType(PyArray_VOID), \n\t sizeof(PyArray_Descr));\n\ttypenum = PyArray_USERDEF + PyArray_NUMUSERTYPES;\n\tdescr->type_num = typenum;\n\tdescr->typeobj = 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 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 frees the copy of the Descr_table already there.\n places a pointer to the new one into the slot.\n*/\nstatic int\nPyArray_RegisterDescrForType(int typenum, PyArray_Descr *descr)\n{\n\tPyArray_Descr *old;\n\tint i;\n\n\tif (!PyTypeNum_ISUSERDEF(typenum)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"data type not registered\");\n\t\treturn -1;\n\t}\n\told = userdescrs[typenum-PyArray_USERDEF];\n\tdescr->typeobj = old->typeobj;\n\tdescr->type_num = typenum;\n\n#define _NULL_CHECK(member) \\\n\tif (descr->member == NULL) descr->member = old->member\n\n\tfor (i=0; imember == 0) descr->member = old->member\n\n\t_ZERO_CHECK(kind);\n\t_ZERO_CHECK(type);\n\t_ZERO_CHECK(elsize);\n\t_ZERO_CHECK(alignment);\n#undef _ZERO_CHECK\n\n\tfree(old);\n\tuserdescrs[typenum-PyArray_USERDEF] = descr;\n\treturn 0;\n}\n\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 n3 = strlen((const char *)sep);\n if (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 \"\\\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->itemsize,\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->itemsize,\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 = strlen((const char *)format);\n while(it->index < it->size) {\n obj = self->descr->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\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->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\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 if (PyArray_TYPE(self) == PyArray_OBJECT) {\n PyErr_SetString(PyExc_ValueError, \"a string for the data\"\\\n\t\t\t\t\"in an object array is not appropriate\");\n return NULL;\n }\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->itemsize;\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 != NULL)) {\n\t\t/* Free internal references if an Object array */\n\t\tPyArray_XDECREF(self);\n\n PyDataMem_FREE(self->data);\n }\n\t\n if (self->dimensions != NULL) {\n PyDimMem_FREE(self->dimensions); \n\t}\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\n\nstatic PyObject *\narray_item(PyArrayObject *self, int i) \n{\n char *item;\n PyArrayObject *r;\n\n\n\tif(self->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n if ((item = index2ptr(self, i)) == NULL) return NULL;\n\n\tr = (PyArrayObject *)PyArray_New(self->ob_type, \n\t\t\t\t\t self->nd-1, self->dimensions+1, \n\t\t\t\t\t self->descr->type_num, \n\t\t\t\t\t self->strides+1, item, \n\t\t\t\t\t self->itemsize, self->flags,\n\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_item(self, i));\n}\n\n\nstatic int \narray_ass_item(PyArrayObject *self, int 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\n if (i < 0) i = i+self->dimensions[0];\n\n if (self->nd > 1) {\n if((tmp = (PyArrayObject *)array_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->setitem(v, item, self) == -1) return -1;\n return 0;\n}\n\n/* -------------------------------------------------------------- */\nstatic int\nslice_coerce_index(PyObject *o, int *v)\n{\n\t*v = PyArray_PyIntAsInt(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, int length,\n int *start, int *stop, int *step,\n intp *slicelength)\n{\n\tint 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 int\nparse_subindex(PyObject *op, int *step_size, intp *n_steps, int max)\n{\n\tint 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\tint 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_PyIntAsInt(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, start, offset, n_add, n_pseudo;\n int step_size;\n\tintp n_steps;\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, *tup;\n\tint n1, n2, n3, val;\n\tint i;\n\n\ttup = PyTuple_New(mit->nd);\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\tPyTuple_SET_ITEM(tup, i++, PyInt_FromLong((long)val++));\n\tval = 0;\n\twhile(val < n1)\n\t\tPyTuple_SET_ITEM(tup, i++, PyInt_FromLong((long)val++));\n\tval = n1+n2;\n\twhile(val < n3)\n\t\tPyTuple_SET_ITEM(tup, i++, PyInt_FromLong((long)val++));\n\n\tnew = PyArray_Transpose(*ret, tup);\n\tPy_DECREF(tup);\n\tPy_DECREF(*ret);\n\t*ret = (PyArrayObject *)new;\n}\n\n\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\tret = (PyArrayObject *)\\\n\t\tPyArray_New(temp->ob_type, mit->nd, mit->dimensions, \n\t\t\t temp->descr->type_num, NULL, NULL, \n\t\t\t temp->itemsize, \n\t\t\t PyArray_ISFORTRAN(temp),\n\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\treturn NULL;\n\tindex = it->size;\n\tswap = ((temp->flags & NOTSWAPPED) != (ret->flags & NOTSWAPPED));\n copyswap = ret->descr->copyswap;\n\tPyArray_MapIterReset(mit);\n\twhile (index--) {\n copyswap(it->dataptr, mit->dataptr, swap, ret->itemsize);\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\tPyArray_Typecode typecode = {0, 0, 0};\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Unbound Map Iterator */\n\tif (mit->ait == NULL) return -1;\n\n\ttypecode.type_num = mit->ait->ao->descr->type_num;\n\ttypecode.itemsize = mit->ait->ao->itemsize;\n\n\tarr = PyArray_FromAny(op, &typecode, \n\t\t\t 0, 0, FORCECAST);\n\tif (arr == NULL) return -1;\n\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, (PyArrayObject **)&arr);\n\t\t}\n\t}\n\t\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) \n\t\treturn -1;\n\n\tindex = mit->size;\n\tswap = ((mit->ait->ao->flags & NOTSWAPPED) != \\\n\t\t(PyArray_FLAGS(arr) & NOTSWAPPED));\n\n copyswap = PyArray_DESCR(arr)->copyswap;\n\tPyArray_MapIterReset(mit);\n /* Need to decref OBJECT arrays */\n if (PyTypeNum_ISOBJECT(typecode.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 copyswap(mit->dataptr, NULL, swap, \n sizeof(PyObject *));\n PyArray_MapIterNext(mit);\n PyArray_ITER_NEXT(it);\n if (it->index == it->size)\n PyArray_ITER_RESET(it);\n }\n return 0;\n }\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\treturn 0;\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 0-dimensional arrays */\n\nstatic PyObject *\narray_subscript(PyArrayObject *self, PyObject *op) \n{\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n\tintp offset;\n int nd, i;\n PyArrayObject *other;\n\tPyArrayMapIterObject *mit;\n\n if (PyArray_IsScalar(op, Integer) || PyInt_Check(op) || \\\n PyLong_Check(op)) {\n intp value;\n value = PyArray_PyIntAsIntp(op);\n if (PyErr_Occurred())\n PyErr_Clear();\n else if (value >= 0) {\n if (value <= MAX_INT)\n return array_item(self, (int) value);\n }\n else if (value < 0) {\n if (value >= -MAX_INT) {\n if (self->nd > 0) value += self->dimensions[0];\n return array_item(self, (int) value);\n }\n }\n }\n\n\tif (PyArrayMapIter_Check(op)) {\n\t\tmit = (PyArrayMapIterObject *)op;\n\t\t/* bind to current array */\n\t\tPyArray_MapIterBind(mit, self);\n\t\t\n\t\t/* If the mapiterator was created with standard indexing\n\t\t behavior, fall through to view-based code */\n\t\tif (!mit->view) return PyArray_GetMap(mit);\n\t\top = mit->indexobj;\n\t}\n\telse { /* wrap arguments into a mapiter object */\n\t\tmit = (PyArrayMapIterObject *)PyArray_MapIterNew(op);\n\t\tif (mit == NULL) return NULL;\n\t\tif (!mit->view) { /* fancy indexing */\n\t\t\tPyArray_MapIterBind(mit, self);\n\t\t\tother = (PyArrayObject *)PyArray_GetMap(mit);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn (PyObject *)other;\n\t\t}\n\t\tPy_DECREF(mit);\n\t}\n\n\ti = PyArray_PyIntAsInt(op);\n\tif (!error_converting(i)) {\n\t\tif (i < 0 && self->nd > 0) i = i+self->dimensions[0];\n\t\treturn array_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\tif ((other = (PyArrayObject *)\t\t\t\t\t\\\n\t PyArray_New(self->ob_type, nd, dimensions, self->descr->type_num,\n\t\t\t strides, self->data+offset, \n\t\t\t self->itemsize, self->flags,\n\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 \narray_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op) \n{\n int ret, 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\n\tif (PyArrayMapIter_Check(index)) {\n\t\tmit = (PyArrayMapIterObject *)index;\n\t\t/* bind behavior to current array */\n\t\tPyArray_MapIterBind(mit, self);\n\t\t\t\n\t\t/* fall through if standard view-based map iterator */\n\t\tif (!mit->view) return PyArray_SetMap(mit, op);\n\t\tindex = mit->indexobj;\n\t}\n\telse {\n\t\tmit = (PyArrayMapIterObject *)PyArray_MapIterNew(index);\n\t\tif (mit == NULL) return -1;\n\t\tif (!mit->view) {\n\t\t\tPyArray_MapIterBind(mit, self);\n\t\t\tret = PyArray_SetMap(mit, op);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn ret;\n\t\t}\n\t\tPy_DECREF((PyObject*)mit);\n\t}\n\n\ti = PyArray_PyIntAsInt(index);\n\tif (!error_converting(i)) {\n\t\treturn array_ass_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 ret = PyArray_CopyObject(tmp, op);\n Py_DECREF(tmp);\n\t\n return ret;\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 \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\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}\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}\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 PyObject *args, *ret;\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n args = Py_BuildValue(\"(OO)\", m1, m2);\n ret = PyObject_Call(op, args, NULL);\n Py_DECREF(args);\n return ret;\n}\n\nstatic PyObject *\nPyArray_GenericUnaryFunction(PyArrayObject *m1, PyObject *op) \n{\n PyObject *args, *ret;\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n args = Py_BuildValue(\"(O)\", m1);\n ret = PyObject_Call(op, args, NULL);\n Py_DECREF(args);\n return ret;\n}\n\nstatic PyObject *\nPyArray_GenericInplaceBinaryFunction(PyArrayObject *m1, \n\t\t\t\t PyObject *m2, PyObject *op) \n{\n PyObject *args, *ret;\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n args = Py_BuildValue(\"(OOO)\", m1, m2, m1);\n ret = PyObject_Call(op, args, NULL);\n Py_DECREF(args);\n return ret;\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_all_nonzero(PyArrayObject *mp) \n{\n\tintp index;\n\tPyArrayIterObject *it;\n\tBool anyTRUE = 0;\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->nonzero(it->dataptr, mp)) {\n\t\t\tanyTRUE = 1;\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 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->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->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->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->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->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_all_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 r = (PyArrayObject *)\\\n\t\tPyArray_New(self->ob_type, self->nd, self->dimensions, \n\t\t\t self->descr->type_num, self->strides, data,\n\t\t\t self->itemsize, 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 any(self == el) */\n\n return PyObject_RichCompareBool((PyObject *)self, el, Py_EQ);\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 *)realloc(*string, *max_n); }\n\t\n if (nd == 0) {\n\t\t\n if ((op = descr->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\tfree(string); return NULL; \n\t}\n\t\n\tif (PyArray_ISFLEXIBLE(self)) {\n\t\tchar buf[100];\n\t\tsnprintf(buf, sizeof(buf), \"%d\", self->itemsize);\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 free(string);\n return ret;\n}\n\nstatic PyObject *PyArray_StrFunction=NULL;\nstatic PyObject *PyArray_ReprFunction=NULL;\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\n\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) \n{\n PyObject *array_other, *result;\n\n switch (cmp_op) \n {\n case Py_LT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less);\n case Py_LE:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less_equal);\n case Py_EQ:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then return the integer\n\t\t\t object 0. This fixes code that used to\n\t\t\t allow equality comparisons between arrays\n\t\t\t and other objects which would give a result\n\t\t\t of 0\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n result = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.equal);\n /* If the comparison results in NULL, then the \n\t\t\t two array objects can not be compared together so \n\t\t\t return zero \n */\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n return result;\n case Py_NE:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then objects cannot be \n\t\t\t compared and cannot be equal, therefore, \n\t\t\t return True;\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n result = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.not_equal);\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n return result;\n case Py_GT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.greater);\n case Py_GE:\n return PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t other, \n\t\t\t\t\t \t n_ops.greater_equal);\n }\n return NULL;\n}\n\nstatic PyObject *\n_check_axis(PyArrayObject *arr, int *axis, int flags)\n{\n\tPyObject *temp;\n\tint n = arr->nd;\n\n\tif ((*axis >= MAX_DIMS) || (n==0)) {\n\t\ttemp = PyArray_Ravel(arr,0);\n\t\t*axis = 0;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_FromAny((PyObject *)arr, NULL, \n\t\t\t\t\t 0, 0, flags);\n\t\t\tif (temp == NULL) return NULL;\n\t\t}\n\t\telse {\n\t\t\tPy_INCREF(arr);\n\t\t\ttemp = (PyObject *)arr;\n\t\t}\n\t}\n\tif (*axis < 0) *axis += n;\n\tif ((*axis < 0) || (*axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", *axis);\n\t\tPy_DECREF(temp);\n\t\treturn NULL;\n\t}\n\treturn temp;\n}\n\n#include \"arraymethods.c\"\n\n/* Lifted from numarray */\nstatic PyObject *\nPyArray_IntTupleFromIntp(int len, intp *vals)\n{\n\tint i;\n PyObject *intTuple = PyTuple_New(len);\n if (!intTuple) goto fail;\n for(i=0; ind == 0) return 1;\n\tsd = ap->itemsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\n\t}\n\treturn 1;\n}\n\n\nstatic int \n_IsFortranContiguous(PyArrayObject *ap) \n{\n\tint sd;\n\tint i;\n\t\n\tif (ap->nd == 0) return 1;\n\tsd = ap->itemsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i=0; i< ap->nd; ++i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\n\t}\n\treturn 1;\n}\n\nstatic int\n_IsAligned(PyArrayObject *ap) \n{\n\tint i, alignment, aligned=1;\n\tintp ptr;\n\tint type = ap->descr->type_num;\n\n\tif ((type == PyArray_STRING) || (type == PyArray_VOID))\n\t\treturn 1;\n\n\talignment = ap->descr->alignment;\n\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\tPyBufferProcs *pb;\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\tpb = base->ob_type->tp_as_buffer;\n\tif (pb == NULL || pb->bf_getwritebuffer == NULL)\n\t\treturn FALSE;\n\t\n\treturn TRUE;\n}\n\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\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not \n walk outside of the memory implied by either numbytes or\n a single segment array of the provided dimensions and element size if\n numbytes is 0 */\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, \n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\t\n\tif (numbytes == 0) \n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\t\n\tfor (i=0; i numbytes) {\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\treturn TRUE;\n\t\n}\n\n\n/* This is the main array creation routine. */\n\n/* Flags argument has multiple related meanings \n depending on data and strides: \n\n If data is given, then flags is flags associated with data. \n If strides is not given, then a contiguous strides array will be created\n and the CONTIGUOUS bit will be set. If the flags argument \n has the FORTRAN bit set, then a FORTRAN-style strides array will be\n created (and of course the FORTRAN flag bit will be set). \n\n If data is not given but created here, then flags will be DEFAULT_FLAGS\n and a non-zero flags argument can be used to indicate a FORTRAN style\n array is desired. \n*/\n\nstatic intp\n_array_fill_strides(intp *strides, intp *dims, int nd, intp itemsize, \n\t\t int inflag, int *objflags) \n{\n\tint i;\n\t/* Only make Fortran strides if not contiguous as well */\n\tif ((inflag & FORTRAN) && !(inflag & CONTIGUOUS)) {\n\t\tfor (i=0; i 1) *objflags &= ~CONTIGUOUS;\n\t\telse *objflags |= CONTIGUOUS;\n\t}\n\telse {\n\t\tfor (i=nd-1;i>=0;i--) {\n\t\t\tstrides[i] = itemsize;\n\t\t\titemsize *= dims[i] ? dims[i] : 1;\n\t\t}\n\t\t*objflags |= CONTIGUOUS;\n\t\tif (nd > 1) *objflags &= ~FORTRAN;\n\t\telse *objflags |= FORTRAN;\n\t}\n\treturn itemsize;\n}\n\n\t\nstatic PyObject *\nPyArray_New(PyTypeObject *subtype, int nd, intp *dims, int type_num,\n intp *strides, char *data, int itemsize, int flags,\n\t PyObject *obj)\n{\n\tPyArrayObject *self;\n\tPyArray_Descr *descr;\n\tregister int i;\n\tintp sd, temp=-1;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\tif (descr == NULL) return NULL;\n\n\tif (nd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"number of dimensions must be >=0\");\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 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\treturn NULL;\n\t\t}\n\t}\n\t\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) return NULL;\t\n\tself->descr = descr;\n\tself->dimensions = 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\n\tif (PyTypeNum_ISFLEXIBLE(type_num)) {\n\t\tif (itemsize < 1) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"type must provide an itemsize\");\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn NULL;\n\t\t}\n\t\tself->itemsize = itemsize;\n\t\t/* Guarantee that these kind of arrays are never byteswapped\n\t\t unknowingly. \n\t\t*/\n\t\tif (type_num != PyArray_UNICODE)\n\t\t\tself->flags |= NOTSWAPPED;\n\t}\n\telse self->itemsize = descr->elsize; \n\t\t\n\tsd = self->itemsize;\n\t\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn PyErr_NoMemory();\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\tPyDimMem_FREE(self->dimensions);\n\t\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\t\treturn NULL;\n\t\t\t}\t\t\t\t\n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t}\n \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 (a.data) doesn't work\n\t\t as it should. */\n\n\t\tif (sd==0) sd = sizeof(intp);\n\n\t\tif ((data = PyDataMem_NEW(sd))==NULL) {\n\t\t\tPyDimMem_FREE(self->dimensions);\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn PyErr_NoMemory();\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\n\t\t/* It is bad to have unitialized OBJECT pointers */\n\t\t/* We shouldn't need to check for the OBJECT Letter\n\t\t but perhaps it's best. */\n\t\tif (type_num == PyArray_OBJECT || \\\n\t\t type_num == PyArray_OBJECTLTR) {\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\tself->nd = nd;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\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;\n\t\tif (temp==-1) { /* 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\tres = PyObject_CallMethod((PyObject *)self, \n\t\t\t\t\t \"__array_finalize__\",\n\t\t\t\t\t \"O\", obj);\n\t\tif (res == NULL) {\n\t\t\tPyDimMem_FREE(self->dimensions);\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn NULL;\n\t\t}\n\t\telse Py_DECREF(res);\n\t}\n\n\treturn (PyObject *)self;\n}\n\n\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\n newsize = PyArray_MultiplyList(new_dimensions, new_nd);\n\n if (newsize == 0) {\n PyErr_SetString(PyExc_ValueError, \n \"newsize is zero; cannot delete an array \"\\\n \"in this way\");\n return NULL;\n }\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 = (((PyObject *)self)->ob_refcnt);\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\n\t\t/* Reallocate space if needed */\n\t\tnew_data = PyDataMem_RENEW(self->data, \n\t\t\t\t\t newsize*(self->itemsize));\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->itemsize;\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->itemsize;\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 */\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; idataptr, fromptr, itemsize);\n\t\t\tPyArray_ITER_NEXT(iter);\n\t\t}\n\n\t\tPy_DECREF(iter);\n\t\tPy_DECREF(behaved);\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\", \"strides\", \n \"swap\", \"fortran\", NULL};\n\tint itemsize = 0;\n\tPyArray_Typecode typecode = {PyArray_NOTYPE, 0, 0};\n\tint type_num = PyArray_NOTYPE;\n PyArray_Dims dims = {NULL, 0};\n PyArray_Dims strides = {NULL, 0};\n PyArray_Chunk buffer;\n\tint fortran = 0;\n int swapped = 0;\n\tPyArrayObject *ret;\n\n\tbuffer.ptr = NULL; \n /* Usually called with shape and type\n but can also be called with buffer, strides, and swapped info\n */\n\n\t/* For now, let's just use this to create an empty, contiguous \n\t array of a specific type and shape. \n\t*/\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&O&ii\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &dims, \n PyArray_TypecodeConverter,\n\t\t\t\t\t &typecode, \n PyArray_BufferConverter,\n &buffer,\n &PyArray_IntpConverter, \n &strides,\n &swapped, &fortran)) \n\t\treturn NULL;\n\t\n if (typecode.type_num ==PyArray_NOTYPE) {\n\t\ttypecode.type_num = PyArray_DOUBLE;\n\t\ttypecode.itemsize = sizeof(double);\n\t}\n\ttype_num = typecode.type_num;\n\titemsize = typecode.itemsize;\n\n\n if (dims.ptr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"need to give a \"\\\n \"valid shape as the first argument\");\n goto fail;\n }\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)PyArray_New(subtype, (int)dims.len, \n dims.ptr, type_num,\n NULL, NULL, itemsize, \n fortran, NULL);\n \n if (ret == NULL) goto fail;\n if (type_num == PyArray_OBJECT) { /* place Py_None */\n PyArray_FillObjectArray(ret, Py_None);\n }\n }\n else { /* buffer given -- use it */\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = buffer.len / itemsize;\n }\n else if (buffer.len < itemsize* \\\n PyArray_MultiplyList(dims.ptr, dims.len)) {\n PyErr_SetString(PyExc_TypeError, \n \"buffer is too small for \" \\\n \"requested array\");\n goto fail;\n }\n if (strides.ptr != NULL) {\n\t\t\tif (strides.len != dims.len) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides, if given, must be \"\\\n\t\t\t\t\t\t\"the same length as shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CheckStrides(itemsize, strides.len, \n\t\t\t\t\t\t buffer.len,\n\t\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides is incompatible \"\\\n\t\t\t\t\t\t\"with shape of requested\"\\\n\t\t\t\t\t\t\"array and size of buffer\");\n\t\t\t\tgoto fail;\n\t\t\t}\n }\n if (type_num == PyArray_OBJECT) {\n PyErr_SetString(PyExc_TypeError, \"cannot construct \"\\\n \"an object array from buffer data\");\n goto fail;\n }\n /* get writeable and aligned */\n if (fortran) buffer.flags |= FORTRAN;\n if (!(swapped)) buffer.flags |= NOTSWAPPED;\n ret = (PyArrayObject *)PyArray_New(subtype, dims.len, \n dims.ptr, type_num,\n strides.ptr,\n (char *)buffer.ptr, \n itemsize, \n buffer.flags, NULL); \n if (ret == 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 PyArray_Return(ret);\n \n fail:\n if (dims.ptr) PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return NULL;\n}\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 static PyObject *module=NULL;\n\n if (module==NULL) {\n module = PyImport_ImportModule(\"scipy.base._internal\");\n if (module == NULL) return NULL;\n }\n return PyObject_CallMethod(module, \"flagsobj\", \"Oii\", \n self, self->flags, 0);\n}\n\n/*\nstatic int\narray_flags_set(PyArrayObject *self, PyObject *obj) \n{\n\tint flagback = self->flags;\n\n if (PyDict_Check(obj)) {\n PyObject *new;\n\t\tnew = PyDict_GetItemString(obj, \"ALIGNED\");\n\t\tif (new) {\n\t\t\tif (PyObject_Not(new)) self->flags &= ~ALIGNED;\n\t\t\telse if (_IsAligned(self)) self->flags |= ALIGNED;\n\t\t\telse {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"cannot set aligned flag of \" \\\n\t\t\t\t\t\t\"mis-aligned array to True\");\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t}\n new = PyDict_GetItemString(obj, \"UPDATEIFCOPY\");\n if (new) {\n if (PyObject_Not(new)) {\n self->flags &= ~UPDATEIFCOPY;\n Py_DECREF(self->base);\n self->base = NULL;\n }\n else {\n\t\t\t\tself->flags = flagback;\n PyErr_SetString(PyExc_ValueError, \n \"cannot set UPDATEIFCOPY \" \\\n \"flag to True\");\n return -1;\n }\n }\n new = PyDict_GetItemString(obj, \"WRITEABLE\");\n if (new) {\n\t\t\tif (PyObject_IsTrue(new)) {\n\t\t\t\tif (_IsWriteable(self)) {\n\t\t\t\t\tself->flags |= WRITEABLE;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tself->flags = flagback;\n\t\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\t\"cannot set \"\t\\\n\t\t\t\t\t\t\t\"WRITEABLE \"\t\\\n\t\t\t\t\t\t\t\"flag to True of \"\\\n\t\t\t\t\t\t\t\"this array \");\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n else\n self->flags &= ~WRITEABLE;\n }\n new = PyDict_GetItemString(obj, \"NOTSWAPPED\");\n if (new) {\n if (PyObject_IsTrue(new))\n self->flags |= NOTSWAPPED;\n else {\n self->flags &= ~NOTSWAPPED;\n\t\t\t}\n\t\t}\n return 0;\n }\n PyErr_SetString(PyExc_ValueError, \n \"object must be a dictionary\");\n return -1;\n}\n*/\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\tif (!PyTuple_Check(val)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"shape must be a tuple\");\n\t\treturn -1;\n\t}\n\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\n\t\n\tif (self->nd > 0) { /* Free old dimensions and strides */\n\t\tPyDimMem_FREE(self->dimensions);\n\t}\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;\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\treturn -1;\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->itemsize;\n\t\n\tif (!PyArray_CheckStrides(self->itemsize, self->nd, numbytes, \n\t\t\t\t self->dimensions, newstrides.ptr)) {\n\t\tPyErr_SetString(PyExc_ValueError, \"strides is not \"\\\n\t\t\t\t\"compatible with available memory\");\n\t\treturn -1;\n\t}\n\tmemcpy(self->strides, newstrides.ptr, sizeof(intp)*newstrides.len);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\treturn 0;\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->itemsize);\n}\n\nstatic PyObject *\narray_size_get(PyArrayObject *self)\n{\n\tlonglong size=PyArray_SIZE(self);\n\tif (size > MAX_INT || size < MIN_INT)\n\t\treturn PyLong_FromLongLong((longlong) size);\n\telse \n\t\treturn PyInt_FromLong((long) size);\n}\n\n\nstatic PyObject *\narray_typechar_get(PyArrayObject *self)\n{\n\tif PyArray_ISFLEXIBLE(self) \n\t\treturn PyString_FromFormat(\"%c%d\", (self->descr->type),\n\t\t\t\t\t self->itemsize);\n\telse \n\t\treturn PyString_FromStringAndSize(&(self->descr->type), 1);\n}\n\nstatic PyObject *\narray_typestr_get(PyArrayObject *self)\n{\n\tstatic char endians[] = \"<>\";\n\tchar endian;\n\tint which;\n\tunsigned long val = 1;\n\tchar *s;\n\tchar basic_=self->descr->kind;\n\n\ts = (char *)&val; /* s[0] == 0 implies big-endian */\n\twhich = (PyArray_ISNOTSWAPPED(self) ? 0 : 1);\n\tif (s[0] == 0) which = 1 - which;\n\tendian = endians[which]; \n\t\n\tif ((basic_==PyArray_VOIDLTR) || (basic_==PyArray_STRINGLTR) || \\\n\t (basic_==PyArray_OBJECTLTR) || (self->itemsize == 1))\n\t\treturn PyString_FromFormat(\"|%c%d\", basic_, self->itemsize);\n\telse\n\t\treturn PyString_FromFormat(\"%c%c%d\", endian, basic_,\n\t\t\t\t\t self->itemsize);\n}\n\nstatic PyObject *\narray_descr_get(PyArrayObject *self)\n{\n\tPyObject *res;\n\tPyObject *dobj;\n\n\t/* hand this off to the typeobject */\n\t/* or give default */\n\tif (PyArray_ISUSERDEF(self)) {\n\t\tres = PyObject_GetAttrString((PyObject *)self->descr->typeobj, \n\t\t\t\t\t \"__array_descr__\");\n\t\tif (res) return res;\n\t\tPyErr_Clear();\n\t}\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\n\nstatic PyObject *\narray_type_get(PyArrayObject *self)\n{\n\treturn PyArray_TypeObjectFromType(self->descr->type_num);\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*/\n\nstatic int\narray_type_set(PyArrayObject *self, PyObject *arg)\n{\n PyArray_Typecode newtype = {PyArray_NOTYPE, 0, 0};\n intp newdim;\n int index;\n char *msg = \"new type not compatible with array.\";\n\n if ((PyArray_TypecodeConverter(arg, &newtype) < 0) ||\n newtype.type_num == PyArray_NOTYPE) {\n PyErr_SetString(PyExc_TypeError, \"invalid type for array\");\n return -1;\n }\n if (!(PyArray_ISONESEGMENT(self) ||\t\t\\\n\t (newtype.itemsize != self->itemsize))) {\n PyErr_SetString(PyExc_ValueError, msg);\n return -1; \n }\n\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\n if (newtype.itemsize < self->itemsize) {\n /* if it is compatible increase the size of the dimension\n at end (or at the front for FORTRAN)\n */\n if (self->itemsize % newtype.itemsize != 0) {\n PyErr_SetString(PyExc_ValueError, msg);\n return -1;\n }\n newdim = self->itemsize / newtype.itemsize;\n\t\tself->dimensions[index] *= newdim;\n self->strides[index] = newtype.itemsize;\n\t}\n \n else if (newtype.itemsize > self->itemsize) {\n \n /* Determine if last (or first if FORTRAN) dimension\n is compatible */\n\n\t\tnewdim = self->dimensions[index] * self->itemsize;\n if ((newdim % newtype.itemsize) != 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, msg);\n return -1;\n }\n\t\t\n self->dimensions[index] = newdim / newtype.itemsize;\n self->strides[index] = newtype.itemsize;\n\t\t\n }\n\t\n \n /* fall through -- adjust type*/\n\n self->descr = PyArray_DescrFromType(newtype.type_num);\n self->itemsize = newtype.itemsize;\n PyArray_UpdateFlags(self, ALIGNED);\n return 0;\n\n}\n\n\n\nstatic PyObject *\narray_base_get(PyArrayObject *self)\n{\n\tif (self->base == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\telse {\n\t\tPy_INCREF(self->base);\n\t\treturn self->base;\n\t}\n}\n\n\nstatic PyObject *\narray_real_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *)ret;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n}\n\n\nstatic int\narray_real_set(PyArrayObject *self, PyObject *val)\n{\n\tPyArrayObject *ret;\n\tPyArrayObject *new;\n\tint rint;\n\n\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0);\n\tif (new == NULL) return -1;\n\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) 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\treturn rint;\n}\n\nstatic PyObject *\narray_imag_get(PyArrayObject *self)\n{\t\n\tPyArrayObject *ret;\n\tint itemsize;\n\tint typenum;\n PyArray_Typecode type;\n\t\n\ttype.type_num = self->descr->type_num;\n\ttype.itemsize = self->itemsize;\n\ttype.fortran = PyArray_ISFORTRAN(self);\n\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\titemsize = self->itemsize >> 1;\n\t\ttypenum = self->descr->type_num - PyArray_NUM_FLOATTYPE;\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 typenum,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data + itemsize,\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\tret = (PyArrayObject *)PyArray_Zeros(self->nd, \n\t\t\t\t\t\t self->dimensions, &type);\n\t\tret->flags &= ~WRITEABLE;\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic int\narray_imag_set(PyArrayObject *self, PyObject *val)\n{\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyArrayObject *ret;\n\t\tPyArrayObject *new;\n\t\tint rint;\n\n\t\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0); \n\t\tif (new == NULL) return -1;\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides+ \\\n\t\t\t\t\t\t (self->itemsize >> 1) ,\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) {\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_Typecode typecode;\n int swap;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode.type_num = self->descr->type_num;\n\ttypecode.itemsize = self->itemsize;\n\ttypecode.fortran = PyArray_ISFORTRAN(self);\n\t\n\tarr = PyArray_FromAny(val, &typecode, \n\t\t\t 0, 0, FORCECAST);\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->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 copyswap(selfit->dataptr, NULL, swap, \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->itemsize);\n copyswap(selfit->dataptr, NULL, swap, self->itemsize);\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\t{\"base\",\n\t (getter)array_base_get,\n\t NULL,\n\t \"base object\"},\n {\"dtype\", \n\t (getter)array_type_get, \n\t (setter)array_type_set,\n\t \"get array type class\"},\n\t{\"dtypechar\",\n\t (getter)array_typechar_get,\n\t NULL,\n\t \"get array type character code\"},\n\t{\"dtypestr\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"get array type string\"},\n {\"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_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\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\n\nstatic char Arraytype__doc__[] = \n \"A array object represents a multidimensional, homogeneous array\\n\"\n\t\" of basic values. Arrays are sequence, mapping and numeric\\n\"\n\t\" objects. More information is available in the scipy module and\\n\"\n\t\" by looking at the methods and attributes of an array.\";\n\nstatic PyTypeObject PyBigArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"scipy.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 \n offsetof(PyArrayObject, weakreflist), /*tp_weaklistoffset */\n\n /* Iterator support (use standard) */\n\n (getiterfunc)0, \t\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 0,\t /* tp_alloc */ \n (newfunc)array_new,\t\t /* tp_new */\n 0,\t \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 \"scipy.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) \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 if (PySequence_Length(s) == 0) \n\t\treturn 1;\n\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);\n\t\tif(d >= 0) d++;\n\t}\n Py_DECREF(e);\n return d;\n}\n\nstatic int\ndiscover_itemsize(PyObject *s, int nd, int *itemsize) \n{\n\tint n, r, i;\n\tPyObject *e;\n\t\n\tn = PyObject_Length(s);\n\n\tif ((nd == 0) || PyString_Check(s) ||\t\t\\\n\t PyUnicode_Check(s) || PyBuffer_Check(s)) {\n\t\tif PyUnicode_Check(s) \n\t\t\t*itemsize = MAX(*itemsize, sizeof(Py_UNICODE)*n);\n\t\telse\n\t\t\t*itemsize = MAX(*itemsize, n);\n\t\treturn 0;\n\t}\n\tfor (i=0; i n_lower) n_lower = d[1];\n }\n d[1] = n_lower;\n\t\n return 0;\n}\n\nstatic void\n_array_small_type(int chktype, int mintype, int chksize, int minsize, \n\t\t PyArray_Typecode *outtype)\n{\n\touttype->type_num = MAX(chktype, mintype);\n\tif (PyTypeNum_ISFLEXIBLE(outtype->type_num) &&\t\\\n\t PyTypeNum_ISFLEXIBLE(mintype)) {\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 == PyArray_STRING) {\n\t\t\touttype->itemsize = MAX(chksize, 2*minsize);\n\t\t}\n\t\telse {\n\t\t\touttype->itemsize = MAX(chksize, minsize);\n\t\t}\n\t}\n\telse {\n\t\touttype->itemsize = chksize;\n\t}\n\treturn;\t\n}\n\nstatic void\n_array_find_type(PyObject *op, PyArray_Typecode *minitype, \n\t\t PyArray_Typecode *outtype, int max)\n{\n int l;\n PyObject *ip;\n\tint chktype=0;\n\tint chksize=0;\n\tint mintype, minsize;\n\n\tif (minitype == NULL) {\n\t\tmintype = PyArray_BOOL;\n\t\tminsize = sizeof(Bool);\n\t}\n\telse {\n\t\tmintype = minitype->type_num;\n\t\tminsize = minitype->itemsize;\n\t}\n\n \n if (max < 0 || mintype == -1) goto deflt;\n\t\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_TYPE(op);\n\t\tchksize = PyArray_ITEMSIZE(op);\n\t\tgoto finish;\n\t}\n\t\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tPyArray_TypecodeFromScalar(op, outtype);\n\t\tchktype = outtype->type_num;\n\t\tchksize = outtype->itemsize;\n\t\tgoto finish;\n\t}\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_TYPE(ip);\n\t\t\tchksize = PyArray_ITEMSIZE(ip);\n\t\t\tgoto finish;\n\t\t}\n } \n\t\n\tif (PyObject_HasAttrString(op, \"__array_typestr__\")) {\n\t\tint swap=0, res;\n\t\tip = PyObject_GetAttrString(op, \"__array_typestr__\");\n\t\tif (ip && PyString_Check(ip)) {\n\t\t\tres = _array_typecode_fromstr(PyString_AS_STRING(ip), \n\t\t\t\t\t\t &swap, outtype); \n\t\t\tif (res >= 0) {\n\t\t\t\tPy_DECREF(ip);\n\t\t\t\tchktype = outtype->type_num;\n\t\t\t\tchksize = outtype->itemsize;\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t}\n\t\tPy_XDECREF(ip);\n\t}\n\n if (PyString_Check(op)) {\n\t\tchktype = PyArray_STRING;\n\t\tchksize = PyString_GET_SIZE(op);\n\t\tgoto finish;\n }\n\n\tif (PyUnicode_Check(op)) {\n\t\tchktype = PyArray_UNICODE;\n\t\tchksize = PyUnicode_GET_DATA_SIZE(op);\n\t\tgoto finish;\n\t}\n\n\tif (PyBuffer_Check(op)) {\n\t\tchktype = PyArray_VOID;\n\t\tchksize = op->ob_type->tp_as_sequence->sq_length(op);\n\t\tPyErr_Clear();\n\t\tgoto finish;\n\t}\n\n\tif (PyInstance_Check(op)) goto deflt;\n\t\n if (PySequence_Check(op)) {\n\t\tPyArray_Typecode newtype;\n\t\tnewtype.type_num = mintype;\n\t\tnewtype.itemsize = minsize;\n\t\tnewtype.fortran = 0;\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 && mintype == 0) {\n\t\t\tnewtype.type_num = PyArray_INTP;\n\t\t\tnewtype.itemsize = sizeof(intp);\n\t\t}\n while (--l >= 0) {\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\t_array_find_type(ip, &newtype, outtype, max-1);\n\t\t\t_array_small_type(outtype->type_num,\n\t\t\t\t\t newtype.type_num, \n\t\t\t\t\t outtype->itemsize,\n\t\t\t\t\t newtype.itemsize,\n\t\t\t\t\t &newtype);\n Py_DECREF(ip);\n }\n\t\tchktype = newtype.type_num;\n\t\tchksize = newtype.itemsize;\n\t\tgoto finish;\n }\n\t\n\tif (PyBool_Check(op)) {\n\t\tchktype = PyArray_BOOL;\n\t\tchksize = sizeof(Bool);\n\t\tgoto finish;\t\t\n\t}\n else if (PyInt_Check(op)) {\n\t\tchktype = PyArray_LONG;\n\t\tchksize = sizeof(long);\n\t\tgoto finish;\n } else if (PyFloat_Check(op)) {\n\t\tchktype = PyArray_DOUBLE;\n\t\tchksize = sizeof(double);\n\t\tgoto finish;\n\t} else if (PyComplex_Check(op)) {\n\t\tchktype = PyArray_CDOUBLE;\n\t\tchksize = sizeof(cdouble);\n\t\tgoto finish;\n\t}\n\n deflt:\n\tchktype = PyArray_OBJECT;\n\tchksize = sizeof(void *);\n\n finish:\n\t_array_small_type(chktype, mintype, chksize, minsize, \n\t\t\t outtype);\n\treturn;\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\" */ \nstatic PyObject *\nArray_FromScalar(PyObject *op, PyArray_Typecode *typecode) \n{\n PyArrayObject *ret;\n\tint itemsize; \n\tint type;\n\t\n\titemsize = typecode->itemsize;\n\ttype = typecode->type_num;\n\n\tif (itemsize == 0 && PyTypeNum_ISFLEXIBLE(type)) {\n\t\titemsize = PyObject_Length(op);\n\t}\n\n\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, 0, NULL, type,\n\t\t\t\t\t NULL, NULL, itemsize, 0, NULL);\n\n\tif (ret == NULL) return NULL;\n\n ret->descr->setitem(op, ret->data, ret);\n\t\n if (PyErr_Occurred()) {\n array_dealloc(ret);\n return NULL;\n } else {\n return (PyObject *)ret;\n }\n}\n\n\nstatic PyObject *\nArray_FromSequence(PyObject *s, PyArray_Typecode *typecode, int min_depth, \n\t\t int max_depth)\n{\n PyArrayObject *r;\n int nd;\n\tintp *d;\n\tint stop_at_string;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->itemsize;\n\t\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 if (!((nd=discover_depth(s, MAX_DIMS+1, stop_at_string)) > 0)) {\n\t\tif (nd==0)\n\t\t\treturn Array_FromScalar(s, typecode);\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid input sequence\");\n return NULL;\n }\n\t\n if ((max_depth && nd > max_depth) ||\t\\\n\t (min_depth && nd < min_depth)) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid number of dimensions\");\n return NULL;\n }\n\t\n\tif ((d=PyDimMem_NEW(nd)) == NULL) {\n\t\treturn PyErr_NoMemory();\n }\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) {\n\t\tPyDimMem_FREE(d);\n\t\treturn NULL;\n\t}\n\tif (itemsize == 0 && PyTypeNum_ISFLEXIBLE(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) {\n\t\t\tPyDimMem_FREE(d);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n r=(PyArrayObject*)PyArray_New(&PyArray_Type, nd, d, \n\t\t\t\t type, NULL, NULL,\n\t\t\t\t itemsize, \n\t\t\t\t typecode->fortran, NULL);\n\n PyDimMem_FREE(d);\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\n\nstatic int \nPyArray_ValidType(int type) \n{\n\tPyArray_Descr *descr;\n\t\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr==NULL) return 0;\n\treturn 1;\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->itemsize;\n\tint nels = PyArray_BUFSIZE;\n\tint el;\n\tint inswap, outswap=0;\n\tint obuf=!PyArray_ISCARRAY(out);\n\tint oelsize = out->itemsize;\n\tPyArray_VectorUnaryFunc *castfunc;\n PyArray_CopySwapFunc *in_csn;\n PyArray_CopySwapFunc *out_csn;\n\tint retval = -1;\n\n\tcastfunc = in->descr->cast[out->descr->type_num];\n in_csn = in->descr->copyswap;\n out_csn = out->descr->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\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\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->itemsize * 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\n/* For backward compatibility */\n\nstatic PyObject *\nPyArray_Cast(PyArrayObject *mp, int type_num) \n{\n\tPyArray_Typecode type;\n\tPyArray_Descr *descr;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\ttype.itemsize = descr->elsize;\n\ttype.type_num = descr->type_num;\n\ttype.fortran = 0;\n\t\n\treturn PyArray_CastToType(mp, &type);\n}\n\nstatic PyObject * \nPyArray_CastToType(PyArrayObject *mp, PyArray_Typecode *at) \n{\n\tPyObject *out;\n\tint ret;\n\n\tif ((mp->descr->type_num == at->type_num) && \\\n\t (at->itemsize==0 || mp->itemsize == at->itemsize) &&\n\t PyArray_ISBEHAVED_RO(mp)) {\n\t\tPy_INCREF(mp);\n\t\treturn (PyObject *)mp;\n\t}\n\t\t\n\tif (at->itemsize == 0) {\n\t\tif (mp->descr->type_num == PyArray_STRING &&\t\\\n\t\t at->type_num == PyArray_UNICODE)\n\t\t\tat->itemsize = mp->itemsize*sizeof(Py_UNICODE);\n\t\tif (mp->descr->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING) \n\t\t\tat->itemsize = mp->itemsize/sizeof(Py_UNICODE);\n\t\tif (at->type_num == PyArray_VOID)\n\t\t\tat->itemsize = mp->itemsize;\n\t}\n\n\tout = PyArray_New(mp->ob_type, mp->nd, \n\t\t\t mp->dimensions, \n\t\t\t at->type_num,\n\t\t\t NULL, NULL, at->itemsize, \n\t\t\t at->fortran, (PyObject *)mp);\n\tif (out == NULL) return NULL;\n\tret = PyArray_CastTo((PyArrayObject *)out, mp);\n\tif (ret != -1) return out;\n\n\tPy_DECREF(out);\n\treturn NULL;\n\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\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\tsimple = ((PyArray_ISCARRAY(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY(mp) && PyArray_ISFARRAY(out)));\n\t\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->itemsize * outsize;\n\t\tintp ncopies = outsize / mpsize;\n\n\t\twhile(ncopies--) {\n\t\t\tinptr = mp->data;\n\t\t\tmp->descr->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\nstatic PyObject *\narray_fromarray(PyArrayObject *arr, PyArray_Typecode *typecode, int flags) \n{\n\t\n\tPyArrayObject *ret=NULL;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->itemsize;\n\tint copy = 0;\n\tint arrflags;\n\tPyArray_Typecode oldtype;\n\tchar *msg = \"cannot copy back to a read-only array\";\n PyTypeObject *subtype;\n\n\toldtype.type_num = PyArray_TYPE(arr);\n\toldtype.itemsize = PyArray_ITEMSIZE(arr);\n\toldtype.fortran = 0;\n\n subtype = arr->ob_type;\n\n\tif (type == PyArray_NOTYPE) type = arr->descr->type_num;\n\tif (itemsize == 0) itemsize = arr->itemsize;\n\ttypecode->type_num = type;\n\ttypecode->itemsize = itemsize;\n\n\t/* Don't copy if sizes are compatible */\n\tif (PyArray_EquivalentTypes(&oldtype, typecode)) {\n\t\tarrflags = arr->flags;\n\n\t\tcopy = (flags & ENSURECOPY) || \\\n\t\t\t((flags & CONTIGUOUS) && (!(arrflags & CONTIGUOUS))) \\\n\t\t\t|| (PyArray_ITEMSIZE(arr) != itemsize) || \\\n\t\t\t((flags & ALIGNED) && (!(arrflags & ALIGNED))) || \\\n\t\t\t((flags & NOTSWAPPED) && (!(arrflags & NOTSWAPPED))) \\\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 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_New(subtype, \n\t\t\t\t\t arr->nd, \n\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t type,\n\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t itemsize,\n\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t (PyObject *)arr);\n\t\t\tif (PyArray_CopyInto(ret, arr) == -1) 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 ret = (PyArrayObject *) \\\n PyArray_New(&PyArray_Type,\n arr->nd,\n arr->dimensions,\n arr->descr->type_num,\n arr->strides,\n arr->data,\n arr->itemsize,\n arr->flags,NULL);\n if (ret == NULL) return NULL;\n ret->base = (PyObject *)arr;\n ret->flags &= ~UPDATEIFCOPY;\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_CanCastSafely(PyArray_TYPE(arr), type)) {\n if ((flags & UPDATEIFCOPY) && \\\n (!PyArray_ISWRITEABLE(arr))) {\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_New(subtype, arr->nd,\n arr->dimensions, typecode->type_num,\n NULL, NULL, typecode->itemsize,\n typecode->fortran, \n (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\nstatic int\n_array_typecode_fromstr(char *str, int *swap, PyArray_Typecode *type)\n{\n int type_num;\n char typechar;\n int size;\n unsigned long number = 1;\n char *s;\n char msg[] = \"unsupported typestring\";\n \n s = (char *)&number; /* s[0] == 0 implies big-endian */\n\n *swap = 0;\n\n if (str[0] == '<' || str[0] == '>') {\n\tif ((str[0] == '<') && (s[0] == 0)) *swap = 1;\n\telse if ((str[0] == '>') && (s[0] != 0)) *swap = 1;\n }\n str += 1;\n \n#define _MY_FAIL {\t\t\t\t \\\n\t PyErr_SetString(PyExc_ValueError, msg); \\\n\t return -1;\t\t\t \\\n }\t\t\n\n typechar = str[0];\n size = atoi(str + 1);\n switch (typechar) {\n case 'b':\n\t if (size == sizeof(Bool))\n\t\t type_num = PyArray_BOOL;\t \n\t else _MY_FAIL \n\t break;\t\t \n case 'u':\n if (size == sizeof(uintp))\n type_num = PyArray_UINTP;\n\t else if (size == sizeof(char))\n\t\t type_num = PyArray_UBYTE;\n\t else if (size == sizeof(short)) \n\t\t type_num = PyArray_USHORT;\n\t else if (size == sizeof(int)) \n\t\t type_num = PyArray_UINT;\n\t else if (size == sizeof(ulong)) \n\t\t type_num = PyArray_ULONG;\n\t else if (size == sizeof(ulonglong))\n\t\t type_num = PyArray_ULONGLONG;\n\t else _MY_FAIL\n\t break;\t\t \n case 'i':\n if (size == sizeof(intp))\n type_num = PyArray_INTP;\n\t else if (size == sizeof(char)) \n\t\t type_num = PyArray_BYTE;\n\t else if (size == sizeof(short)) \n\t\t type_num = PyArray_SHORT;\n\t else if (size == sizeof(int))\n\t\t type_num = PyArray_INT;\n\t else if (size == sizeof(long)) \n\t\t type_num = PyArray_LONG;\n\t else if (size == sizeof(longlong))\n\t\t type_num = PyArray_LONGLONG;\n\t else _MY_FAIL\n\t break;\t\t \n case 'f':\n\t if (size == sizeof(float))\n\t\t type_num = PyArray_FLOAT;\n\t else if (size == sizeof(double))\n\t\t type_num = PyArray_DOUBLE;\n\t else if (size == sizeof(longdouble))\n\t\t type_num = PyArray_LONGDOUBLE;\n\t else _MY_FAIL\n\t break;\n case 'c':\n\t if (size == sizeof(float)*2)\n\t\t type_num = PyArray_CFLOAT;\n\t else if (size == sizeof(double)*2)\n\t\t type_num = PyArray_CDOUBLE;\n\t else if (size == sizeof(longdouble)*2)\n\t\t type_num = PyArray_CLONGDOUBLE;\n\t else _MY_FAIL\n\t break;\n case 'O':\n\t if (size == sizeof(PyObject *))\n\t\t type_num = PyArray_OBJECT;\n\t else _MY_FAIL\n\t break;\n case 'S':\n\t type_num = PyArray_STRING;\n\t break;\n case 'U':\n\t type_num = PyArray_UNICODE;\n\t size *= sizeof(Py_UNICODE);\n\t break;\t \n case 'V':\n\t type_num = PyArray_VOID;\n\t break;\n default:\n\t _MY_FAIL\n }\n\n#undef _MY_FAIL\n\n type->type_num = type_num;\n type->itemsize = size;\n type->fortran = 0;\n return 0;\n}\n\nstatic PyObject *\narray_frominterface(PyObject *input, PyArray_Typecode *intype, int flags)\n{\n\tPyObject *attr=NULL, *item=NULL, *r;\n\tPyArrayObject *ret=NULL;\n\tPyArray_Typecode type;\n\tchar *data;\n\tint buffer_len;\n\tint res, i, n;\n\tintp dims[MAX_DIMS], strides[MAX_DIMS];\n\tint swap;\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\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) {Py_XDECREF(attr); return NULL;}\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t}\n\telse {\n\t\tif (PyTuple_GET_SIZE(attr) != 2) {\n\t\t\tPy_DECREF(attr);\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\treturn NULL;\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\tPy_DECREF(attr);\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\treturn NULL;\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 = PyObject_GetAttrString(input, \"__array_typestr__\");\n\tif (!PyString_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_typestr__ must be a string\");\n\t\tPy_DECREF(attr);\n\t\treturn NULL;\t\n\t}\n\tres = _array_typecode_fromstr(PyString_AS_STRING(attr), &swap, &type);\n\tPy_DECREF(attr);\n\tif (res < 0) return NULL;\n \n\tattr = PyObject_GetAttrString(input, \"__array_shape__\");\n\tif (!PyTuple_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_shape__ must be a tuple\");\n\t\tPy_DECREF(attr);\n\t\treturn NULL;\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\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\treturn NULL;\n\t\t}\n\t\tfor (i=0; istrides, strides, n*sizeof(intp));\n\t}\n\n\tif (swap) {\n\t\tPyObject *tmp;\n tmp = PyArray_Byteswap(ret, TRUE);\n\t\tPy_DECREF(tmp);\n\t}\n\n\tPyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n\tr = array_fromarray(ret, intype, flags);\n\tPy_DECREF(ret);\n\treturn r;\n}\n\nstatic PyObject *\narray_fromattr(PyObject *op, PyArray_Typecode *typecode, int flags) \n{\n PyObject *new, *r;\n\t \n if (typecode->type_num == PyArray_NOTYPE) {\n new = PyObject_CallMethod(op, \"__array__\", NULL);\n } else {\n\t\tPyArray_Descr *descr;\n\t\tPyObject *obj;\n\n\t\tdescr = PyArray_DescrFromType(typecode->type_num);\n\t\tif (PyTypeNum_ISFLEXIBLE(typecode->type_num)) {\n\t\t\tobj = PyString_FromFormat(\"%c%d\", descr->type,\n\t\t\t\t\t\t typecode->itemsize);\n\t\t}\n\t\telse { \n\t\t\tobj = (PyObject *)(descr->typeobj); Py_INCREF(obj);\n\t\t}\n\t\tnew = PyObject_CallMethod(op, \"__array__\", \"N\", obj);\n }\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 r = array_fromarray((PyArrayObject *)new, typecode, flags);\n Py_DECREF(new);\n return r;\n} \n\n\nstatic PyObject *\narray_fromobject(PyObject *op, PyArray_Typecode *typecode, int min_depth, \n\t\t int max_depth, int flags) \n{\n /* This is the main code to make a NumPy array from a Python\n Object. It is called from lot's of different places which\n is why there are so many checks. The comments try to\n explain some of the checks. */\n\n\tint type = typecode->type_num;\n PyObject *r=NULL;\n\n\t/* Is input object already an array? */\n\t/* This is where the flags are used */\n if (PyArray_Check(op)) \n\t\tr = array_fromarray((PyArrayObject *)op, typecode, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, typecode);\n\t}\n\telse if (PyObject_HasAttrString(op, \"__array__\")) {\n\t\t/* Code that returns the object to convert for a non\n\t\t multiarray input object from the __array__ attribute of the\n\t\t object. */\n r = array_fromattr(op, typecode, flags);\n\t}\n\telse if (PyObject_HasAttrString(op, \"__array_shape__\") &&\n\t\t PyObject_HasAttrString(op, \"__array_typestr__\")) {\n\t\tr = array_frominterface(op, typecode, flags);\n\t}\n\telse {\n\t\tif (type == PyArray_NOTYPE) {\n\t\t\t_array_find_type(op, NULL, typecode, MAX_DIMS);\n\t\t}\n\t\tif (PySequence_Check(op))\n\t\t\tr = Array_FromSequence(op, typecode, \n\t\t\t\t\t min_depth, max_depth);\n\t\telse\n\t\t\tr = Array_FromScalar(op, typecode);\n\t}\n\n /* If we didn't succed return NULL */\n if (r == NULL) return NULL;\n\t\n\t/* Be sure we succeed here */\n\t\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"internal error: array_fromobject \"\\\n\t\t\t\t\"not producing an array\");\n\t\tPy_DECREF(r);\n return NULL;\n }\n\n if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {\n Py_DECREF(r);\n PyErr_SetString(PyExc_ValueError, \n \"object of too small depth for desired array\");\n return NULL;\n }\n if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {\n Py_DECREF(r);\n PyErr_SetString(PyExc_ValueError, \n \"object too deep for desired array\");\n return NULL;\n }\n return r;\n}\n\nstatic void\nPyArray_ArrayType(PyObject *op, PyArray_Typecode *intype, \n\t\t PyArray_Typecode *outtype) \n{\n\t_array_find_type(op, intype, outtype, MAX_DIMS);\n\treturn;\n}\n\nstatic int \nPyArray_ObjectType(PyObject *op, int minimum_type) \n{\n\tPyArray_Typecode intype, outtype;\n\tintype.type_num = minimum_type;\n\t_array_find_type(op, &intype, &outtype, MAX_DIMS);\n\treturn outtype.type_num;\n}\n\n\n\n/* flags is any of \n CONTIGUOUS, \n FORTRAN, (or set typecode->fortran=1)\n ALIGNED, \n NOTSWAPPED, \n WRITEABLE, \n ENSURECOPY, \n UPDATEIFCOPY,\n FORCECAST,\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, NOTSWAPPED, and WRITEABLE\n and therefore it is redundant to include those as well. \n\n BEHAVED_FLAGS == ALIGNED | NOTSWAPPED | WRITEABLE\n BEHAVED_FLAGS_RO == ALIGNED | NOTSWAPPED\n CARRAY_FLAGS = CONTIGUOUS | BEHAVED_FLAGS\n FARRAY_FLAGS = FORTRAN | BEHAVED_FLAGS\n \n By default, the returned array will be a copy of the object, \n (C) contiguous in memory, aligned, notswapped, and writeable.\n \n So CONTIGUOUS | ENSURECOPY passed in means that the returned\n array does not have to be CONTIGUOUS or a COPY but should be\n ALIGNED, NOTSWAPPED and WRITEABLE. \n\n typecode->fortran can be set to request a\n fortran-contiguous array. Fortran arrays are always behaved (aligned, \n notswapped, and writeable) and not (C) CONTIGUOUS. Note that either\n FORTRAN in the flag or typecode->fortran = 1 is enough to request\n a FORTRAN-style array. \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\nstatic PyObject *\nPyArray_FromAny(PyObject *op, PyArray_Typecode *typecode, int min_depth, \n\t\tint max_depth, int requires) \n{\n \tPyArray_Typecode mine = {PyArray_NOTYPE, 0, 0};\n\tPyArray_Typecode *type;\n\t\n\tif (typecode == NULL) type = &mine;\n\telse type = typecode;\n\t\t\n\tif (requires & ENSURECOPY) {\n\t\trequires |= DEFAULT_FLAGS;\n\t}\n\t/* Ensure that type->fortran and flags & FORTRAN are the\n\t same */\n\tif (requires & FORTRAN) typecode->fortran = 1;\n\tif (type->fortran == 1) {\n\t\trequires |= FARRAY_FLAGS;\n\t\tif (min_depth > 2) requires &= ~CONTIGUOUS;\n\t}\n\n\t/* make sure itemsize is not 0 unless warranted. */\n\tif ((type->itemsize == 0) && (type->type_num != PyArray_NOTYPE)) {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(type->type_num);\n\t\tif (descr != NULL) type->itemsize = descr->elsize;\n\t\telse return NULL;\n\t}\n\t\n\treturn array_fromobject(op, type, min_depth, max_depth, \n\t\t\t\trequires);\t\n}\n\n/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0, 0) */\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\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);\n Py_DECREF(op);\n return new;\n}\n\n/* These are all compressed into a single API */\n/* Deprecated calls -- Use PyArray_FromAny */\n\nstatic PyObject *\nPyArray_FromObject(PyObject *op, int type, int min_depth, int max_depth) \n{\n\tPyArray_Typecode typecode = {0, 0, 0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth,\n\t\t\t max_depth, BEHAVED_FLAGS | ENSUREARRAY);\n}\n\nstatic PyObject *\nPyArray_ContiguousFromObject(PyObject *op, int type, int min_depth, \n\t\t\t int max_depth) \n{\n\tPyArray_Typecode typecode = {0, 0, 0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth,\n\t\t\t max_depth, DEFAULT_FLAGS | ENSUREARRAY);\n}\n\nstatic PyObject *\nPyArray_CopyFromObject(PyObject *op, int type, int min_depth, \n\t\t int max_depth) \n{\n\tPyArray_Typecode typecode = {0, 0, 0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth, max_depth,\n\t\t\t ENSURECOPY | ENSUREARRAY);\n}\n\n/* End of deprecated */\n\nstatic PyObject *\nPyArray_ContiguousFromAny(PyObject *op, int type, int min_depth, \n\t\t\t int max_depth)\n{\n\tPyArray_Typecode typecode = {0,0,0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth,\n\t\t\t max_depth, DEFAULT_FLAGS);\n}\t\n\nstatic int \nPyArray_CanCastSafely(int fromtype, int totype) \n{\n\tPyArray_Descr *from, *to;\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\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 (to->elsize > from->elsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (to->elsize >= from->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (from->elsize < 8)\n return (to->elsize > from->elsize);\n else\n return (to->elsize >= from->elsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (from->elsize < 8)\n return ((to->elsize >> 1) > from->elsize);\n else\n return ((to->elsize >> 1) >= from->elsize);\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 (to->elsize > from->elsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (to->elsize >= from->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (from->elsize < 8)\n return (to->elsize > from->elsize);\n else\n return (to->elsize >= from->elsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (from->elsize < 8)\n return ((to->elsize >> 1) > from->elsize);\n else\n return ((to->elsize >> 1) >= from->elsize);\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 ((to->elsize >> 1) >= from->elsize);\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\nstatic Bool\nPyArray_CanCastTo(PyArray_Typecode *from, PyArray_Typecode *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->itemsize <= to->itemsize);\n\t\t\t}\n\t\t\telse if (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->itemsize * sizeof(Py_UNICODE)\\\n\t\t\t\t <= to->itemsize);\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->itemsize <= to->itemsize);\n\t\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 scipy's arraymap ****/\n/* and Python's array iterator ***/\n \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 = PyObject_GC_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 PyObject_GC_Track(it);\n return (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 PyObject_GC_UnTrack(it);\n Py_XDECREF(it->ao);\n PyObject_GC_Del(it);\n }\n\nstatic int\narrayiter_traverse(PyArrayIterObject *it, visitproc visit, void *arg)\n{\n if (it->ao != NULL)\n return visit((PyObject *)(it->ao), arg);\n return 0;\n}\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->itemsize;\n\tr = PyArray_New(self->ao->ob_type, 1, &count, \n\t\t\tself->ao->descr->type_num, NULL, NULL,\n\t\t\titemsize, 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->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->itemsize;\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\tr = PyArray_New(self->ao->ob_type, ind->nd, ind->dimensions,\n\t\t\tself->ao->descr->type_num, NULL, \n\t\t\tNULL, self->ao->itemsize, \n\t\t\t0, (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)->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\tint i;\n\tPyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tint 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\t\t\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\n\t/* Tuples 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\tr = PyArray_New(self->ao->ob_type, 1, &ii, \n\t\t\t\t\tself->ao->descr->type_num, NULL, \n\t\t\t\t\tNULL, self->ao->itemsize, 0,\n\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 */\n\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->itemsize;\n\t\tr = PyArray_New(self->ao->ob_type, 1, &n_steps, \n\t\t\t\tself->ao->descr->type_num, NULL, NULL,\n\t\t\t\tsize, 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)->copyswap;\n\t\twhile(n_steps--) {\n copyswap(dptr, self->dataptr, swap, size);\n\t\t\tfor(i=0; i< step_size; i++) \n\t\t\t\tPyArray_ITER_NEXT(self);\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\tif (PyArray_IsScalar(ind, Integer) || PyList_Check(ind)) {\n\t\tobj = PyArray_FromAny(ind, &indtype, 0, 0, FORCECAST);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tr = iter_subscript_Bool(self, (PyArrayObject *)obj);\n\t\t} \n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, &indtype, 0, 0, \n\t\t\t\t\t FORCECAST | BEHAVED_FLAGS);\n\t\t\tif (new==NULL) goto fail;\n\t\t\tobj = new;\n\t\t\tr = iter_subscript_int(self, (PyArrayObject *)obj);\n\t\t}\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\t\"unsupported iterator index\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPy_DECREF(obj);\n\t\treturn r;\n\t}\n\n\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\n fail:\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->itemsize;\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->copyswap;\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(self->dataptr, val->dataptr, swap,\n itemsize);\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t\tPyArray_ITER_NEXT(val);\n\t\tif (val->index==val->size) \n\t\t\tPyArray_ITER_RESET(val);\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_Typecode typecode;\n\tintp num;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\titemsize = typecode.itemsize = self->ao->itemsize;\n\ttypecode.type_num = self->ao->descr->type_num;\n copyswap = self->ao->descr->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\n\nstatic int\niter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val) \n{\n\tint i;\n\tPyObject *arrval=NULL;\n\tPyArrayIterObject *val_it=NULL;\n\tPyArray_Typecode type;\n\tPyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tint swap;\n\tint itemsize;\n\tint start, step_size;\n\tintp n_steps;\n\tPyObject *obj;\n PyArray_CopySwapFunc *copyswap;\n\t\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\ti = iter_ass_subscript(self, ind, val);\n\t\tPy_DECREF(ind);\n\t\treturn i;\n\t}\n\t\n\ttype.type_num = self->ao->descr->type_num;\n\titemsize = type.itemsize = self->ao->itemsize;\n\t\n\tarrval = PyArray_FromAny(val, &type, 0, 0, 0);\n\tif (arrval==NULL) return -1;\n\tval_it = (PyArrayIterObject *)PyArray_IterNew(arrval);\n\tif (val_it==NULL) goto fail;\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\n copyswap = PyArray_DESCR(arrval)->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\tgoto succeed;\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 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 copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, itemsize);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\tgoto succeed;\n\t\t}\n\t\twhile(n_steps--) {\n copyswap(self->dataptr, val_it->dataptr,\n swap, itemsize);\n\t\t\tfor(i=0; i < step_size; i++) \n\t\t\t\tPyArray_ITER_NEXT(self);\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\tgoto succeed;\n\t} \n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tif (PyArray_IsScalar(ind, Integer))\n\t\tobj = PyArray_FromScalar(ind, &indtype);\n\telse if (PyList_Check(ind)) {\n\t\tobj = PyArray_FromAny(ind, &indtype, 0, 0, FORCECAST);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tif (iter_ass_sub_Bool(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto fail;\n\t\t} \n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, &indtype, 0, 0, \n\t\t\t\t\t FORCECAST | BEHAVED_FLAGS);\n\t\t\tif (new==NULL) goto fail;\n\t\t\tPy_DECREF(obj);\n\t\t\tobj = new;\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 fail;\n\t\t}\n\t\telse goto fail;\n\t\tPy_DECREF(obj);\n\t\tgoto succeed;\n\t}\n\n\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\tgoto fail;\n\n succeed:\n\tPy_DECREF(val_it);\n\tPy_DECREF(arrval);\n\treturn 0;\n\n fail:\n\tPy_XDECREF(val_it);\n\tPy_XDECREF(arrval);\n\treturn -1;\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 if (PyArray_ISCONTIGUOUS(it->ao)) {\n r = PyArray_New(it->ao->ob_type, 1, &size, \n\t\t\t\tit->ao->descr->type_num,\n NULL, it->ao->data, it->ao->itemsize, \n\t\t\t\tit->ao->flags,\n (PyObject *)it->ao); \n\t\tif (r==NULL) return NULL;\n }\n else {\n r = PyArray_New(it->ao->ob_type, 1, &size, \n\t\t\t\tit->ao->descr->type_num,\n NULL, NULL, it->ao->itemsize, 0, \n (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\n\nstatic PyTypeObject PyArrayIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"scipy.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 | Py_TPFLAGS_HAVE_GC,/* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)arrayiter_traverse,\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)arrayiter_next,\t\t/* tp_iternext */\n iter_methods,\t\t\t\t/* tp_methods */\n};\n\n/** END of Array Iterator **/\n\n\n\n/*********************** Subscript Array Iterator *************************\n * *\n * This object handles subscript behavior for array objects. *\n * It is an iterator object with a next method *\n * It abstracts the n-dimensional mapping behavior to make the looping *\n * code more understandable (maybe) *\n * and so that indexing can be set up ahead of time *\n */ \n\n/* This checks the args for any fancy indexing objects */\n\n#define SOBJ_NOTFANCY 0 \n#define SOBJ_ISFANCY 1\n#define SOBJ_BADARRAY 2\n#define SOBJ_TOOMANY 3\n#define SOBJ_LISTTUP 4\n\nstatic int\nfancy_indexing_check(PyObject *args)\n{\n\tint i, n;\n\tPyObject *obj;\n\tint retval = SOBJ_NOTFANCY;\n\n\tif (PyTuple_Check(args)) {\n\t\tn = PyTuple_GET_SIZE(args);\n\t\tif (n >= MAX_DIMS) return SOBJ_TOOMANY;\n\t\tfor (i=0; i=MAX_DIMS) return SOBJ_ISFANCY;\n\t\tfor (i=0; i SOBJ_ISFANCY) return retval;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* convert an indexing object to an INTP indexing array iterator\n if possible -- otherwise, it is a Slice or Ellipsis object\n and has to be interpreted on bind to a particular \n array so leave it NULL for now.\n */\nstatic int\n_convert_obj(PyObject *obj, PyArrayIterObject **iter)\n{\n\tPyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tPyObject *arr;\n\n\tif (PySlice_Check(obj) || (obj == Py_Ellipsis))\n\t\t*iter = NULL;\n\telse {\n\t\tarr = PyArray_FromAny(obj, &indtype, 0, 0, FORCECAST);\n\t\tif (arr == NULL) return -1;\n\t\t*iter = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (*iter == NULL) return -1;\n\t}\n\treturn 0;\n}\n\n/* Adjust dimensionality and strides for index object iterators \n --- i.e. broadcast\n */\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->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->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=NULL, *obj=NULL;\n\tint i, j, n, curraxis, ellipexp, noellip;\n\tPyArrayIterObject *it;\n\tintp dimsize;\n\tintp *indptr;\n\n\t/* Remove old binding if any */\n\tPy_XDECREF(mit->ait);\n\tmit->ait = NULL;\n\n\tPy_XDECREF(mit->subspace);\n\tmit->subspace = NULL;\n\t\n\tsubnd = arr->nd - mit->numiter;\n\tif (subnd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"too many indices for array\");\n\t\treturn;\n\t}\n\n\tmit->ait = (PyArrayIterObject *)PyArray_IterNew((PyObject *)arr);\n\tif (mit->ait == NULL) return;\n\n\t/* If this is just a view, then do nothing more */\n\t/* views are handled by just adjusting the strides\n\t and dimensions of the object.\n\t*/\n\t \n\tif (mit->view) return;\n\n\t/* no subspace iteration needed. 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\tif (mit->subspace == NULL) goto fail;\n\tPy_DECREF(sub);\n\n\t/* Expand dimensions of result */\n\tn = mit->subspace->ao->nd;\n\tfor (i=0; idimensions[mit->nd+i] = mit->subspace->ao->dimensions[i];\n\tmit->nd += n;\n\n\t/* Now, we still need to interpret the ellipsis and slice objects \n\t to determine which axes the indexing arrays are referring to\n\t*/\n\tn = PyTuple_GET_SIZE(mit->indexobj);\n\n\t/* The number of dimensions an ellipsis takes up */\n\tellipexp = arr->nd - n + 1;\n\t/* Now fill in iteraxes -- remember indexing arrays have been \n converted to 0's in mit->indexobj */\n\tcurraxis = 0;\n\tj = 0;\n\tnoellip = 1; /* Only expand the first ellipsis */\n\tmemset(mit->bscoord, 0, sizeof(intp)*arr->nd);\n\tfor (i=0; iindexobj, i);\n\t\tif (PyInt_Check(obj) || PyLong_Check(obj)) \n\t\t\tmit->iteraxes[j++] = curraxis++;\n\t\telse if (noellip && obj == Py_Ellipsis) {\n\t\t\tcurraxis += ellipexp;\n\t\t\tnoellip = 0;\n\t\t}\n\t\telse {\n\t\t\tint start=0;\n\t\t\tint 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}\t\t\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn;\n\n fail:\n\tPy_XDECREF(sub);\n\tPy_XDECREF(mit->ait);\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_Typecode typecode = {PyArray_BOOL, 0, 0};\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\tba = (PyArrayObject *)PyArray_FromAny(myBool, &typecode, 0, 0, \n\t\t\t\t\t CARRAY_FLAGS);\n\tif (ba == NULL) return -1;\n\tnd = ba->nd;\n\tfor (j=0; jdata;\n\tcount = 0;\n\n\t/* pre-determine how many nonzero entries there are */\n\tfor (i=0; iao->data;\n\t\tcoords[j] = 0;\n\t\tdims_m1[j] = ba->dimensions[j]-1;\n\t}\n\n\tptr = (Bool *)ba->data;\n\n\tif (count == 0) return nd;\n\n\t/* Loop through the Boolean array and copy coordinates\n\t for non-zero entries */\n\tfor (i=0; i=0; j--) {\n\t\t\tif (coords[j] < dims_m1[j]) {\n\t\t\t\tcoords[j]++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcoords[j] = 0;\n\t\t\t}\n\t\t}\n\t}\n\treturn nd;\n\n fail:\n\tfor (j=0; jiters[i] = NULL;\n \tmit->view = 0;\n \tmit->index = 0;\n \tmit->ait = NULL;\n \tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tfancy = fancy_indexing_check(indexobj);\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\tif (fancy == SOBJ_NOTFANCY) { /* bail out */\n\t\tmit->view = 1;\n\t\tgoto ret;\n\t}\n\n\tif (fancy == SOBJ_BADARRAY) {\n\t\tPyErr_SetString(PyExc_TypeError,\t\t\t\\\n\t\t\t\t\"arrays used as indexes must be of \" \\\n\t\t\t\t\"integer type\");\n\t\tgoto fail;\n\t}\n\tif (fancy == SOBJ_TOOMANY) {\n\t\tPyErr_SetString(PyExc_TypeError, \"too many indicies\");\n\t\tgoto fail;\n\t}\n\n\tif (fancy == SOBJ_LISTTUP) {\n\t\tPyObject *newobj;\n\t\tnewobj = PySequence_Tuple(indexobj);\n\t\tif (newobj == NULL) goto fail;\n\t\tPy_DECREF(indexobj);\n\t\tindexobj = newobj;\n\t\tmit->indexobj = indexobj;\n\t}\n\n#undef SOBJ_NOTFANCY \n#undef SOBJ_ISFANCY \n#undef SOBJ_BADARRAY \n#undef SOBJ_TOOMANY \n#undef SOBJ_LISTTUP \n\n\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\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 (PyList_Check(indexobj) || PyArray_Check(indexobj)) {\n\t\tmit->numiter = 1;\n\t\tarr = PyArray_FromAny(indexobj, &indtype, 0, 0, FORCECAST);\n\t\tif (arr == NULL) goto fail;\n\t\tmit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (mit->iters[0] == NULL) 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(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\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = new;\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\t/* Store the number of iterators actually converted */\n\t\t/* These will be mapped to actual axes at bind time */\n\t\tif (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)\n\t\t\tgoto fail;\n\t}\n\n ret:\n PyObject_GC_Track(mit);\n return (PyObject *)mit;\n \n fail:\n\tPy_XDECREF(arr);\n\tPy_XDECREF(mit->indexobj);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n PyObject_GC_Del(mit);\n\treturn NULL;\n}\n\n\n/* return unbound mapiter object */\n\nstatic PyObject *\narraymapiter_new(PyTypeObject *type, PyObject *args, PyObject *kwds) \n{\n\tPyObject *newtup, *res;\n\tint n;\n\n\tif (!PyTuple_Check(args)) {\n\t\tPyErr_BadInternalCall();\n\t\treturn NULL;\n\t}\n\n\tn = PyTuple_GET_SIZE(args);\n\t\n\tif (n < 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"must be initialized with >= 1 argument\");\n\t\treturn NULL;\n\t}\n\t\n\tif (n > 1) {\n\t\tnewtup = PyTuple_GetSlice(args, 0, n);\n\t\tif (newtup == NULL) return NULL;\n\t\tres = PyArray_MapIterNew(newtup);\n\t\tPy_DECREF(newtup);\n\t}\n\telse { /* n == 1 */\n\t\tnewtup = PyTuple_GET_ITEM(args, 0);\n\t\tres = PyArray_MapIterNew(newtup);\n\t}\n\n\treturn res; \t\n}\n\n\n/* Returns a 0-dim array holding the element desired */\n/*\nstatic PyObject *\narraymapiter_next(PyArrayMapIterObject *mit)\n{\n\tPyObject *ret;\n\tif (mit->ait == NULL) return NULL;\n\tif (mit->view) return NULL;\n\tif (mit->index < mit->size) {\n\t\tret = PyArray_ToScalar(mit->dataptr, mit->ait->ao);\n\t\tPyArray_MapIterNext(mit);\n\t\treturn ret;\n\t}\n return NULL;\n}\n*/\n\nstatic void\narraymapiter_dealloc(PyArrayMapIterObject *mit)\n{\n\tint i;\n PyObject_GC_UnTrack(mit);\n Py_XDECREF(mit->ait);\n\tPy_XDECREF(mit->indexobj);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n PyObject_GC_Del(mit);\n}\n\nstatic int\narraymapiter_traverse(PyArrayMapIterObject *mit, visitproc visit, void *arg)\n{\n\tint ret, i;\n if (mit->ait != NULL)\n if ((ret = visit((PyObject *)(mit->ait), arg)) != 0) \n\t\t\treturn ret;\t\n\n\tif (mit->iters != NULL) \n\t\tfor (i=0; inumiter; i++) \n\t\t\tif (mit->iters[i] != NULL) \n\t\t\t\tif ((ret=visit((PyObject *)mit->iters[i], \n\t\t\t\t\t arg)) != 0)\n\t\t\t\t\treturn ret;\n\n\tif (mit->indexobj != NULL)\n\t\tif ((ret = visit(mit->indexobj, arg)) != 0) return ret;\n\t\n return 0;\n}\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 MapIterNew must be \n that does not work. 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 char doc_mapiter_bind[] = \"obj.bind(a)\\n Bind an array to the \"\\\n\t\"mapiter object\";\n\nstatic PyObject *\nmapiter_bind(PyArrayMapIterObject *mit, PyObject *args)\n{\n\tPyArrayObject *arr;\n\n if (!PyArg_ParseTuple(args, \"O!\", &PyArray_Type, &arr)) return NULL;\n\n \tPyArray_MapIterBind(mit, arr);\n\n\tif (mit->ait == NULL) return NULL;\n\t\n \tPyArray_MapIterReset(mit);\n\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyMethodDef mapiter_methods[] = {\n\t{\"bind\", (PyCFunction)mapiter_bind, 1, doc_mapiter_bind},\n {NULL,\t\tNULL}\t\t\n};\n*/\n\n\nstatic PyTypeObject PyArrayMapIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"scipy.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 | Py_TPFLAGS_HAVE_GC,/* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)arraymapiter_traverse,\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, /*arraymapiter_next,*/\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 (newfunc)arraymapiter_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n\n};\n\n/** END of Subscript Iterator **/\n\n\n\n", "methods": [ { "name": "PyArray_PyIntAsIntp", "long_name": "PyArray_PyIntAsIntp( PyObject * o)", "filename": "arrayobject.c", "nloc": 59, "complexity": 19, "token_count": 385, "parameters": [ "o" ], "start_line": 40, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 64, "top_nesting_level": 0 }, { "name": "PyArray_PyIntAsInt", "long_name": "PyArray_PyIntAsInt( PyObject * o)", "filename": "arrayobject.c", "nloc": 57, "complexity": 19, "token_count": 389, "parameters": [ "o" ], "start_line": 109, "end_line": 169, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 61, "top_nesting_level": 0 }, { "name": "PyArray_GetPriority", "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", "filename": "arrayobject.c", "nloc": 17, "complexity": 5, "token_count": 86, "parameters": [ "obj", "default_" ], "start_line": 173, "end_line": 191, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "PyArray_Zero", "long_name": "PyArray_Zero( PyArrayObject * arr)", "filename": "arrayobject.c", "nloc": 34, "complexity": 6, "token_count": 190, "parameters": [ "arr" ], "start_line": 208, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "PyArray_One", "long_name": "PyArray_One( PyArrayObject * arr)", "filename": "arrayobject.c", "nloc": 40, "complexity": 7, "token_count": 222, "parameters": [ "arr" ], "start_line": 246, "end_line": 289, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "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": 295, "end_line": 345, "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": 368, "end_line": 399, "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": 213, "parameters": [ "src" ], "start_line": 402, "end_line": 436, "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": 449, "end_line": 471, "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": 474, "end_line": 495, "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": 499, "end_line": 537, "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": 542, "end_line": 562, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "index2ptr", "long_name": "index2ptr( PyArrayObject * mp , int i)", "filename": "arrayobject.c", "nloc": 10, "complexity": 7, "token_count": 86, "parameters": [ "mp", "i" ], "start_line": 570, "end_line": 580, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "PyArray_Size", "long_name": "PyArray_Size( PyObject * op)", "filename": "arrayobject.c", "nloc": 9, "complexity": 2, "token_count": 33, "parameters": [ "op" ], "start_line": 583, "end_line": 591, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "PyArray_CopyInto", "long_name": "PyArray_CopyInto( PyArrayObject * dest , PyArrayObject * src)", "filename": "arrayobject.c", "nloc": 71, "complexity": 16, "token_count": 427, "parameters": [ "dest", "src" ], "start_line": 604, "end_line": 684, "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": 16, "complexity": 2, "token_count": 98, "parameters": [ "dest", "src_object" ], "start_line": 688, "end_line": 707, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "PyArray_FromDimsAndDataAndDescr", "long_name": "PyArray_FromDimsAndDataAndDescr( int nd , int * d , PyArray_Descr * descr , char * data)", "filename": "arrayobject.c", "nloc": 15, "complexity": 3, "token_count": 121, "parameters": [ "nd", "d", "descr", "data" ], "start_line": 715, "end_line": 734, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "PyArray_FromDimsAndData", "long_name": "PyArray_FromDimsAndData( int nd , int * d , int type , char * data)", "filename": "arrayobject.c", "nloc": 14, "complexity": 3, "token_count": 112, "parameters": [ "nd", "d", "type", "data" ], "start_line": 738, "end_line": 755, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "PyArray_FromDims", "long_name": "PyArray_FromDims( int nd , int * d , int type)", "filename": "arrayobject.c", "nloc": 14, "complexity": 5, "token_count": 133, "parameters": [ "nd", "d", "type" ], "start_line": 759, "end_line": 776, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "PyArray_Copy", "long_name": "PyArray_Copy( PyArrayObject * m1)", "filename": "arrayobject.c", "nloc": 11, "complexity": 2, "token_count": 77, "parameters": [ "m1" ], "start_line": 782, "end_line": 794, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "PyArray_Scalar", "long_name": "PyArray_Scalar( char * data , int type_num , int itemsize , int swap)", "filename": "arrayobject.c", "nloc": 48, "complexity": 8, "token_count": 289, "parameters": [ "data", "type_num", "itemsize", "swap" ], "start_line": 800, "end_line": 849, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "top_nesting_level": 0 }, { "name": "PyArray_ToScalar", "long_name": "PyArray_ToScalar( char * data , PyArrayObject * arr)", "filename": "arrayobject.c", "nloc": 7, "complexity": 1, "token_count": 51, "parameters": [ "data", "arr" ], "start_line": 856, "end_line": 863, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_Return", "long_name": "PyArray_Return( PyArrayObject * mp)", "filename": "arrayobject.c", "nloc": 17, "complexity": 5, "token_count": 85, "parameters": [ "mp" ], "start_line": 869, "end_line": 888, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "PyArray_RegisterDataType", "long_name": "PyArray_RegisterDataType( PyTypeObject * type)", "filename": "arrayobject.c", "nloc": 31, "complexity": 6, "token_count": 177, "parameters": [ "type" ], "start_line": 899, "end_line": 931, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "PyArray_RegisterDescrForType", "long_name": "PyArray_RegisterDescrForType( int typenum , PyArray_Descr * descr)", "filename": "arrayobject.c", "nloc": 32, "complexity": 3, "token_count": 167, "parameters": [ "typenum", "descr" ], "start_line": 941, "end_line": 984, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "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": 16, "token_count": 577, "parameters": [ "self", "fp", "sep", "format" ], "start_line": 988, "end_line": 1079, "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": 24, "complexity": 5, "token_count": 151, "parameters": [ "self" ], "start_line": 1082, "end_line": 1110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "PyArray_ToString", "long_name": "PyArray_ToString( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 34, "complexity": 6, "token_count": 191, "parameters": [ "self" ], "start_line": 1113, "end_line": 1148, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "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": 1157, "end_line": 1194, "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": 1201, "end_line": 1209, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "array_item", "long_name": "array_item( PyArrayObject * self , int i)", "filename": "arrayobject.c", "nloc": 22, "complexity": 4, "token_count": 150, "parameters": [ "self", "i" ], "start_line": 1213, "end_line": 1237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "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": 26, "parameters": [ "self", "i" ], "start_line": 1240, "end_line": 1243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "array_ass_item", "long_name": "array_ass_item( PyArrayObject * self , int i , PyObject * v)", "filename": "arrayobject.c", "nloc": 27, "complexity": 8, "token_count": 177, "parameters": [ "self", "i", "v" ], "start_line": 1247, "end_line": 1277, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "slice_coerce_index", "long_name": "slice_coerce_index( PyObject * o , int * v)", "filename": "arrayobject.c", "nloc": 9, "complexity": 2, "token_count": 40, "parameters": [ "o", "v" ], "start_line": 1281, "end_line": 1289, "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 , int length , int * start , int * stop , int * step , intp * slicelength)", "filename": "arrayobject.c", "nloc": 45, "complexity": 24, "token_count": 376, "parameters": [ "r", "length", "start", "stop", "step", "slicelength" ], "start_line": 1295, "end_line": 1345, "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 , int * step_size , intp * n_steps , int max)", "filename": "arrayobject.c", "nloc": 45, "complexity": 11, "token_count": 223, "parameters": [ "op", "step_size", "n_steps", "max" ], "start_line": 1352, "end_line": 1397, "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": 89, "complexity": 20, "token_count": 540, "parameters": [ "self", "op", "dimensions", "strides", "offset_ptr" ], "start_line": 1401, "end_line": 1496, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 96, "top_nesting_level": 0 }, { "name": "_swap_axes", "long_name": "_swap_axes( PyArrayMapIterObject * mit , PyArrayObject ** ret)", "filename": "arrayobject.c", "nloc": 24, "complexity": 4, "token_count": 187, "parameters": [ "mit", "ret" ], "start_line": 1499, "end_line": 1533, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "PyArray_GetMap", "long_name": "PyArray_GetMap( PyArrayMapIterObject * mit)", "filename": "arrayobject.c", "nloc": 36, "complexity": 8, "token_count": 252, "parameters": [ "mit" ], "start_line": 1538, "end_line": 1587, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "top_nesting_level": 0 }, { "name": "PyArray_SetMap", "long_name": "PyArray_SetMap( PyArrayMapIterObject * mit , PyObject * op)", "filename": "arrayobject.c", "nloc": 50, "complexity": 12, "token_count": 392, "parameters": [ "mit", "op" ], "start_line": 1590, "end_line": 1649, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 60, "top_nesting_level": 0 }, { "name": "array_subscript", "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", "filename": "arrayobject.c", "nloc": 61, "complexity": 19, "token_count": 425, "parameters": [ "self", "op" ], "start_line": 1670, "end_line": 1745, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 76, "top_nesting_level": 0 }, { "name": "array_ass_sub", "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", "filename": "arrayobject.c", "nloc": 43, "complexity": 9, "token_count": 251, "parameters": [ "self", "index", "op" ], "start_line": 1758, "end_line": 1810, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "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": 1818, "end_line": 1821, "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": 1840, "end_line": 1852, "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": 1855, "end_line": 1870, "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": 1874, "end_line": 1883, "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": 1886, "end_line": 1897, "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": 1965, "end_line": 1998, "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": 2005, "end_line": 2044, "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": 23, "complexity": 5, "token_count": 136, "parameters": [ "m1", "op", "axis", "rtype" ], "start_line": 2047, "end_line": 2069, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "PyArray_GenericAccumulateFunction", "long_name": "PyArray_GenericAccumulateFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", "filename": "arrayobject.c", "nloc": 23, "complexity": 5, "token_count": 136, "parameters": [ "m1", "op", "axis", "rtype" ], "start_line": 2073, "end_line": 2095, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "PyArray_GenericBinaryFunction", "long_name": "PyArray_GenericBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", "filename": "arrayobject.c", "nloc": 12, "complexity": 2, "token_count": 69, "parameters": [ "m1", "m2", "op" ], "start_line": 2099, "end_line": 2110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_GenericUnaryFunction", "long_name": "PyArray_GenericUnaryFunction( PyArrayObject * m1 , PyObject * op)", "filename": "arrayobject.c", "nloc": 12, "complexity": 2, "token_count": 63, "parameters": [ "m1", "op" ], "start_line": 2113, "end_line": 2124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_GenericInplaceBinaryFunction", "long_name": "PyArray_GenericInplaceBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", "filename": "arrayobject.c", "nloc": 13, "complexity": 2, "token_count": 71, "parameters": [ "m1", "m2", "op" ], "start_line": 2127, "end_line": 2139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 2142, "end_line": 2145, "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": 2148, "end_line": 2151, "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": 2154, "end_line": 2157, "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": 2160, "end_line": 2163, "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": 2166, "end_line": 2169, "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": 2172, "end_line": 2175, "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": 2178, "end_line": 2181, "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": 2184, "end_line": 2187, "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": 2190, "end_line": 2193, "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": 2196, "end_line": 2199, "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": 2202, "end_line": 2205, "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": 2208, "end_line": 2211, "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": 2214, "end_line": 2217, "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": 2220, "end_line": 2223, "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": 2226, "end_line": 2229, "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": 2232, "end_line": 2235, "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": 2238, "end_line": 2241, "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": 2244, "end_line": 2247, "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": 2250, "end_line": 2253, "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": 2256, "end_line": 2259, "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": 2262, "end_line": 2265, "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": 2268, "end_line": 2271, "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": 2274, "end_line": 2277, "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": 2280, "end_line": 2283, "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": 2286, "end_line": 2289, "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": 2292, "end_line": 2295, "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": 2298, "end_line": 2301, "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": 2304, "end_line": 2308, "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": 2311, "end_line": 2315, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "array_all_nonzero", "long_name": "array_all_nonzero( PyArrayObject * mp)", "filename": "arrayobject.c", "nloc": 18, "complexity": 4, "token_count": 93, "parameters": [ "mp" ], "start_line": 2319, "end_line": 2337, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "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": 2340, "end_line": 2355, "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": 143, "parameters": [ "v" ], "start_line": 2359, "end_line": 2385, "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": 143, "parameters": [ "v" ], "start_line": 2388, "end_line": 2413, "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": 124, "parameters": [ "v" ], "start_line": 2416, "end_line": 2438, "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": 124, "parameters": [ "v" ], "start_line": 2441, "end_line": 2463, "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": 124, "parameters": [ "v" ], "start_line": 2466, "end_line": 2488, "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": 2491, "end_line": 2495, "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": 34, "complexity": 11, "token_count": 258, "parameters": [ "self", "ilow", "ihigh" ], "start_line": 2556, "end_line": 2594, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "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": 2598, "end_line": 2619, "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": 4, "complexity": 1, "token_count": 26, "parameters": [ "self", "el" ], "start_line": 2622, "end_line": 2627, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "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": 308, "parameters": [ "string", "n", "max_n", "data", "nd", "dimensions", "strides", "self" ], "start_line": 2648, "end_line": 2695, "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": 222, "parameters": [ "self" ], "start_line": 2698, "end_line": 2734, "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": 2740, "end_line": 2757, "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": 2760, "end_line": 2772, "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": 2775, "end_line": 2787, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "array_richcompare", "long_name": "array_richcompare( PyArrayObject * self , PyObject * other , int cmp_op)", "filename": "arrayobject.c", "nloc": 61, "complexity": 13, "token_count": 273, "parameters": [ "self", "other", "cmp_op" ], "start_line": 2791, "end_line": 2868, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 78, "top_nesting_level": 0 }, { "name": "_check_axis", "long_name": "_check_axis( PyArrayObject * arr , int * axis , int flags)", "filename": "arrayobject.c", "nloc": 29, "complexity": 8, "token_count": 164, "parameters": [ "arr", "axis", "flags" ], "start_line": 2871, "end_line": 2900, "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": 17, "complexity": 4, "token_count": 91, "parameters": [ "len", "vals" ], "start_line": 2906, "end_line": 2922, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "PyArray_IntpFromSequence", "long_name": "PyArray_IntpFromSequence( PyObject * seq , intp * vals , int maxvals)", "filename": "arrayobject.c", "nloc": 21, "complexity": 7, "token_count": 161, "parameters": [ "seq", "vals", "maxvals" ], "start_line": 2927, "end_line": 2950, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "_IsContiguous", "long_name": "_IsContiguous( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 14, "complexity": 6, "token_count": 109, "parameters": [ "ap" ], "start_line": 2956, "end_line": 2972, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_IsFortranContiguous", "long_name": "_IsFortranContiguous( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 14, "complexity": 6, "token_count": 107, "parameters": [ "ap" ], "start_line": 2976, "end_line": 2992, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_IsAligned", "long_name": "_IsAligned( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 14, "complexity": 4, "token_count": 110, "parameters": [ "ap" ], "start_line": 2995, "end_line": 3011, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_IsWriteable", "long_name": "_IsWriteable( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 16, "complexity": 8, "token_count": 109, "parameters": [ "ap" ], "start_line": 3014, "end_line": 3047, "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": 22, "complexity": 9, "token_count": 129, "parameters": [ "ret", "flagmask" ], "start_line": 3051, "end_line": 3073, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "PyArray_CheckStrides", "long_name": "PyArray_CheckStrides( int elsize , int nd , intp numbytes , intp * dims , intp * newstrides)", "filename": "arrayobject.c", "nloc": 13, "complexity": 4, "token_count": 84, "parameters": [ "elsize", "nd", "numbytes", "dims", "newstrides" ], "start_line": 3080, "end_line": 3095, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "_array_fill_strides", "long_name": "_array_fill_strides( intp * strides , intp * dims , int nd , intp itemsize , int inflag , int * objflags)", "filename": "arrayobject.c", "nloc": 24, "complexity": 9, "token_count": 171, "parameters": [ "strides", "dims", "nd", "itemsize", "inflag", "objflags" ], "start_line": 3115, "end_line": 3139, "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 , char * data , int itemsize , int flags , PyObject * obj)", "filename": "arrayobject.c", "nloc": 117, "complexity": 27, "token_count": 713, "parameters": [ "subtype", "nd", "dims", "type_num", "strides", "data", "itemsize", "flags", "obj" ], "start_line": 3143, "end_line": 3293, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 151, "top_nesting_level": 0 }, { "name": "PyArray_Resize", "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape)", "filename": "arrayobject.c", "nloc": 87, "complexity": 15, "token_count": 501, "parameters": [ "self", "newshape" ], "start_line": 3298, "end_line": 3403, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 106, "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": 3408, "end_line": 3425, "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": 47, "complexity": 7, "token_count": 261, "parameters": [ "arr", "obj" ], "start_line": 3428, "end_line": 3480, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "top_nesting_level": 0 }, { "name": "array_new", "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", "filename": "arrayobject.c", "nloc": 100, "complexity": 20, "token_count": 589, "parameters": [ "subtype", "args", "kwds" ], "start_line": 3483, "end_line": 3598, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 116, "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": 3605, "end_line": 3608, "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": 10, "complexity": 3, "token_count": 57, "parameters": [ "self" ], "start_line": 3611, "end_line": 3621, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "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": 3694, "end_line": 3697, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "array_shape_set", "long_name": "array_shape_set( PyArrayObject * self , PyObject * val)", "filename": "arrayobject.c", "nloc": 33, "complexity": 6, "token_count": 206, "parameters": [ "self", "val" ], "start_line": 3701, "end_line": 3735, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "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": 3739, "end_line": 3742, "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": 32, "complexity": 7, "token_count": 209, "parameters": [ "self", "obj" ], "start_line": 3745, "end_line": 3778, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "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": 3782, "end_line": 3789, "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": 3792, "end_line": 3800, "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": 3804, "end_line": 3810, "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": 3813, "end_line": 3827, "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": 3830, "end_line": 3874, "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": 19, "parameters": [ "self" ], "start_line": 3878, "end_line": 3881, "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": 8, "complexity": 3, "token_count": 42, "parameters": [ "self" ], "start_line": 3884, "end_line": 3891, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "array_typechar_get", "long_name": "array_typechar_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 8, "complexity": 2, "token_count": 47, "parameters": [ "self" ], "start_line": 3895, "end_line": 3902, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "array_typestr_get", "long_name": "array_typestr_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 19, "complexity": 7, "token_count": 141, "parameters": [ "self" ], "start_line": 3905, "end_line": 3925, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "array_descr_get", "long_name": "array_descr_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 19, "complexity": 5, "token_count": 128, "parameters": [ "self" ], "start_line": 3928, "end_line": 3950, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "array_type_get", "long_name": "array_type_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 4, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 3954, "end_line": 3957, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "array_type_set", "long_name": "array_type_set( PyArrayObject * self , PyObject * arg)", "filename": "arrayobject.c", "nloc": 41, "complexity": 10, "token_count": 294, "parameters": [ "self", "arg" ], "start_line": 3969, "end_line": 4027, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 59, "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": 4032, "end_line": 4042, "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": 4046, "end_line": 4071, "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": 31, "complexity": 4, "token_count": 177, "parameters": [ "self", "val" ], "start_line": 4075, "end_line": 4107, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "array_imag_get", "long_name": "array_imag_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 34, "complexity": 3, "token_count": 200, "parameters": [ "self" ], "start_line": 4110, "end_line": 4145, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "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": 203, "parameters": [ "self", "val" ], "start_line": 4148, "end_line": 4185, "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": 4188, "end_line": 4191, "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": 51, "complexity": 9, "token_count": 368, "parameters": [ "self", "val" ], "start_line": 4194, "end_line": 4248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 55, "top_nesting_level": 0 }, { "name": "discover_depth", "long_name": "discover_depth( PyObject * s , int max , int stop_at_string)", "filename": "arrayobject.c", "nloc": 23, "complexity": 14, "token_count": 169, "parameters": [ "s", "max", "stop_at_string" ], "start_line": 4423, "end_line": 4448, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "discover_itemsize", "long_name": "discover_itemsize( PyObject * s , int nd , int * itemsize)", "filename": "arrayobject.c", "nloc": 21, "complexity": 9, "token_count": 161, "parameters": [ "s", "nd", "itemsize" ], "start_line": 4451, "end_line": 4473, "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": 4480, "end_line": 4506, "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( int chktype , int mintype , int chksize , int minsize , PyArray_Typecode * outtype)", "filename": "arrayobject.c", "nloc": 19, "complexity": 5, "token_count": 100, "parameters": [ "chktype", "mintype", "chksize", "minsize", "outtype" ], "start_line": 4509, "end_line": 4529, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "_array_find_type", "long_name": "_array_find_type( PyObject * op , PyArray_Typecode * minitype , PyArray_Typecode * outtype , int max)", "filename": "arrayobject.c", "nloc": 126, "complexity": 28, "token_count": 671, "parameters": [ "op", "minitype", "outtype", "max" ], "start_line": 4532, "end_line": 4673, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 142, "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": 4676, "end_line": 4699, "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_Typecode * typecode)", "filename": "arrayobject.c", "nloc": 21, "complexity": 5, "token_count": 132, "parameters": [ "op", "typecode" ], "start_line": 4703, "end_line": 4729, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 0 }, { "name": "Array_FromSequence", "long_name": "Array_FromSequence( PyObject * s , PyArray_Typecode * typecode , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 51, "complexity": 17, "token_count": 313, "parameters": [ "s", "typecode", "min_depth", "max_depth" ], "start_line": 4733, "end_line": 4790, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 58, "top_nesting_level": 0 }, { "name": "PyArray_ValidType", "long_name": "PyArray_ValidType( int type)", "filename": "arrayobject.c", "nloc": 7, "complexity": 2, "token_count": 30, "parameters": [ "type" ], "start_line": 4794, "end_line": 4801, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "_bufferedcast", "long_name": "_bufferedcast( PyArrayObject * out , PyArrayObject * in)", "filename": "arrayobject.c", "nloc": 75, "complexity": 16, "token_count": 477, "parameters": [ "out", "in" ], "start_line": 4807, "end_line": 4897, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 91, "top_nesting_level": 0 }, { "name": "PyArray_Cast", "long_name": "PyArray_Cast( PyArrayObject * mp , int type_num)", "filename": "arrayobject.c", "nloc": 10, "complexity": 1, "token_count": 56, "parameters": [ "mp", "type_num" ], "start_line": 4903, "end_line": 4914, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_CastToType", "long_name": "PyArray_CastToType( PyArrayObject * mp , PyArray_Typecode * at)", "filename": "arrayobject.c", "nloc": 31, "complexity": 13, "token_count": 233, "parameters": [ "mp", "at" ], "start_line": 4917, "end_line": 4952, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "PyArray_CastTo", "long_name": "PyArray_CastTo( PyArrayObject * out , PyArrayObject * mp)", "filename": "arrayobject.c", "nloc": 40, "complexity": 10, "token_count": 214, "parameters": [ "out", "mp" ], "start_line": 4959, "end_line": 5005, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "array_fromarray", "long_name": "array_fromarray( PyArrayObject * arr , PyArray_Typecode * typecode , int flags)", "filename": "arrayobject.c", "nloc": 116, "complexity": 35, "token_count": 721, "parameters": [ "arr", "typecode", "flags" ], "start_line": 5008, "end_line": 5139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 132, "top_nesting_level": 0 }, { "name": "_array_typecode_fromstr", "long_name": "_array_typecode_fromstr( char * str , int * swap , PyArray_Typecode * type)", "filename": "arrayobject.c", "nloc": 94, "complexity": 36, "token_count": 533, "parameters": [ "str", "swap", "type" ], "start_line": 5143, "end_line": 5248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 106, "top_nesting_level": 0 }, { "name": "array_frominterface", "long_name": "array_frominterface( PyObject * input , PyArray_Typecode * intype , int flags)", "filename": "arrayobject.c", "nloc": 113, "complexity": 26, "token_count": 715, "parameters": [ "input", "intype", "flags" ], "start_line": 5251, "end_line": 5374, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 124, "top_nesting_level": 0 }, { "name": "array_fromattr", "long_name": "array_fromattr( PyObject * op , PyArray_Typecode * typecode , int flags)", "filename": "arrayobject.c", "nloc": 30, "complexity": 5, "token_count": 181, "parameters": [ "op", "typecode", "flags" ], "start_line": 5377, "end_line": 5408, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "array_fromobject", "long_name": "array_fromobject( PyObject * op , PyArray_Typecode * typecode , int min_depth , int max_depth , int flags)", "filename": "arrayobject.c", "nloc": 49, "complexity": 14, "token_count": 291, "parameters": [ "op", "typecode", "min_depth", "max_depth", "flags" ], "start_line": 5412, "end_line": 5477, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 66, "top_nesting_level": 0 }, { "name": "PyArray_ArrayType", "long_name": "PyArray_ArrayType( PyObject * op , PyArray_Typecode * intype , PyArray_Typecode * outtype)", "filename": "arrayobject.c", "nloc": 6, "complexity": 1, "token_count": 29, "parameters": [ "op", "intype", "outtype" ], "start_line": 5480, "end_line": 5485, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "PyArray_ObjectType", "long_name": "PyArray_ObjectType( PyObject * op , int minimum_type)", "filename": "arrayobject.c", "nloc": 7, "complexity": 1, "token_count": 40, "parameters": [ "op", "minimum_type" ], "start_line": 5488, "end_line": 5494, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "PyArray_FromAny", "long_name": "PyArray_FromAny( PyObject * op , PyArray_Typecode * typecode , int min_depth , int max_depth , int requires)", "filename": "arrayobject.c", "nloc": 24, "complexity": 9, "token_count": 165, "parameters": [ "op", "typecode", "min_depth", "max_depth", "requires" ], "start_line": 5548, "end_line": 5578, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "PyArray_EnsureArray", "long_name": "PyArray_EnsureArray( PyObject * op)", "filename": "arrayobject.c", "nloc": 14, "complexity": 5, "token_count": 87, "parameters": [ "op" ], "start_line": 5589, "end_line": 5605, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "PyArray_FromObject", "long_name": "PyArray_FromObject( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 7, "complexity": 1, "token_count": 51, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5611, "end_line": 5617, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "PyArray_ContiguousFromObject", "long_name": "PyArray_ContiguousFromObject( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 8, "complexity": 1, "token_count": 51, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5620, "end_line": 5627, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_CopyFromObject", "long_name": "PyArray_CopyFromObject( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 8, "complexity": 1, "token_count": 51, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5630, "end_line": 5637, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_ContiguousFromAny", "long_name": "PyArray_ContiguousFromAny( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 8, "complexity": 1, "token_count": 49, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5642, "end_line": 5649, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_CanCastSafely", "long_name": "PyArray_CanCastSafely( int fromtype , int totype)", "filename": "arrayobject.c", "nloc": 81, "complexity": 39, "token_count": 476, "parameters": [ "fromtype", "totype" ], "start_line": 5652, "end_line": 5735, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 84, "top_nesting_level": 0 }, { "name": "PyArray_CanCastTo", "long_name": "PyArray_CanCastTo( PyArray_Typecode * from , PyArray_Typecode * to)", "filename": "arrayobject.c", "nloc": 24, "complexity": 7, "token_count": 134, "parameters": [ "from", "to" ], "start_line": 5738, "end_line": 5762, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 }, { "name": "PyArray_IterNew", "long_name": "PyArray_IterNew( PyObject * obj)", "filename": "arrayobject.c", "nloc": 34, "complexity": 6, "token_count": 258, "parameters": [ "obj" ], "start_line": 5772, "end_line": 5809, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "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": 5814, "end_line": 5824, "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": 6, "complexity": 1, "token_count": 25, "parameters": [ "it" ], "start_line": 5827, "end_line": 5832, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "arrayiter_traverse", "long_name": "arrayiter_traverse( PyArrayIterObject * it , visitproc visit , * arg)", "filename": "arrayobject.c", "nloc": 6, "complexity": 2, "token_count": 42, "parameters": [ "it", "visit", "arg" ], "start_line": 5835, "end_line": 5840, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "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": 5844, "end_line": 5847, "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": 42, "complexity": 7, "token_count": 272, "parameters": [ "self", "ind" ], "start_line": 5851, "end_line": 5899, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "iter_subscript_int", "long_name": "iter_subscript_int( PyArrayIterObject * self , PyArrayObject * ind)", "filename": "arrayobject.c", "nloc": 51, "complexity": 8, "token_count": 347, "parameters": [ "self", "ind" ], "start_line": 5902, "end_line": 5955, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 0 }, { "name": "iter_subscript", "long_name": "iter_subscript( PyArrayIterObject * self , PyObject * ind)", "filename": "arrayobject.c", "nloc": 97, "complexity": 20, "token_count": 593, "parameters": [ "self", "ind" ], "start_line": 5959, "end_line": 6078, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 120, "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": 176, "parameters": [ "self", "ind", "val", "swap" ], "start_line": 6082, "end_line": 6114, "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": 289, "parameters": [ "self", "ind", "val", "swap" ], "start_line": 6117, "end_line": 6159, "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": 103, "complexity": 24, "token_count": 636, "parameters": [ "self", "ind", "val" ], "start_line": 6163, "end_line": 6285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 123, "top_nesting_level": 0 }, { "name": "iter_array", "long_name": "iter_array( PyArrayIterObject * it , PyObject * op)", "filename": "arrayobject.c", "nloc": 30, "complexity": 5, "token_count": 221, "parameters": [ "it", "op" ], "start_line": 6298, "end_line": 6340, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "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": 6345, "end_line": 6349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "fancy_indexing_check", "long_name": "fancy_indexing_check( PyObject * args)", "filename": "arrayobject.c", "nloc": 55, "complexity": 22, "token_count": 293, "parameters": [ "args" ], "start_line": 6414, "end_line": 6475, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 62, "top_nesting_level": 0 }, { "name": "_convert_obj", "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", "filename": "arrayobject.c", "nloc": 15, "complexity": 5, "token_count": 105, "parameters": [ "obj", "iter" ], "start_line": 6483, "end_line": 6498, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "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": 6504, "end_line": 6573, "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": 261, "parameters": [ "mit" ], "start_line": 6577, "end_line": 6614, "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": 296, "parameters": [ "mit" ], "start_line": 6620, "end_line": 6664, "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": 102, "complexity": 22, "token_count": 690, "parameters": [ "mit", "arr" ], "start_line": 6682, "end_line": 6818, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 137, "top_nesting_level": 0 }, { "name": "_nonzero_indices", "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", "filename": "arrayobject.c", "nloc": 57, "complexity": 15, "token_count": 454, "parameters": [ "myBool", "iters" ], "start_line": 6824, "end_line": 6893, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 70, "top_nesting_level": 0 }, { "name": "PyArray_MapIterNew", "long_name": "PyArray_MapIterNew( PyObject * indexobj)", "filename": "arrayobject.c", "nloc": 111, "complexity": 24, "token_count": 745, "parameters": [ "indexobj" ], "start_line": 6896, "end_line": 7029, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 134, "top_nesting_level": 0 }, { "name": "arraymapiter_new", "long_name": "arraymapiter_new( PyTypeObject * type , PyObject * args , PyObject * kwds)", "filename": "arrayobject.c", "nloc": 26, "complexity": 5, "token_count": 130, "parameters": [ "type", "args", "kwds" ], "start_line": 7035, "end_line": 7065, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "arraymapiter_dealloc", "long_name": "arraymapiter_dealloc( PyArrayMapIterObject * mit)", "filename": "arrayobject.c", "nloc": 10, "complexity": 2, "token_count": 60, "parameters": [ "mit" ], "start_line": 7086, "end_line": 7095, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "arraymapiter_traverse", "long_name": "arraymapiter_traverse( PyArrayMapIterObject * mit , visitproc visit , * arg)", "filename": "arrayobject.c", "nloc": 16, "complexity": 9, "token_count": 146, "parameters": [ "mit", "visit", "arg" ], "start_line": 7098, "end_line": 7116, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 } ], "methods_before": [ { "name": "PyArray_PyIntAsIntp", "long_name": "PyArray_PyIntAsIntp( PyObject * o)", "filename": "arrayobject.c", "nloc": 59, "complexity": 19, "token_count": 385, "parameters": [ "o" ], "start_line": 40, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 64, "top_nesting_level": 0 }, { "name": "PyArray_PyIntAsInt", "long_name": "PyArray_PyIntAsInt( PyObject * o)", "filename": "arrayobject.c", "nloc": 57, "complexity": 19, "token_count": 389, "parameters": [ "o" ], "start_line": 109, "end_line": 169, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 61, "top_nesting_level": 0 }, { "name": "PyArray_GetPriority", "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", "filename": "arrayobject.c", "nloc": 17, "complexity": 5, "token_count": 86, "parameters": [ "obj", "default_" ], "start_line": 173, "end_line": 191, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "PyArray_Zero", "long_name": "PyArray_Zero( PyArrayObject * arr)", "filename": "arrayobject.c", "nloc": 34, "complexity": 6, "token_count": 190, "parameters": [ "arr" ], "start_line": 208, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "PyArray_One", "long_name": "PyArray_One( PyArrayObject * arr)", "filename": "arrayobject.c", "nloc": 40, "complexity": 7, "token_count": 222, "parameters": [ "arr" ], "start_line": 246, "end_line": 289, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "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": 295, "end_line": 345, "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": 368, "end_line": 399, "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": 213, "parameters": [ "src" ], "start_line": 402, "end_line": 436, "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": 449, "end_line": 471, "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": 474, "end_line": 495, "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": 499, "end_line": 537, "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": 542, "end_line": 562, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "index2ptr", "long_name": "index2ptr( PyArrayObject * mp , int i)", "filename": "arrayobject.c", "nloc": 10, "complexity": 7, "token_count": 86, "parameters": [ "mp", "i" ], "start_line": 570, "end_line": 580, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "PyArray_Size", "long_name": "PyArray_Size( PyObject * op)", "filename": "arrayobject.c", "nloc": 9, "complexity": 2, "token_count": 33, "parameters": [ "op" ], "start_line": 583, "end_line": 591, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "PyArray_CopyInto", "long_name": "PyArray_CopyInto( PyArrayObject * dest , PyArrayObject * src)", "filename": "arrayobject.c", "nloc": 71, "complexity": 16, "token_count": 427, "parameters": [ "dest", "src" ], "start_line": 604, "end_line": 684, "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": 16, "complexity": 2, "token_count": 98, "parameters": [ "dest", "src_object" ], "start_line": 688, "end_line": 707, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "PyArray_FromDimsAndDataAndDescr", "long_name": "PyArray_FromDimsAndDataAndDescr( int nd , int * d , PyArray_Descr * descr , char * data)", "filename": "arrayobject.c", "nloc": 15, "complexity": 3, "token_count": 121, "parameters": [ "nd", "d", "descr", "data" ], "start_line": 715, "end_line": 734, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "PyArray_FromDimsAndData", "long_name": "PyArray_FromDimsAndData( int nd , int * d , int type , char * data)", "filename": "arrayobject.c", "nloc": 14, "complexity": 3, "token_count": 112, "parameters": [ "nd", "d", "type", "data" ], "start_line": 738, "end_line": 755, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "PyArray_FromDims", "long_name": "PyArray_FromDims( int nd , int * d , int type)", "filename": "arrayobject.c", "nloc": 14, "complexity": 5, "token_count": 133, "parameters": [ "nd", "d", "type" ], "start_line": 759, "end_line": 776, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "PyArray_Copy", "long_name": "PyArray_Copy( PyArrayObject * m1)", "filename": "arrayobject.c", "nloc": 11, "complexity": 2, "token_count": 77, "parameters": [ "m1" ], "start_line": 782, "end_line": 794, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "PyArray_Scalar", "long_name": "PyArray_Scalar( char * data , int type_num , int itemsize , int swap)", "filename": "arrayobject.c", "nloc": 48, "complexity": 8, "token_count": 289, "parameters": [ "data", "type_num", "itemsize", "swap" ], "start_line": 800, "end_line": 849, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "top_nesting_level": 0 }, { "name": "PyArray_ToScalar", "long_name": "PyArray_ToScalar( char * data , PyArrayObject * arr)", "filename": "arrayobject.c", "nloc": 7, "complexity": 1, "token_count": 51, "parameters": [ "data", "arr" ], "start_line": 856, "end_line": 863, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_Return", "long_name": "PyArray_Return( PyArrayObject * mp)", "filename": "arrayobject.c", "nloc": 17, "complexity": 5, "token_count": 85, "parameters": [ "mp" ], "start_line": 869, "end_line": 888, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "PyArray_RegisterDataType", "long_name": "PyArray_RegisterDataType( PyTypeObject * type)", "filename": "arrayobject.c", "nloc": 31, "complexity": 6, "token_count": 177, "parameters": [ "type" ], "start_line": 899, "end_line": 931, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "PyArray_RegisterDescrForType", "long_name": "PyArray_RegisterDescrForType( int typenum , PyArray_Descr * descr)", "filename": "arrayobject.c", "nloc": 32, "complexity": 3, "token_count": 167, "parameters": [ "typenum", "descr" ], "start_line": 941, "end_line": 984, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "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": 16, "token_count": 577, "parameters": [ "self", "fp", "sep", "format" ], "start_line": 988, "end_line": 1079, "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": 24, "complexity": 5, "token_count": 151, "parameters": [ "self" ], "start_line": 1082, "end_line": 1110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "PyArray_ToString", "long_name": "PyArray_ToString( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 34, "complexity": 6, "token_count": 191, "parameters": [ "self" ], "start_line": 1113, "end_line": 1148, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "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": 1157, "end_line": 1194, "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": 1201, "end_line": 1209, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "array_item", "long_name": "array_item( PyArrayObject * self , int i)", "filename": "arrayobject.c", "nloc": 22, "complexity": 4, "token_count": 150, "parameters": [ "self", "i" ], "start_line": 1213, "end_line": 1237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "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": 26, "parameters": [ "self", "i" ], "start_line": 1240, "end_line": 1243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "array_ass_item", "long_name": "array_ass_item( PyArrayObject * self , int i , PyObject * v)", "filename": "arrayobject.c", "nloc": 27, "complexity": 8, "token_count": 177, "parameters": [ "self", "i", "v" ], "start_line": 1247, "end_line": 1277, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "slice_coerce_index", "long_name": "slice_coerce_index( PyObject * o , int * v)", "filename": "arrayobject.c", "nloc": 9, "complexity": 2, "token_count": 40, "parameters": [ "o", "v" ], "start_line": 1281, "end_line": 1289, "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 , int length , int * start , int * stop , int * step , intp * slicelength)", "filename": "arrayobject.c", "nloc": 45, "complexity": 24, "token_count": 376, "parameters": [ "r", "length", "start", "stop", "step", "slicelength" ], "start_line": 1295, "end_line": 1345, "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 , int * step_size , intp * n_steps , int max)", "filename": "arrayobject.c", "nloc": 45, "complexity": 11, "token_count": 223, "parameters": [ "op", "step_size", "n_steps", "max" ], "start_line": 1352, "end_line": 1397, "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": 89, "complexity": 20, "token_count": 540, "parameters": [ "self", "op", "dimensions", "strides", "offset_ptr" ], "start_line": 1401, "end_line": 1496, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 96, "top_nesting_level": 0 }, { "name": "_swap_axes", "long_name": "_swap_axes( PyArrayMapIterObject * mit , PyArrayObject ** ret)", "filename": "arrayobject.c", "nloc": 24, "complexity": 4, "token_count": 187, "parameters": [ "mit", "ret" ], "start_line": 1499, "end_line": 1533, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "PyArray_GetMap", "long_name": "PyArray_GetMap( PyArrayMapIterObject * mit)", "filename": "arrayobject.c", "nloc": 36, "complexity": 8, "token_count": 252, "parameters": [ "mit" ], "start_line": 1538, "end_line": 1587, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "top_nesting_level": 0 }, { "name": "PyArray_SetMap", "long_name": "PyArray_SetMap( PyArrayMapIterObject * mit , PyObject * op)", "filename": "arrayobject.c", "nloc": 50, "complexity": 12, "token_count": 392, "parameters": [ "mit", "op" ], "start_line": 1590, "end_line": 1649, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 60, "top_nesting_level": 0 }, { "name": "array_subscript", "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", "filename": "arrayobject.c", "nloc": 61, "complexity": 19, "token_count": 425, "parameters": [ "self", "op" ], "start_line": 1670, "end_line": 1745, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 76, "top_nesting_level": 0 }, { "name": "array_ass_sub", "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", "filename": "arrayobject.c", "nloc": 43, "complexity": 9, "token_count": 251, "parameters": [ "self", "index", "op" ], "start_line": 1758, "end_line": 1810, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "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": 1818, "end_line": 1821, "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": 1840, "end_line": 1852, "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": 1855, "end_line": 1870, "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": 1874, "end_line": 1883, "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": 1886, "end_line": 1897, "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": 1965, "end_line": 1998, "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": 2005, "end_line": 2044, "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": 23, "complexity": 5, "token_count": 136, "parameters": [ "m1", "op", "axis", "rtype" ], "start_line": 2047, "end_line": 2069, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "PyArray_GenericAccumulateFunction", "long_name": "PyArray_GenericAccumulateFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", "filename": "arrayobject.c", "nloc": 23, "complexity": 5, "token_count": 136, "parameters": [ "m1", "op", "axis", "rtype" ], "start_line": 2073, "end_line": 2095, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "PyArray_GenericBinaryFunction", "long_name": "PyArray_GenericBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", "filename": "arrayobject.c", "nloc": 12, "complexity": 2, "token_count": 69, "parameters": [ "m1", "m2", "op" ], "start_line": 2099, "end_line": 2110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_GenericUnaryFunction", "long_name": "PyArray_GenericUnaryFunction( PyArrayObject * m1 , PyObject * op)", "filename": "arrayobject.c", "nloc": 12, "complexity": 2, "token_count": 63, "parameters": [ "m1", "op" ], "start_line": 2113, "end_line": 2124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_GenericInplaceBinaryFunction", "long_name": "PyArray_GenericInplaceBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", "filename": "arrayobject.c", "nloc": 13, "complexity": 2, "token_count": 71, "parameters": [ "m1", "m2", "op" ], "start_line": 2127, "end_line": 2139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 2142, "end_line": 2145, "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": 2148, "end_line": 2151, "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": 2154, "end_line": 2157, "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": 2160, "end_line": 2163, "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": 2166, "end_line": 2169, "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": 2172, "end_line": 2175, "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": 2178, "end_line": 2181, "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": 2184, "end_line": 2187, "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": 2190, "end_line": 2193, "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": 2196, "end_line": 2199, "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": 2202, "end_line": 2205, "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": 2208, "end_line": 2211, "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": 2214, "end_line": 2217, "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": 2220, "end_line": 2223, "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": 2226, "end_line": 2229, "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": 2232, "end_line": 2235, "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": 2238, "end_line": 2241, "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": 2244, "end_line": 2247, "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": 2250, "end_line": 2253, "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": 2256, "end_line": 2259, "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": 2262, "end_line": 2265, "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": 2268, "end_line": 2271, "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": 2274, "end_line": 2277, "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": 2280, "end_line": 2283, "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": 2286, "end_line": 2289, "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": 2292, "end_line": 2295, "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": 2298, "end_line": 2301, "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": 2304, "end_line": 2308, "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": 2311, "end_line": 2315, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "array_all_nonzero", "long_name": "array_all_nonzero( PyArrayObject * mp)", "filename": "arrayobject.c", "nloc": 18, "complexity": 4, "token_count": 93, "parameters": [ "mp" ], "start_line": 2319, "end_line": 2337, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "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": 2340, "end_line": 2355, "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": 143, "parameters": [ "v" ], "start_line": 2359, "end_line": 2385, "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": 143, "parameters": [ "v" ], "start_line": 2388, "end_line": 2413, "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": 124, "parameters": [ "v" ], "start_line": 2416, "end_line": 2438, "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": 124, "parameters": [ "v" ], "start_line": 2441, "end_line": 2463, "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": 124, "parameters": [ "v" ], "start_line": 2466, "end_line": 2488, "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": 2491, "end_line": 2495, "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": 34, "complexity": 11, "token_count": 258, "parameters": [ "self", "ilow", "ihigh" ], "start_line": 2556, "end_line": 2594, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "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": 2598, "end_line": 2619, "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": 4, "complexity": 1, "token_count": 26, "parameters": [ "self", "el" ], "start_line": 2622, "end_line": 2627, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "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": 308, "parameters": [ "string", "n", "max_n", "data", "nd", "dimensions", "strides", "self" ], "start_line": 2648, "end_line": 2695, "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": 222, "parameters": [ "self" ], "start_line": 2698, "end_line": 2734, "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": 2740, "end_line": 2757, "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": 2760, "end_line": 2772, "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": 2775, "end_line": 2787, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "array_richcompare", "long_name": "array_richcompare( PyArrayObject * self , PyObject * other , int cmp_op)", "filename": "arrayobject.c", "nloc": 61, "complexity": 13, "token_count": 273, "parameters": [ "self", "other", "cmp_op" ], "start_line": 2791, "end_line": 2868, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 78, "top_nesting_level": 0 }, { "name": "_check_axis", "long_name": "_check_axis( PyArrayObject * arr , int * axis , int flags)", "filename": "arrayobject.c", "nloc": 29, "complexity": 8, "token_count": 164, "parameters": [ "arr", "axis", "flags" ], "start_line": 2871, "end_line": 2900, "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": 17, "complexity": 4, "token_count": 91, "parameters": [ "len", "vals" ], "start_line": 2906, "end_line": 2922, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "PyArray_IntpFromSequence", "long_name": "PyArray_IntpFromSequence( PyObject * seq , intp * vals , int maxvals)", "filename": "arrayobject.c", "nloc": 21, "complexity": 7, "token_count": 161, "parameters": [ "seq", "vals", "maxvals" ], "start_line": 2927, "end_line": 2950, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "_IsContiguous", "long_name": "_IsContiguous( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 14, "complexity": 6, "token_count": 109, "parameters": [ "ap" ], "start_line": 2956, "end_line": 2972, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_IsFortranContiguous", "long_name": "_IsFortranContiguous( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 14, "complexity": 6, "token_count": 107, "parameters": [ "ap" ], "start_line": 2976, "end_line": 2992, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_IsAligned", "long_name": "_IsAligned( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 14, "complexity": 4, "token_count": 110, "parameters": [ "ap" ], "start_line": 2995, "end_line": 3011, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_IsWriteable", "long_name": "_IsWriteable( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 16, "complexity": 8, "token_count": 109, "parameters": [ "ap" ], "start_line": 3014, "end_line": 3047, "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": 22, "complexity": 9, "token_count": 129, "parameters": [ "ret", "flagmask" ], "start_line": 3051, "end_line": 3073, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "PyArray_CheckStrides", "long_name": "PyArray_CheckStrides( int elsize , int nd , intp numbytes , intp * dims , intp * newstrides)", "filename": "arrayobject.c", "nloc": 13, "complexity": 4, "token_count": 84, "parameters": [ "elsize", "nd", "numbytes", "dims", "newstrides" ], "start_line": 3080, "end_line": 3095, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "_array_fill_strides", "long_name": "_array_fill_strides( intp * strides , intp * dims , int nd , intp itemsize , int inflag , int * objflags)", "filename": "arrayobject.c", "nloc": 24, "complexity": 9, "token_count": 171, "parameters": [ "strides", "dims", "nd", "itemsize", "inflag", "objflags" ], "start_line": 3115, "end_line": 3139, "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 , char * data , int itemsize , int flags , PyObject * obj)", "filename": "arrayobject.c", "nloc": 117, "complexity": 27, "token_count": 713, "parameters": [ "subtype", "nd", "dims", "type_num", "strides", "data", "itemsize", "flags", "obj" ], "start_line": 3143, "end_line": 3293, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 151, "top_nesting_level": 0 }, { "name": "PyArray_Resize", "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape)", "filename": "arrayobject.c", "nloc": 87, "complexity": 15, "token_count": 501, "parameters": [ "self", "newshape" ], "start_line": 3298, "end_line": 3403, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 106, "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": 3408, "end_line": 3425, "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": 47, "complexity": 7, "token_count": 261, "parameters": [ "arr", "obj" ], "start_line": 3428, "end_line": 3480, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "top_nesting_level": 0 }, { "name": "array_new", "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", "filename": "arrayobject.c", "nloc": 100, "complexity": 20, "token_count": 589, "parameters": [ "subtype", "args", "kwds" ], "start_line": 3483, "end_line": 3598, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 116, "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": 3605, "end_line": 3608, "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": 10, "complexity": 3, "token_count": 57, "parameters": [ "self" ], "start_line": 3611, "end_line": 3621, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "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": 3694, "end_line": 3697, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "array_shape_set", "long_name": "array_shape_set( PyArrayObject * self , PyObject * val)", "filename": "arrayobject.c", "nloc": 33, "complexity": 6, "token_count": 206, "parameters": [ "self", "val" ], "start_line": 3701, "end_line": 3735, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "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": 3739, "end_line": 3742, "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": 32, "complexity": 7, "token_count": 209, "parameters": [ "self", "obj" ], "start_line": 3745, "end_line": 3778, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "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": 3782, "end_line": 3789, "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": 3792, "end_line": 3800, "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": 3804, "end_line": 3810, "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": 3813, "end_line": 3827, "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": 3830, "end_line": 3874, "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": 19, "parameters": [ "self" ], "start_line": 3878, "end_line": 3881, "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": 8, "complexity": 3, "token_count": 45, "parameters": [ "self" ], "start_line": 3884, "end_line": 3891, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "array_typechar_get", "long_name": "array_typechar_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 8, "complexity": 2, "token_count": 47, "parameters": [ "self" ], "start_line": 3895, "end_line": 3902, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "array_typestr_get", "long_name": "array_typestr_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 19, "complexity": 7, "token_count": 141, "parameters": [ "self" ], "start_line": 3905, "end_line": 3925, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "array_descr_get", "long_name": "array_descr_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 19, "complexity": 5, "token_count": 128, "parameters": [ "self" ], "start_line": 3928, "end_line": 3950, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "array_type_get", "long_name": "array_type_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 4, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 3954, "end_line": 3957, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "array_type_set", "long_name": "array_type_set( PyArrayObject * self , PyObject * arg)", "filename": "arrayobject.c", "nloc": 41, "complexity": 10, "token_count": 294, "parameters": [ "self", "arg" ], "start_line": 3969, "end_line": 4027, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 59, "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": 4032, "end_line": 4042, "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": 4046, "end_line": 4071, "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": 31, "complexity": 4, "token_count": 177, "parameters": [ "self", "val" ], "start_line": 4075, "end_line": 4107, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "array_imag_get", "long_name": "array_imag_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 34, "complexity": 3, "token_count": 200, "parameters": [ "self" ], "start_line": 4110, "end_line": 4145, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "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": 203, "parameters": [ "self", "val" ], "start_line": 4148, "end_line": 4185, "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": 4188, "end_line": 4191, "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": 51, "complexity": 9, "token_count": 368, "parameters": [ "self", "val" ], "start_line": 4194, "end_line": 4248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 55, "top_nesting_level": 0 }, { "name": "discover_depth", "long_name": "discover_depth( PyObject * s , int max , int stop_at_string)", "filename": "arrayobject.c", "nloc": 23, "complexity": 14, "token_count": 169, "parameters": [ "s", "max", "stop_at_string" ], "start_line": 4423, "end_line": 4448, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "discover_itemsize", "long_name": "discover_itemsize( PyObject * s , int nd , int * itemsize)", "filename": "arrayobject.c", "nloc": 21, "complexity": 9, "token_count": 161, "parameters": [ "s", "nd", "itemsize" ], "start_line": 4451, "end_line": 4473, "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": 4480, "end_line": 4506, "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( int chktype , int mintype , int chksize , int minsize , PyArray_Typecode * outtype)", "filename": "arrayobject.c", "nloc": 19, "complexity": 5, "token_count": 100, "parameters": [ "chktype", "mintype", "chksize", "minsize", "outtype" ], "start_line": 4509, "end_line": 4529, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "_array_find_type", "long_name": "_array_find_type( PyObject * op , PyArray_Typecode * minitype , PyArray_Typecode * outtype , int max)", "filename": "arrayobject.c", "nloc": 126, "complexity": 28, "token_count": 671, "parameters": [ "op", "minitype", "outtype", "max" ], "start_line": 4532, "end_line": 4673, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 142, "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": 4676, "end_line": 4699, "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_Typecode * typecode)", "filename": "arrayobject.c", "nloc": 21, "complexity": 5, "token_count": 132, "parameters": [ "op", "typecode" ], "start_line": 4703, "end_line": 4729, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 0 }, { "name": "Array_FromSequence", "long_name": "Array_FromSequence( PyObject * s , PyArray_Typecode * typecode , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 51, "complexity": 17, "token_count": 313, "parameters": [ "s", "typecode", "min_depth", "max_depth" ], "start_line": 4733, "end_line": 4790, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 58, "top_nesting_level": 0 }, { "name": "PyArray_ValidType", "long_name": "PyArray_ValidType( int type)", "filename": "arrayobject.c", "nloc": 7, "complexity": 2, "token_count": 30, "parameters": [ "type" ], "start_line": 4794, "end_line": 4801, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "_bufferedcast", "long_name": "_bufferedcast( PyArrayObject * out , PyArrayObject * in)", "filename": "arrayobject.c", "nloc": 75, "complexity": 16, "token_count": 477, "parameters": [ "out", "in" ], "start_line": 4807, "end_line": 4897, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 91, "top_nesting_level": 0 }, { "name": "PyArray_Cast", "long_name": "PyArray_Cast( PyArrayObject * mp , int type_num)", "filename": "arrayobject.c", "nloc": 10, "complexity": 1, "token_count": 56, "parameters": [ "mp", "type_num" ], "start_line": 4903, "end_line": 4914, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_CastToType", "long_name": "PyArray_CastToType( PyArrayObject * mp , PyArray_Typecode * at)", "filename": "arrayobject.c", "nloc": 31, "complexity": 13, "token_count": 233, "parameters": [ "mp", "at" ], "start_line": 4917, "end_line": 4952, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "PyArray_CastTo", "long_name": "PyArray_CastTo( PyArrayObject * out , PyArrayObject * mp)", "filename": "arrayobject.c", "nloc": 40, "complexity": 10, "token_count": 214, "parameters": [ "out", "mp" ], "start_line": 4959, "end_line": 5005, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "array_fromarray", "long_name": "array_fromarray( PyArrayObject * arr , PyArray_Typecode * typecode , int flags)", "filename": "arrayobject.c", "nloc": 116, "complexity": 35, "token_count": 721, "parameters": [ "arr", "typecode", "flags" ], "start_line": 5008, "end_line": 5139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 132, "top_nesting_level": 0 }, { "name": "_array_typecode_fromstr", "long_name": "_array_typecode_fromstr( char * str , int * swap , PyArray_Typecode * type)", "filename": "arrayobject.c", "nloc": 94, "complexity": 36, "token_count": 533, "parameters": [ "str", "swap", "type" ], "start_line": 5143, "end_line": 5248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 106, "top_nesting_level": 0 }, { "name": "array_frominterface", "long_name": "array_frominterface( PyObject * input , PyArray_Typecode * intype , int flags)", "filename": "arrayobject.c", "nloc": 113, "complexity": 26, "token_count": 715, "parameters": [ "input", "intype", "flags" ], "start_line": 5251, "end_line": 5374, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 124, "top_nesting_level": 0 }, { "name": "array_fromattr", "long_name": "array_fromattr( PyObject * op , PyArray_Typecode * typecode , int flags)", "filename": "arrayobject.c", "nloc": 30, "complexity": 5, "token_count": 181, "parameters": [ "op", "typecode", "flags" ], "start_line": 5377, "end_line": 5408, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "array_fromobject", "long_name": "array_fromobject( PyObject * op , PyArray_Typecode * typecode , int min_depth , int max_depth , int flags)", "filename": "arrayobject.c", "nloc": 49, "complexity": 14, "token_count": 291, "parameters": [ "op", "typecode", "min_depth", "max_depth", "flags" ], "start_line": 5412, "end_line": 5477, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 66, "top_nesting_level": 0 }, { "name": "PyArray_ArrayType", "long_name": "PyArray_ArrayType( PyObject * op , PyArray_Typecode * intype , PyArray_Typecode * outtype)", "filename": "arrayobject.c", "nloc": 6, "complexity": 1, "token_count": 29, "parameters": [ "op", "intype", "outtype" ], "start_line": 5480, "end_line": 5485, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "PyArray_ObjectType", "long_name": "PyArray_ObjectType( PyObject * op , int minimum_type)", "filename": "arrayobject.c", "nloc": 7, "complexity": 1, "token_count": 40, "parameters": [ "op", "minimum_type" ], "start_line": 5488, "end_line": 5494, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "PyArray_FromAny", "long_name": "PyArray_FromAny( PyObject * op , PyArray_Typecode * typecode , int min_depth , int max_depth , int requires)", "filename": "arrayobject.c", "nloc": 24, "complexity": 9, "token_count": 165, "parameters": [ "op", "typecode", "min_depth", "max_depth", "requires" ], "start_line": 5548, "end_line": 5578, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "PyArray_EnsureArray", "long_name": "PyArray_EnsureArray( PyObject * op)", "filename": "arrayobject.c", "nloc": 14, "complexity": 5, "token_count": 87, "parameters": [ "op" ], "start_line": 5589, "end_line": 5605, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "PyArray_FromObject", "long_name": "PyArray_FromObject( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 7, "complexity": 1, "token_count": 51, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5611, "end_line": 5617, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "PyArray_ContiguousFromObject", "long_name": "PyArray_ContiguousFromObject( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 8, "complexity": 1, "token_count": 51, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5620, "end_line": 5627, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_CopyFromObject", "long_name": "PyArray_CopyFromObject( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 8, "complexity": 1, "token_count": 51, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5630, "end_line": 5637, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_ContiguousFromAny", "long_name": "PyArray_ContiguousFromAny( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 8, "complexity": 1, "token_count": 49, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5642, "end_line": 5649, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_CanCastSafely", "long_name": "PyArray_CanCastSafely( int fromtype , int totype)", "filename": "arrayobject.c", "nloc": 81, "complexity": 39, "token_count": 476, "parameters": [ "fromtype", "totype" ], "start_line": 5652, "end_line": 5735, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 84, "top_nesting_level": 0 }, { "name": "PyArray_CanCastTo", "long_name": "PyArray_CanCastTo( PyArray_Typecode * from , PyArray_Typecode * to)", "filename": "arrayobject.c", "nloc": 24, "complexity": 7, "token_count": 134, "parameters": [ "from", "to" ], "start_line": 5738, "end_line": 5762, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 }, { "name": "PyArray_IterNew", "long_name": "PyArray_IterNew( PyObject * obj)", "filename": "arrayobject.c", "nloc": 34, "complexity": 6, "token_count": 258, "parameters": [ "obj" ], "start_line": 5772, "end_line": 5809, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "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": 5814, "end_line": 5824, "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": 6, "complexity": 1, "token_count": 25, "parameters": [ "it" ], "start_line": 5827, "end_line": 5832, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "arrayiter_traverse", "long_name": "arrayiter_traverse( PyArrayIterObject * it , visitproc visit , * arg)", "filename": "arrayobject.c", "nloc": 6, "complexity": 2, "token_count": 42, "parameters": [ "it", "visit", "arg" ], "start_line": 5835, "end_line": 5840, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "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": 5844, "end_line": 5847, "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": 42, "complexity": 7, "token_count": 272, "parameters": [ "self", "ind" ], "start_line": 5851, "end_line": 5899, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "iter_subscript_int", "long_name": "iter_subscript_int( PyArrayIterObject * self , PyArrayObject * ind)", "filename": "arrayobject.c", "nloc": 51, "complexity": 8, "token_count": 347, "parameters": [ "self", "ind" ], "start_line": 5902, "end_line": 5955, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 0 }, { "name": "iter_subscript", "long_name": "iter_subscript( PyArrayIterObject * self , PyObject * ind)", "filename": "arrayobject.c", "nloc": 97, "complexity": 20, "token_count": 593, "parameters": [ "self", "ind" ], "start_line": 5959, "end_line": 6078, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 120, "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": 176, "parameters": [ "self", "ind", "val", "swap" ], "start_line": 6082, "end_line": 6114, "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": 289, "parameters": [ "self", "ind", "val", "swap" ], "start_line": 6117, "end_line": 6159, "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": 103, "complexity": 24, "token_count": 636, "parameters": [ "self", "ind", "val" ], "start_line": 6163, "end_line": 6285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 123, "top_nesting_level": 0 }, { "name": "iter_array", "long_name": "iter_array( PyArrayIterObject * it , PyObject * op)", "filename": "arrayobject.c", "nloc": 30, "complexity": 5, "token_count": 221, "parameters": [ "it", "op" ], "start_line": 6298, "end_line": 6340, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "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": 6345, "end_line": 6349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "fancy_indexing_check", "long_name": "fancy_indexing_check( PyObject * args)", "filename": "arrayobject.c", "nloc": 55, "complexity": 22, "token_count": 293, "parameters": [ "args" ], "start_line": 6414, "end_line": 6475, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 62, "top_nesting_level": 0 }, { "name": "_convert_obj", "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", "filename": "arrayobject.c", "nloc": 15, "complexity": 5, "token_count": 105, "parameters": [ "obj", "iter" ], "start_line": 6483, "end_line": 6498, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "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": 6504, "end_line": 6573, "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": 261, "parameters": [ "mit" ], "start_line": 6577, "end_line": 6614, "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": 296, "parameters": [ "mit" ], "start_line": 6620, "end_line": 6664, "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": 102, "complexity": 22, "token_count": 690, "parameters": [ "mit", "arr" ], "start_line": 6682, "end_line": 6818, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 137, "top_nesting_level": 0 }, { "name": "_nonzero_indices", "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", "filename": "arrayobject.c", "nloc": 57, "complexity": 15, "token_count": 454, "parameters": [ "myBool", "iters" ], "start_line": 6824, "end_line": 6893, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 70, "top_nesting_level": 0 }, { "name": "PyArray_MapIterNew", "long_name": "PyArray_MapIterNew( PyObject * indexobj)", "filename": "arrayobject.c", "nloc": 111, "complexity": 24, "token_count": 745, "parameters": [ "indexobj" ], "start_line": 6896, "end_line": 7029, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 134, "top_nesting_level": 0 }, { "name": "arraymapiter_new", "long_name": "arraymapiter_new( PyTypeObject * type , PyObject * args , PyObject * kwds)", "filename": "arrayobject.c", "nloc": 26, "complexity": 5, "token_count": 130, "parameters": [ "type", "args", "kwds" ], "start_line": 7035, "end_line": 7065, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "arraymapiter_dealloc", "long_name": "arraymapiter_dealloc( PyArrayMapIterObject * mit)", "filename": "arrayobject.c", "nloc": 10, "complexity": 2, "token_count": 60, "parameters": [ "mit" ], "start_line": 7086, "end_line": 7095, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "arraymapiter_traverse", "long_name": "arraymapiter_traverse( PyArrayMapIterObject * mit , visitproc visit , * arg)", "filename": "arrayobject.c", "nloc": 16, "complexity": 9, "token_count": 146, "parameters": [ "mit", "visit", "arg" ], "start_line": 7098, "end_line": 7116, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "array_size_get", "long_name": "array_size_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 8, "complexity": 3, "token_count": 42, "parameters": [ "self" ], "start_line": 3884, "end_line": 3891, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 } ], "nloc": 5643, "complexity": 1233, "token_count": 33722, "diff_parsed": { "added": [ "\t\treturn PyLong_FromLongLong(size);" ], "deleted": [ "\t\treturn PyLong_FromLongLong((longlong) size);" ] } } ] }, { "hash": "83643d12f617983314c277505802789d1542928d", "msg": "Fixes to array_ass_item and array_item so that other uses of these besides the sequence protocol work for 64-bit systems.", "author": { "name": "Travis Oliphant", "email": "oliphant@enthought.com" }, "committer": { "name": "Travis Oliphant", "email": "oliphant@enthought.com" }, "author_date": "2005-10-26T05:43:29+00:00", "author_timezone": 0, "committer_date": "2005-10-26T05:43:29+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "c001bbef5637bdf8f625cf4ab5f32521aa7dac17" ], "project_name": "repo_copy", "project_path": "/tmp/tmpn4cqam_6/repo_copy", "deletions": 20, "insertions": 33, "lines": 53, "files": 1, "dmm_unit_size": 0.6666666666666666, "dmm_unit_complexity": 0.6666666666666666, "dmm_unit_interfacing": 0.16666666666666666, "modified_files": [ { "old_path": "scipy/base/src/arrayobject.c", "new_path": "scipy/base/src/arrayobject.c", "filename": "arrayobject.c", "extension": "c", "change_type": "MODIFY", "diff": "@@ -567,7 +567,7 @@ copy_and_swap(void *dst, void *src, int itemsize, intp numitems,\n #include \"arraytypes.inc\"\n \n static char *\n-index2ptr(PyArrayObject *mp, int i) \n+index2ptr(PyArrayObject *mp, intp i) \n {\n \tif (i==0 && (mp->nd == 0 || mp->dimensions[0] > 0)) \n \t\treturn mp->data;\n@@ -794,7 +794,7 @@ PyArray_Copy(PyArrayObject *m1)\n }\n \n \n-static PyObject *array_item(PyArrayObject *, int);\n+static PyObject *array_big_item(PyArrayObject *, intp);\n \n static PyObject *\n PyArray_Scalar(char *data, int type_num, int itemsize, int swap)\n@@ -1094,7 +1094,7 @@ PyArray_ToList(PyArrayObject *self)\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@@ -1210,19 +1210,19 @@ array_length(PyArrayObject *self)\n \n \n static PyObject *\n-array_item(PyArrayObject *self, int i) \n+array_big_item(PyArrayObject *self, intp i) \n {\n- char *item;\n- PyArrayObject *r;\n-\n-\n+\tchar *item;\n+\tPyArrayObject *r;\n+\t\n+\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-\n+\t\n \tr = (PyArrayObject *)PyArray_New(self->ob_type, \n \t\t\t\t\t self->nd-1, self->dimensions+1, \n \t\t\t\t\t self->descr->type_num, \n@@ -1239,12 +1239,12 @@ array_item(PyArrayObject *self, int i)\n static PyObject *\n array_item_nice(PyArrayObject *self, int i) \n {\n-\treturn PyArray_Return((PyArrayObject *)array_item(self, i));\n+\treturn PyArray_Return((PyArrayObject *)array_big_item(self, (intp) i));\n }\n \n \n static int \n-array_ass_item(PyArrayObject *self, int i, PyObject *v) \n+array_ass_big_item(PyArrayObject *self, intp i, PyObject *v) \n {\n PyArrayObject *tmp;\n char *item;\n@@ -1264,7 +1264,7 @@ array_ass_item(PyArrayObject *self, int i, PyObject *v)\n if (i < 0) i = i+self->dimensions[0];\n \n if (self->nd > 1) {\n- if((tmp = (PyArrayObject *)array_item(self, i)) == NULL)\n+ if((tmp = (PyArrayObject *)array_big_item(self, i)) == NULL)\n return -1;\n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n@@ -1276,6 +1276,17 @@ array_ass_item(PyArrayObject *self, int i, PyObject *v)\n return 0;\n }\n \n+#if SIZEOF_INT == SIZEOF_INTP\n+#define array_ass_item array_ass_big_item\n+#else\n+static int\n+array_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 /* -------------------------------------------------------------- */\n static int\n slice_coerce_index(PyObject *o, int *v)\n@@ -1671,7 +1682,8 @@ array_subscript(PyArrayObject *self, PyObject *op)\n {\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n \tintp offset;\n- int nd, i;\n+ int nd;\n+\tintp i;\n PyArrayObject *other;\n \tPyArrayMapIterObject *mit;\n \n@@ -1683,12 +1695,12 @@ array_subscript(PyArrayObject *self, PyObject *op)\n PyErr_Clear();\n else if (value >= 0) {\n if (value <= MAX_INT)\n- return array_item(self, (int) value);\n+ return array_big_item(self, value);\n }\n else if (value < 0) {\n if (value >= -MAX_INT) {\n if (self->nd > 0) value += self->dimensions[0];\n- return array_item(self, (int) value);\n+ return array_big_item(self, value);\n }\n }\n }\n@@ -1715,10 +1727,10 @@ array_subscript(PyArrayObject *self, PyObject *op)\n \t\tPy_DECREF(mit);\n \t}\n \n-\ti = PyArray_PyIntAsInt(op);\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_item(self, i);\n+\t\treturn array_big_item(self, i);\n \t}\n \tPyErr_Clear();\n \n@@ -1757,7 +1769,8 @@ array_subscript(PyArrayObject *self, PyObject *op)\n static int \n array_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op) \n {\n- int ret, i;\n+ int ret;\n+\tintp i;\n PyArrayObject *tmp;\n \tPyArrayMapIterObject *mit;\n \t\n@@ -1793,9 +1806,9 @@ array_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op)\n \t\tPy_DECREF((PyObject*)mit);\n \t}\n \n-\ti = PyArray_PyIntAsInt(index);\n+\ti = PyArray_PyIntAsIntp(index);\n \tif (!error_converting(i)) {\n-\t\treturn array_ass_item(self, i, op);\n+\t\treturn array_ass_big_item(self, i, op);\n \t}\n \tPyErr_Clear();\n \t\n", "added_lines": 33, "deleted_lines": 20, "source_code": " /*\n Provide multidimensional arrays as a basic object type in python. \n\nBased on Original Numeric implementation\nCopyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\nwith contributions from many Numeric Python developers 1995-2004 *\n\nHeavily modified in 2005 with inspiration from Numarray \n\nby\n\nTravis Oliphant\nAssistant Professor at\nBrigham Young University \n\nmaintainer email: oliphant.travis@ieee.org\n\nNumarray design (which provided guidance) by \nSpace Science Telescope Institute \n (J. Todd Miller, Perry Greenfield, Rick White)\n\n*/\n\n/* $Id: arrayobject.c,v 1.59 2005/09/14 00:14:00 teoliphant Exp $ */\n\n/*\n#include \"Python.h\"\n#include \"structmember.h\"\n\n#define _MULTIARRAYMODULE\n#include \"Numeric3/arrayobject.h\"\n*/\n\n/* Helper functions */\n\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\n\nstatic intp\nPyArray_PyIntAsIntp(PyObject *o)\n{\n\tlonglong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr=NULL;\n\tPyArray_Typecode typecode = {PyArray_INTP, 0, 0};\n\tintp ret;\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\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\tarr = PyArray_CastToType((PyArrayObject *)o, &typecode);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tarr = PyArray_FromScalar(o, &typecode);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((intp *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\t\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONGLONG != SIZEOF_PY_INTPTR_T)\n\tif ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C intp\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (intp) long_value;\n}\n\n\nstatic PyObject *array_int(PyArrayObject *v);\n\nstatic int\nPyArray_PyIntAsInt(PyObject *o)\n{\n\tlong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr=NULL;\n\tPyArray_Typecode typecode = {PyArray_INT, 0, 0};\n\tint ret;\n\t\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\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\tarr = PyArray_CastToType((PyArrayObject *)o, &typecode);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tarr = PyArray_FromScalar(o, &typecode);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((int *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONG != SIZEOF_INT)\n\tif ((long_value < INT_MIN) || (long_value > INT_MAX)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C int\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (int) long_value;\n}\n\n\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\nstatic char *\nPyArray_Zero(PyArrayObject *arr)\n{\n char *zeroval;\n char *buf;\n int buf_len;\n PyObject *obj, *ret;\n\n zeroval = PyDataMem_NEW(arr->itemsize);\n if (zeroval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n if (PyArray_ISOBJECT(arr)) {\n obj=PyInt_FromLong((long) 0);\n memcpy(zeroval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return zeroval;\n }\n ret = PyObject_GetAttrString((PyObject *)arr, \"_zero\");\n if (ret != NULL) {\n if (PyObject_AsReadBuffer(ret, (const void **)&buf, \n &buf_len) < 0) {\n PyErr_SetString(PyExc_ValueError, \n \"_zero not returning \" \\\n \"writeable buffer\");\n Py_DECREF(ret);\n return NULL;\n }\n memcpy(zeroval, buf, buf_len);\n Py_DECREF(ret);\n }\n if (PyErr_Occurred()) PyErr_Clear();\n memset(zeroval, 0, arr->itemsize);\n return zeroval;\n}\n\nstatic char *\nPyArray_One(PyArrayObject *arr)\n{\n char *oneval;\n char *buf;\n int buf_len, ret2;\n PyObject *obj, *ret;\n\n oneval = PyDataMem_NEW(arr->itemsize);\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 ret = PyObject_GetAttrString((PyObject *)arr, \"_one\");\n if (ret != NULL) {\n if (PyObject_AsReadBuffer(ret, (const void **)&buf, \n &buf_len) < 0) {\n PyErr_SetString(PyExc_ValueError, \n \"_one not returning \" \\\n \"writeable buffer\");\n Py_DECREF(ret);\n PyDataMem_FREE(oneval);\n return NULL;\n }\n memcpy(oneval, buf, buf_len);\n Py_DECREF(ret);\n }\n if (PyErr_Occurred()) PyErr_Clear();\n\n ret2 = arr->descr->setitem(obj, oneval, arr);\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->itemsize;\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 *)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 { free(new_data); return NULL; }\n}\n\n/* end Helper functions */\n\n\nstatic PyObject *PyArray_New(PyTypeObject *, int nd, intp *, \n int, intp *, char *, 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. */\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/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\n\nstatic char *\nindex2ptr(PyArrayObject *mp, intp i) \n{\n\tif (i==0 && (mp->nd == 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\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\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->copyswap;\n\tcopyswapn = dest->descr->copyswapn;\n\n elsize = dest->itemsize;\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->itemsize;\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\tPyArray_Typecode typecode;\n\n\n\ttypecode.type_num = dest->descr->type_num;\n\ttypecode.itemsize = dest->itemsize;\n\ttypecode.fortran = PyArray_ISFORTRAN(dest);\n\t\t\t\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n\t\t\t\t\t &typecode, 0,\n\t\t\t\t\t dest->nd, 0);\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\nstatic PyObject *\nPyArray_FromDimsAndDataAndDescr(int nd, int *d, \n PyArray_Descr *descr,\n char *data) {\n\tPyObject *ret;\n\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\n\tintp newd[MAX_DIMS];\n\t\n\tfor (i=0; itype_num, NULL, data, descr->elsize, \n\t\t\t CARRAY_FLAGS, NULL);\n#else\n\tret = PyArray_New(&PyArray_Type, nd, (intp *)d, \n descr->type_num, NULL, data, descr->elsize, \n\t\t\t CARRAY_FLAGS, NULL);\n#endif\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_FromDimsAndData(int nd, int *d, int type, char *data) \n{\n\tPyObject *ret;\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\t\n\tintp newd[MAX_DIMS];\n\n\tfor (i=0; iob_type, m1->nd, \n\t\t\t\t\t m1->dimensions,\n\t\t\t\t\t m1->descr->type_num,\n\t\t\t\t\t NULL, NULL, m1->itemsize,\n\t\t\t\t\t 0, (PyObject *)m1);\n\t\n if (PyArray_CopyInto(ret, m1) == -1) return NULL;\n\t\n return (PyObject *)ret;\n}\n\n\nstatic PyObject *array_big_item(PyArrayObject *, intp);\n\nstatic PyObject *\nPyArray_Scalar(char *data, int type_num, int itemsize, int swap)\n{\n PyArray_Descr *descr;\n\tPyTypeObject *type;\n\tPyObject *obj;\t\n\tchar *destptr;\n PyArray_CopySwapFunc *copyswap;\n\n descr = PyArray_DescrFromType(type_num);\n if (descr == NULL) return NULL;\n type = descr->typeobj;\n copyswap = descr->copyswap;\n\tif (type_num == PyArray_STRING) \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_ISFLEXIBLE(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 {\n\t\t\tdestptr = PyDataMem_NEW(itemsize);\n\t\t\tif (destptr == NULL) {\n\t\t\t\tPyObject_Del(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tif (type_num == PyArray_UNICODE) {\n\t\t\t\tPyUnicode_AS_UNICODE(obj) = \\\n\t\t\t\t\t(Py_UNICODE *)destptr;\n\t\t\t\t((PyUnicodeObject*)obj)->length = itemsize / \\\n\t\t\t\t\tsizeof(Py_UNICODE);\n\t\t\t\t((PyUnicodeObject*)obj)->hash = -1;\n\t\t\t}\n\t\t\telse {\n\t\t\t\t((PyVoidScalarObject *)obj)->obval = destptr;\n\t\t\t\t((PyVoidScalarObject *)obj)->ob_size = itemsize;\n\t\t\t}\n\t\t}\n\t}\n\telse {\n\t\tdestptr = &(((PyScalarObject*)obj)->obval);\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*/\nstatic PyObject *\nPyArray_ToScalar(char *data, PyArrayObject *arr)\n{\n\tint type_num = arr->descr->type_num;\n\tint itemsize = arr->itemsize;\n int swap = !(PyArray_ISNOTSWAPPED(arr));\n\n\treturn PyArray_Scalar(data, type_num, itemsize, swap);\n}\n\n\n/* Return Python scalar if 0-d array object is encountered */\n\nstatic PyObject *\nPyArray_Return(PyArrayObject *mp) \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((PyObject *)mp) && 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*/\nstatic int \nPyArray_RegisterDataType(PyTypeObject *type)\n{\n\tPyArray_Descr *descr;\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 = malloc(sizeof(PyArray_Descr));\n\tmemcpy(descr, PyArray_DescrFromType(PyArray_VOID), \n\t sizeof(PyArray_Descr));\n\ttypenum = PyArray_USERDEF + PyArray_NUMUSERTYPES;\n\tdescr->type_num = typenum;\n\tdescr->typeobj = 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 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 frees the copy of the Descr_table already there.\n places a pointer to the new one into the slot.\n*/\nstatic int\nPyArray_RegisterDescrForType(int typenum, PyArray_Descr *descr)\n{\n\tPyArray_Descr *old;\n\tint i;\n\n\tif (!PyTypeNum_ISUSERDEF(typenum)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"data type not registered\");\n\t\treturn -1;\n\t}\n\told = userdescrs[typenum-PyArray_USERDEF];\n\tdescr->typeobj = old->typeobj;\n\tdescr->type_num = typenum;\n\n#define _NULL_CHECK(member) \\\n\tif (descr->member == NULL) descr->member = old->member\n\n\tfor (i=0; imember == 0) descr->member = old->member\n\n\t_ZERO_CHECK(kind);\n\t_ZERO_CHECK(type);\n\t_ZERO_CHECK(elsize);\n\t_ZERO_CHECK(alignment);\n#undef _ZERO_CHECK\n\n\tfree(old);\n\tuserdescrs[typenum-PyArray_USERDEF] = descr;\n\treturn 0;\n}\n\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 n3 = strlen((const char *)sep);\n if (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 \"\\\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->itemsize,\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->itemsize,\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 = strlen((const char *)format);\n while(it->index < it->size) {\n obj = self->descr->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\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->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\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 if (PyArray_TYPE(self) == PyArray_OBJECT) {\n PyErr_SetString(PyExc_ValueError, \"a string for the data\"\\\n\t\t\t\t\"in an object array is not appropriate\");\n return NULL;\n }\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->itemsize;\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 != NULL)) {\n\t\t/* Free internal references if an Object array */\n\t\tPyArray_XDECREF(self);\n\n PyDataMem_FREE(self->data);\n }\n\t\n if (self->dimensions != NULL) {\n PyDimMem_FREE(self->dimensions); \n\t}\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\n\nstatic PyObject *\narray_big_item(PyArrayObject *self, intp i) \n{\n\tchar *item;\n\tPyArrayObject *r;\n\t\n\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\tr = (PyArrayObject *)PyArray_New(self->ob_type, \n\t\t\t\t\t self->nd-1, self->dimensions+1, \n\t\t\t\t\t self->descr->type_num, \n\t\t\t\t\t self->strides+1, item, \n\t\t\t\t\t self->itemsize, self->flags,\n\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\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->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, int *v)\n{\n\t*v = PyArray_PyIntAsInt(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, int length,\n int *start, int *stop, int *step,\n intp *slicelength)\n{\n\tint 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 int\nparse_subindex(PyObject *op, int *step_size, intp *n_steps, int max)\n{\n\tint 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\tint 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_PyIntAsInt(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, start, offset, n_add, n_pseudo;\n int step_size;\n\tintp n_steps;\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, *tup;\n\tint n1, n2, n3, val;\n\tint i;\n\n\ttup = PyTuple_New(mit->nd);\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\tPyTuple_SET_ITEM(tup, i++, PyInt_FromLong((long)val++));\n\tval = 0;\n\twhile(val < n1)\n\t\tPyTuple_SET_ITEM(tup, i++, PyInt_FromLong((long)val++));\n\tval = n1+n2;\n\twhile(val < n3)\n\t\tPyTuple_SET_ITEM(tup, i++, PyInt_FromLong((long)val++));\n\n\tnew = PyArray_Transpose(*ret, tup);\n\tPy_DECREF(tup);\n\tPy_DECREF(*ret);\n\t*ret = (PyArrayObject *)new;\n}\n\n\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\tret = (PyArrayObject *)\\\n\t\tPyArray_New(temp->ob_type, mit->nd, mit->dimensions, \n\t\t\t temp->descr->type_num, NULL, NULL, \n\t\t\t temp->itemsize, \n\t\t\t PyArray_ISFORTRAN(temp),\n\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\treturn NULL;\n\tindex = it->size;\n\tswap = ((temp->flags & NOTSWAPPED) != (ret->flags & NOTSWAPPED));\n copyswap = ret->descr->copyswap;\n\tPyArray_MapIterReset(mit);\n\twhile (index--) {\n copyswap(it->dataptr, mit->dataptr, swap, ret->itemsize);\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\tPyArray_Typecode typecode = {0, 0, 0};\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Unbound Map Iterator */\n\tif (mit->ait == NULL) return -1;\n\n\ttypecode.type_num = mit->ait->ao->descr->type_num;\n\ttypecode.itemsize = mit->ait->ao->itemsize;\n\n\tarr = PyArray_FromAny(op, &typecode, \n\t\t\t 0, 0, FORCECAST);\n\tif (arr == NULL) return -1;\n\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, (PyArrayObject **)&arr);\n\t\t}\n\t}\n\t\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) \n\t\treturn -1;\n\n\tindex = mit->size;\n\tswap = ((mit->ait->ao->flags & NOTSWAPPED) != \\\n\t\t(PyArray_FLAGS(arr) & NOTSWAPPED));\n\n copyswap = PyArray_DESCR(arr)->copyswap;\n\tPyArray_MapIterReset(mit);\n /* Need to decref OBJECT arrays */\n if (PyTypeNum_ISOBJECT(typecode.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 copyswap(mit->dataptr, NULL, swap, \n sizeof(PyObject *));\n PyArray_MapIterNext(mit);\n PyArray_ITER_NEXT(it);\n if (it->index == it->size)\n PyArray_ITER_RESET(it);\n }\n return 0;\n }\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\treturn 0;\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 0-dimensional arrays */\n\nstatic PyObject *\narray_subscript(PyArrayObject *self, PyObject *op) \n{\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n\tintp offset;\n int nd;\n\tintp i;\n PyArrayObject *other;\n\tPyArrayMapIterObject *mit;\n\n if (PyArray_IsScalar(op, Integer) || PyInt_Check(op) || \\\n PyLong_Check(op)) {\n intp value;\n value = PyArray_PyIntAsIntp(op);\n if (PyErr_Occurred())\n PyErr_Clear();\n else if (value >= 0) {\n if (value <= MAX_INT)\n return array_big_item(self, value);\n }\n else if (value < 0) {\n if (value >= -MAX_INT) {\n if (self->nd > 0) value += self->dimensions[0];\n return array_big_item(self, value);\n }\n }\n }\n\n\tif (PyArrayMapIter_Check(op)) {\n\t\tmit = (PyArrayMapIterObject *)op;\n\t\t/* bind to current array */\n\t\tPyArray_MapIterBind(mit, self);\n\t\t\n\t\t/* If the mapiterator was created with standard indexing\n\t\t behavior, fall through to view-based code */\n\t\tif (!mit->view) return PyArray_GetMap(mit);\n\t\top = mit->indexobj;\n\t}\n\telse { /* wrap arguments into a mapiter object */\n\t\tmit = (PyArrayMapIterObject *)PyArray_MapIterNew(op);\n\t\tif (mit == NULL) return NULL;\n\t\tif (!mit->view) { /* fancy indexing */\n\t\t\tPyArray_MapIterBind(mit, self);\n\t\t\tother = (PyArrayObject *)PyArray_GetMap(mit);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn (PyObject *)other;\n\t\t}\n\t\tPy_DECREF(mit);\n\t}\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\tif ((other = (PyArrayObject *)\t\t\t\t\t\\\n\t PyArray_New(self->ob_type, nd, dimensions, self->descr->type_num,\n\t\t\t strides, self->data+offset, \n\t\t\t self->itemsize, self->flags,\n\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 \narray_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op) \n{\n int ret;\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\n\tif (PyArrayMapIter_Check(index)) {\n\t\tmit = (PyArrayMapIterObject *)index;\n\t\t/* bind behavior to current array */\n\t\tPyArray_MapIterBind(mit, self);\n\t\t\t\n\t\t/* fall through if standard view-based map iterator */\n\t\tif (!mit->view) return PyArray_SetMap(mit, op);\n\t\tindex = mit->indexobj;\n\t}\n\telse {\n\t\tmit = (PyArrayMapIterObject *)PyArray_MapIterNew(index);\n\t\tif (mit == NULL) return -1;\n\t\tif (!mit->view) {\n\t\t\tPyArray_MapIterBind(mit, self);\n\t\t\tret = PyArray_SetMap(mit, op);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn ret;\n\t\t}\n\t\tPy_DECREF((PyObject*)mit);\n\t}\n\n\ti = PyArray_PyIntAsIntp(index);\n\tif (!error_converting(i)) {\n\t\treturn array_ass_big_item(self, i, op);\n\t}\n\tPyErr_Clear();\n\t\n\t/* Rest of standard (view-based) indexing */\n\n if ((tmp = (PyArrayObject *)array_subscript(self, index)) == NULL)\n return -1; \n ret = PyArray_CopyObject(tmp, op);\n Py_DECREF(tmp);\n\t\n return ret;\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 \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\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}\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}\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 PyObject *args, *ret;\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n args = Py_BuildValue(\"(OO)\", m1, m2);\n ret = PyObject_Call(op, args, NULL);\n Py_DECREF(args);\n return ret;\n}\n\nstatic PyObject *\nPyArray_GenericUnaryFunction(PyArrayObject *m1, PyObject *op) \n{\n PyObject *args, *ret;\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n args = Py_BuildValue(\"(O)\", m1);\n ret = PyObject_Call(op, args, NULL);\n Py_DECREF(args);\n return ret;\n}\n\nstatic PyObject *\nPyArray_GenericInplaceBinaryFunction(PyArrayObject *m1, \n\t\t\t\t PyObject *m2, PyObject *op) \n{\n PyObject *args, *ret;\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n args = Py_BuildValue(\"(OOO)\", m1, m2, m1);\n ret = PyObject_Call(op, args, NULL);\n Py_DECREF(args);\n return ret;\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_all_nonzero(PyArrayObject *mp) \n{\n\tintp index;\n\tPyArrayIterObject *it;\n\tBool anyTRUE = 0;\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->nonzero(it->dataptr, mp)) {\n\t\t\tanyTRUE = 1;\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 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->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->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->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->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->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_all_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 r = (PyArrayObject *)\\\n\t\tPyArray_New(self->ob_type, self->nd, self->dimensions, \n\t\t\t self->descr->type_num, self->strides, data,\n\t\t\t self->itemsize, 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 any(self == el) */\n\n return PyObject_RichCompareBool((PyObject *)self, el, Py_EQ);\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 *)realloc(*string, *max_n); }\n\t\n if (nd == 0) {\n\t\t\n if ((op = descr->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\tfree(string); return NULL; \n\t}\n\t\n\tif (PyArray_ISFLEXIBLE(self)) {\n\t\tchar buf[100];\n\t\tsnprintf(buf, sizeof(buf), \"%d\", self->itemsize);\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 free(string);\n return ret;\n}\n\nstatic PyObject *PyArray_StrFunction=NULL;\nstatic PyObject *PyArray_ReprFunction=NULL;\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\n\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) \n{\n PyObject *array_other, *result;\n\n switch (cmp_op) \n {\n case Py_LT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less);\n case Py_LE:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less_equal);\n case Py_EQ:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then return the integer\n\t\t\t object 0. This fixes code that used to\n\t\t\t allow equality comparisons between arrays\n\t\t\t and other objects which would give a result\n\t\t\t of 0\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n result = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.equal);\n /* If the comparison results in NULL, then the \n\t\t\t two array objects can not be compared together so \n\t\t\t return zero \n */\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n return result;\n case Py_NE:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then objects cannot be \n\t\t\t compared and cannot be equal, therefore, \n\t\t\t return True;\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n result = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.not_equal);\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n return result;\n case Py_GT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.greater);\n case Py_GE:\n return PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t other, \n\t\t\t\t\t \t n_ops.greater_equal);\n }\n return NULL;\n}\n\nstatic PyObject *\n_check_axis(PyArrayObject *arr, int *axis, int flags)\n{\n\tPyObject *temp;\n\tint n = arr->nd;\n\n\tif ((*axis >= MAX_DIMS) || (n==0)) {\n\t\ttemp = PyArray_Ravel(arr,0);\n\t\t*axis = 0;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_FromAny((PyObject *)arr, NULL, \n\t\t\t\t\t 0, 0, flags);\n\t\t\tif (temp == NULL) return NULL;\n\t\t}\n\t\telse {\n\t\t\tPy_INCREF(arr);\n\t\t\ttemp = (PyObject *)arr;\n\t\t}\n\t}\n\tif (*axis < 0) *axis += n;\n\tif ((*axis < 0) || (*axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", *axis);\n\t\tPy_DECREF(temp);\n\t\treturn NULL;\n\t}\n\treturn temp;\n}\n\n#include \"arraymethods.c\"\n\n/* Lifted from numarray */\nstatic PyObject *\nPyArray_IntTupleFromIntp(int len, intp *vals)\n{\n\tint i;\n PyObject *intTuple = PyTuple_New(len);\n if (!intTuple) goto fail;\n for(i=0; ind == 0) return 1;\n\tsd = ap->itemsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\n\t}\n\treturn 1;\n}\n\n\nstatic int \n_IsFortranContiguous(PyArrayObject *ap) \n{\n\tint sd;\n\tint i;\n\t\n\tif (ap->nd == 0) return 1;\n\tsd = ap->itemsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i=0; i< ap->nd; ++i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\n\t}\n\treturn 1;\n}\n\nstatic int\n_IsAligned(PyArrayObject *ap) \n{\n\tint i, alignment, aligned=1;\n\tintp ptr;\n\tint type = ap->descr->type_num;\n\n\tif ((type == PyArray_STRING) || (type == PyArray_VOID))\n\t\treturn 1;\n\n\talignment = ap->descr->alignment;\n\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\tPyBufferProcs *pb;\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\tpb = base->ob_type->tp_as_buffer;\n\tif (pb == NULL || pb->bf_getwritebuffer == NULL)\n\t\treturn FALSE;\n\t\n\treturn TRUE;\n}\n\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\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not \n walk outside of the memory implied by either numbytes or\n a single segment array of the provided dimensions and element size if\n numbytes is 0 */\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, \n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\t\n\tif (numbytes == 0) \n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\t\n\tfor (i=0; i numbytes) {\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\treturn TRUE;\n\t\n}\n\n\n/* This is the main array creation routine. */\n\n/* Flags argument has multiple related meanings \n depending on data and strides: \n\n If data is given, then flags is flags associated with data. \n If strides is not given, then a contiguous strides array will be created\n and the CONTIGUOUS bit will be set. If the flags argument \n has the FORTRAN bit set, then a FORTRAN-style strides array will be\n created (and of course the FORTRAN flag bit will be set). \n\n If data is not given but created here, then flags will be DEFAULT_FLAGS\n and a non-zero flags argument can be used to indicate a FORTRAN style\n array is desired. \n*/\n\nstatic intp\n_array_fill_strides(intp *strides, intp *dims, int nd, intp itemsize, \n\t\t int inflag, int *objflags) \n{\n\tint i;\n\t/* Only make Fortran strides if not contiguous as well */\n\tif ((inflag & FORTRAN) && !(inflag & CONTIGUOUS)) {\n\t\tfor (i=0; i 1) *objflags &= ~CONTIGUOUS;\n\t\telse *objflags |= CONTIGUOUS;\n\t}\n\telse {\n\t\tfor (i=nd-1;i>=0;i--) {\n\t\t\tstrides[i] = itemsize;\n\t\t\titemsize *= dims[i] ? dims[i] : 1;\n\t\t}\n\t\t*objflags |= CONTIGUOUS;\n\t\tif (nd > 1) *objflags &= ~FORTRAN;\n\t\telse *objflags |= FORTRAN;\n\t}\n\treturn itemsize;\n}\n\n\t\nstatic PyObject *\nPyArray_New(PyTypeObject *subtype, int nd, intp *dims, int type_num,\n intp *strides, char *data, int itemsize, int flags,\n\t PyObject *obj)\n{\n\tPyArrayObject *self;\n\tPyArray_Descr *descr;\n\tregister int i;\n\tintp sd, temp=-1;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\tif (descr == NULL) return NULL;\n\n\tif (nd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"number of dimensions must be >=0\");\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 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\treturn NULL;\n\t\t}\n\t}\n\t\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) return NULL;\t\n\tself->descr = descr;\n\tself->dimensions = 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\n\tif (PyTypeNum_ISFLEXIBLE(type_num)) {\n\t\tif (itemsize < 1) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"type must provide an itemsize\");\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn NULL;\n\t\t}\n\t\tself->itemsize = itemsize;\n\t\t/* Guarantee that these kind of arrays are never byteswapped\n\t\t unknowingly. \n\t\t*/\n\t\tif (type_num != PyArray_UNICODE)\n\t\t\tself->flags |= NOTSWAPPED;\n\t}\n\telse self->itemsize = descr->elsize; \n\t\t\n\tsd = self->itemsize;\n\t\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn PyErr_NoMemory();\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\tPyDimMem_FREE(self->dimensions);\n\t\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\t\treturn NULL;\n\t\t\t}\t\t\t\t\n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t}\n \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 (a.data) doesn't work\n\t\t as it should. */\n\n\t\tif (sd==0) sd = sizeof(intp);\n\n\t\tif ((data = PyDataMem_NEW(sd))==NULL) {\n\t\t\tPyDimMem_FREE(self->dimensions);\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn PyErr_NoMemory();\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\n\t\t/* It is bad to have unitialized OBJECT pointers */\n\t\t/* We shouldn't need to check for the OBJECT Letter\n\t\t but perhaps it's best. */\n\t\tif (type_num == PyArray_OBJECT || \\\n\t\t type_num == PyArray_OBJECTLTR) {\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\tself->nd = nd;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\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;\n\t\tif (temp==-1) { /* 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\tres = PyObject_CallMethod((PyObject *)self, \n\t\t\t\t\t \"__array_finalize__\",\n\t\t\t\t\t \"O\", obj);\n\t\tif (res == NULL) {\n\t\t\tPyDimMem_FREE(self->dimensions);\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn NULL;\n\t\t}\n\t\telse Py_DECREF(res);\n\t}\n\n\treturn (PyObject *)self;\n}\n\n\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\n newsize = PyArray_MultiplyList(new_dimensions, new_nd);\n\n if (newsize == 0) {\n PyErr_SetString(PyExc_ValueError, \n \"newsize is zero; cannot delete an array \"\\\n \"in this way\");\n return NULL;\n }\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 = (((PyObject *)self)->ob_refcnt);\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\n\t\t/* Reallocate space if needed */\n\t\tnew_data = PyDataMem_RENEW(self->data, \n\t\t\t\t\t newsize*(self->itemsize));\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->itemsize;\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->itemsize;\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 */\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; idataptr, fromptr, itemsize);\n\t\t\tPyArray_ITER_NEXT(iter);\n\t\t}\n\n\t\tPy_DECREF(iter);\n\t\tPy_DECREF(behaved);\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\", \"strides\", \n \"swap\", \"fortran\", NULL};\n\tint itemsize = 0;\n\tPyArray_Typecode typecode = {PyArray_NOTYPE, 0, 0};\n\tint type_num = PyArray_NOTYPE;\n PyArray_Dims dims = {NULL, 0};\n PyArray_Dims strides = {NULL, 0};\n PyArray_Chunk buffer;\n\tint fortran = 0;\n int swapped = 0;\n\tPyArrayObject *ret;\n\n\tbuffer.ptr = NULL; \n /* Usually called with shape and type\n but can also be called with buffer, strides, and swapped info\n */\n\n\t/* For now, let's just use this to create an empty, contiguous \n\t array of a specific type and shape. \n\t*/\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&O&ii\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &dims, \n PyArray_TypecodeConverter,\n\t\t\t\t\t &typecode, \n PyArray_BufferConverter,\n &buffer,\n &PyArray_IntpConverter, \n &strides,\n &swapped, &fortran)) \n\t\treturn NULL;\n\t\n if (typecode.type_num ==PyArray_NOTYPE) {\n\t\ttypecode.type_num = PyArray_DOUBLE;\n\t\ttypecode.itemsize = sizeof(double);\n\t}\n\ttype_num = typecode.type_num;\n\titemsize = typecode.itemsize;\n\n\n if (dims.ptr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"need to give a \"\\\n \"valid shape as the first argument\");\n goto fail;\n }\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)PyArray_New(subtype, (int)dims.len, \n dims.ptr, type_num,\n NULL, NULL, itemsize, \n fortran, NULL);\n \n if (ret == NULL) goto fail;\n if (type_num == PyArray_OBJECT) { /* place Py_None */\n PyArray_FillObjectArray(ret, Py_None);\n }\n }\n else { /* buffer given -- use it */\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = buffer.len / itemsize;\n }\n else if (buffer.len < itemsize* \\\n PyArray_MultiplyList(dims.ptr, dims.len)) {\n PyErr_SetString(PyExc_TypeError, \n \"buffer is too small for \" \\\n \"requested array\");\n goto fail;\n }\n if (strides.ptr != NULL) {\n\t\t\tif (strides.len != dims.len) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides, if given, must be \"\\\n\t\t\t\t\t\t\"the same length as shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CheckStrides(itemsize, strides.len, \n\t\t\t\t\t\t buffer.len,\n\t\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides is incompatible \"\\\n\t\t\t\t\t\t\"with shape of requested\"\\\n\t\t\t\t\t\t\"array and size of buffer\");\n\t\t\t\tgoto fail;\n\t\t\t}\n }\n if (type_num == PyArray_OBJECT) {\n PyErr_SetString(PyExc_TypeError, \"cannot construct \"\\\n \"an object array from buffer data\");\n goto fail;\n }\n /* get writeable and aligned */\n if (fortran) buffer.flags |= FORTRAN;\n if (!(swapped)) buffer.flags |= NOTSWAPPED;\n ret = (PyArrayObject *)PyArray_New(subtype, dims.len, \n dims.ptr, type_num,\n strides.ptr,\n (char *)buffer.ptr, \n itemsize, \n buffer.flags, NULL); \n if (ret == 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 PyArray_Return(ret);\n \n fail:\n if (dims.ptr) PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return NULL;\n}\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 static PyObject *module=NULL;\n\n if (module==NULL) {\n module = PyImport_ImportModule(\"scipy.base._internal\");\n if (module == NULL) return NULL;\n }\n return PyObject_CallMethod(module, \"flagsobj\", \"Oii\", \n self, self->flags, 0);\n}\n\n/*\nstatic int\narray_flags_set(PyArrayObject *self, PyObject *obj) \n{\n\tint flagback = self->flags;\n\n if (PyDict_Check(obj)) {\n PyObject *new;\n\t\tnew = PyDict_GetItemString(obj, \"ALIGNED\");\n\t\tif (new) {\n\t\t\tif (PyObject_Not(new)) self->flags &= ~ALIGNED;\n\t\t\telse if (_IsAligned(self)) self->flags |= ALIGNED;\n\t\t\telse {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"cannot set aligned flag of \" \\\n\t\t\t\t\t\t\"mis-aligned array to True\");\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t}\n new = PyDict_GetItemString(obj, \"UPDATEIFCOPY\");\n if (new) {\n if (PyObject_Not(new)) {\n self->flags &= ~UPDATEIFCOPY;\n Py_DECREF(self->base);\n self->base = NULL;\n }\n else {\n\t\t\t\tself->flags = flagback;\n PyErr_SetString(PyExc_ValueError, \n \"cannot set UPDATEIFCOPY \" \\\n \"flag to True\");\n return -1;\n }\n }\n new = PyDict_GetItemString(obj, \"WRITEABLE\");\n if (new) {\n\t\t\tif (PyObject_IsTrue(new)) {\n\t\t\t\tif (_IsWriteable(self)) {\n\t\t\t\t\tself->flags |= WRITEABLE;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tself->flags = flagback;\n\t\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\t\"cannot set \"\t\\\n\t\t\t\t\t\t\t\"WRITEABLE \"\t\\\n\t\t\t\t\t\t\t\"flag to True of \"\\\n\t\t\t\t\t\t\t\"this array \");\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n else\n self->flags &= ~WRITEABLE;\n }\n new = PyDict_GetItemString(obj, \"NOTSWAPPED\");\n if (new) {\n if (PyObject_IsTrue(new))\n self->flags |= NOTSWAPPED;\n else {\n self->flags &= ~NOTSWAPPED;\n\t\t\t}\n\t\t}\n return 0;\n }\n PyErr_SetString(PyExc_ValueError, \n \"object must be a dictionary\");\n return -1;\n}\n*/\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\tif (!PyTuple_Check(val)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"shape must be a tuple\");\n\t\treturn -1;\n\t}\n\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\n\t\n\tif (self->nd > 0) { /* Free old dimensions and strides */\n\t\tPyDimMem_FREE(self->dimensions);\n\t}\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;\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\treturn -1;\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->itemsize;\n\t\n\tif (!PyArray_CheckStrides(self->itemsize, self->nd, numbytes, \n\t\t\t\t self->dimensions, newstrides.ptr)) {\n\t\tPyErr_SetString(PyExc_ValueError, \"strides is not \"\\\n\t\t\t\t\"compatible with available memory\");\n\t\treturn -1;\n\t}\n\tmemcpy(self->strides, newstrides.ptr, sizeof(intp)*newstrides.len);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\treturn 0;\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->itemsize);\n}\n\nstatic PyObject *\narray_size_get(PyArrayObject *self)\n{\n\tlonglong size=PyArray_SIZE(self);\n\tif (size > MAX_INT || size < MIN_INT)\n\t\treturn PyLong_FromLongLong(size);\n\telse \n\t\treturn PyInt_FromLong((long) size);\n}\n\n\nstatic PyObject *\narray_typechar_get(PyArrayObject *self)\n{\n\tif PyArray_ISFLEXIBLE(self) \n\t\treturn PyString_FromFormat(\"%c%d\", (self->descr->type),\n\t\t\t\t\t self->itemsize);\n\telse \n\t\treturn PyString_FromStringAndSize(&(self->descr->type), 1);\n}\n\nstatic PyObject *\narray_typestr_get(PyArrayObject *self)\n{\n\tstatic char endians[] = \"<>\";\n\tchar endian;\n\tint which;\n\tunsigned long val = 1;\n\tchar *s;\n\tchar basic_=self->descr->kind;\n\n\ts = (char *)&val; /* s[0] == 0 implies big-endian */\n\twhich = (PyArray_ISNOTSWAPPED(self) ? 0 : 1);\n\tif (s[0] == 0) which = 1 - which;\n\tendian = endians[which]; \n\t\n\tif ((basic_==PyArray_VOIDLTR) || (basic_==PyArray_STRINGLTR) || \\\n\t (basic_==PyArray_OBJECTLTR) || (self->itemsize == 1))\n\t\treturn PyString_FromFormat(\"|%c%d\", basic_, self->itemsize);\n\telse\n\t\treturn PyString_FromFormat(\"%c%c%d\", endian, basic_,\n\t\t\t\t\t self->itemsize);\n}\n\nstatic PyObject *\narray_descr_get(PyArrayObject *self)\n{\n\tPyObject *res;\n\tPyObject *dobj;\n\n\t/* hand this off to the typeobject */\n\t/* or give default */\n\tif (PyArray_ISUSERDEF(self)) {\n\t\tres = PyObject_GetAttrString((PyObject *)self->descr->typeobj, \n\t\t\t\t\t \"__array_descr__\");\n\t\tif (res) return res;\n\t\tPyErr_Clear();\n\t}\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\n\nstatic PyObject *\narray_type_get(PyArrayObject *self)\n{\n\treturn PyArray_TypeObjectFromType(self->descr->type_num);\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*/\n\nstatic int\narray_type_set(PyArrayObject *self, PyObject *arg)\n{\n PyArray_Typecode newtype = {PyArray_NOTYPE, 0, 0};\n intp newdim;\n int index;\n char *msg = \"new type not compatible with array.\";\n\n if ((PyArray_TypecodeConverter(arg, &newtype) < 0) ||\n newtype.type_num == PyArray_NOTYPE) {\n PyErr_SetString(PyExc_TypeError, \"invalid type for array\");\n return -1;\n }\n if (!(PyArray_ISONESEGMENT(self) ||\t\t\\\n\t (newtype.itemsize != self->itemsize))) {\n PyErr_SetString(PyExc_ValueError, msg);\n return -1; \n }\n\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\n if (newtype.itemsize < self->itemsize) {\n /* if it is compatible increase the size of the dimension\n at end (or at the front for FORTRAN)\n */\n if (self->itemsize % newtype.itemsize != 0) {\n PyErr_SetString(PyExc_ValueError, msg);\n return -1;\n }\n newdim = self->itemsize / newtype.itemsize;\n\t\tself->dimensions[index] *= newdim;\n self->strides[index] = newtype.itemsize;\n\t}\n \n else if (newtype.itemsize > self->itemsize) {\n \n /* Determine if last (or first if FORTRAN) dimension\n is compatible */\n\n\t\tnewdim = self->dimensions[index] * self->itemsize;\n if ((newdim % newtype.itemsize) != 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, msg);\n return -1;\n }\n\t\t\n self->dimensions[index] = newdim / newtype.itemsize;\n self->strides[index] = newtype.itemsize;\n\t\t\n }\n\t\n \n /* fall through -- adjust type*/\n\n self->descr = PyArray_DescrFromType(newtype.type_num);\n self->itemsize = newtype.itemsize;\n PyArray_UpdateFlags(self, ALIGNED);\n return 0;\n\n}\n\n\n\nstatic PyObject *\narray_base_get(PyArrayObject *self)\n{\n\tif (self->base == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\telse {\n\t\tPy_INCREF(self->base);\n\t\treturn self->base;\n\t}\n}\n\n\nstatic PyObject *\narray_real_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *)ret;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n}\n\n\nstatic int\narray_real_set(PyArrayObject *self, PyObject *val)\n{\n\tPyArrayObject *ret;\n\tPyArrayObject *new;\n\tint rint;\n\n\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0);\n\tif (new == NULL) return -1;\n\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) 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\treturn rint;\n}\n\nstatic PyObject *\narray_imag_get(PyArrayObject *self)\n{\t\n\tPyArrayObject *ret;\n\tint itemsize;\n\tint typenum;\n PyArray_Typecode type;\n\t\n\ttype.type_num = self->descr->type_num;\n\ttype.itemsize = self->itemsize;\n\ttype.fortran = PyArray_ISFORTRAN(self);\n\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\titemsize = self->itemsize >> 1;\n\t\ttypenum = self->descr->type_num - PyArray_NUM_FLOATTYPE;\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 typenum,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data + itemsize,\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\tret = (PyArrayObject *)PyArray_Zeros(self->nd, \n\t\t\t\t\t\t self->dimensions, &type);\n\t\tret->flags &= ~WRITEABLE;\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic int\narray_imag_set(PyArrayObject *self, PyObject *val)\n{\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyArrayObject *ret;\n\t\tPyArrayObject *new;\n\t\tint rint;\n\n\t\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0); \n\t\tif (new == NULL) return -1;\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides+ \\\n\t\t\t\t\t\t (self->itemsize >> 1) ,\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) {\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_Typecode typecode;\n int swap;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode.type_num = self->descr->type_num;\n\ttypecode.itemsize = self->itemsize;\n\ttypecode.fortran = PyArray_ISFORTRAN(self);\n\t\n\tarr = PyArray_FromAny(val, &typecode, \n\t\t\t 0, 0, FORCECAST);\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->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 copyswap(selfit->dataptr, NULL, swap, \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->itemsize);\n copyswap(selfit->dataptr, NULL, swap, self->itemsize);\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\t{\"base\",\n\t (getter)array_base_get,\n\t NULL,\n\t \"base object\"},\n {\"dtype\", \n\t (getter)array_type_get, \n\t (setter)array_type_set,\n\t \"get array type class\"},\n\t{\"dtypechar\",\n\t (getter)array_typechar_get,\n\t NULL,\n\t \"get array type character code\"},\n\t{\"dtypestr\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"get array type string\"},\n {\"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_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\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\n\nstatic char Arraytype__doc__[] = \n \"A array object represents a multidimensional, homogeneous array\\n\"\n\t\" of basic values. Arrays are sequence, mapping and numeric\\n\"\n\t\" objects. More information is available in the scipy module and\\n\"\n\t\" by looking at the methods and attributes of an array.\";\n\nstatic PyTypeObject PyBigArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"scipy.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 \n offsetof(PyArrayObject, weakreflist), /*tp_weaklistoffset */\n\n /* Iterator support (use standard) */\n\n (getiterfunc)0, \t\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 0,\t /* tp_alloc */ \n (newfunc)array_new,\t\t /* tp_new */\n 0,\t \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 \"scipy.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) \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 if (PySequence_Length(s) == 0) \n\t\treturn 1;\n\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);\n\t\tif(d >= 0) d++;\n\t}\n Py_DECREF(e);\n return d;\n}\n\nstatic int\ndiscover_itemsize(PyObject *s, int nd, int *itemsize) \n{\n\tint n, r, i;\n\tPyObject *e;\n\t\n\tn = PyObject_Length(s);\n\n\tif ((nd == 0) || PyString_Check(s) ||\t\t\\\n\t PyUnicode_Check(s) || PyBuffer_Check(s)) {\n\t\tif PyUnicode_Check(s) \n\t\t\t*itemsize = MAX(*itemsize, sizeof(Py_UNICODE)*n);\n\t\telse\n\t\t\t*itemsize = MAX(*itemsize, n);\n\t\treturn 0;\n\t}\n\tfor (i=0; i n_lower) n_lower = d[1];\n }\n d[1] = n_lower;\n\t\n return 0;\n}\n\nstatic void\n_array_small_type(int chktype, int mintype, int chksize, int minsize, \n\t\t PyArray_Typecode *outtype)\n{\n\touttype->type_num = MAX(chktype, mintype);\n\tif (PyTypeNum_ISFLEXIBLE(outtype->type_num) &&\t\\\n\t PyTypeNum_ISFLEXIBLE(mintype)) {\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 == PyArray_STRING) {\n\t\t\touttype->itemsize = MAX(chksize, 2*minsize);\n\t\t}\n\t\telse {\n\t\t\touttype->itemsize = MAX(chksize, minsize);\n\t\t}\n\t}\n\telse {\n\t\touttype->itemsize = chksize;\n\t}\n\treturn;\t\n}\n\nstatic void\n_array_find_type(PyObject *op, PyArray_Typecode *minitype, \n\t\t PyArray_Typecode *outtype, int max)\n{\n int l;\n PyObject *ip;\n\tint chktype=0;\n\tint chksize=0;\n\tint mintype, minsize;\n\n\tif (minitype == NULL) {\n\t\tmintype = PyArray_BOOL;\n\t\tminsize = sizeof(Bool);\n\t}\n\telse {\n\t\tmintype = minitype->type_num;\n\t\tminsize = minitype->itemsize;\n\t}\n\n \n if (max < 0 || mintype == -1) goto deflt;\n\t\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_TYPE(op);\n\t\tchksize = PyArray_ITEMSIZE(op);\n\t\tgoto finish;\n\t}\n\t\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tPyArray_TypecodeFromScalar(op, outtype);\n\t\tchktype = outtype->type_num;\n\t\tchksize = outtype->itemsize;\n\t\tgoto finish;\n\t}\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_TYPE(ip);\n\t\t\tchksize = PyArray_ITEMSIZE(ip);\n\t\t\tgoto finish;\n\t\t}\n } \n\t\n\tif (PyObject_HasAttrString(op, \"__array_typestr__\")) {\n\t\tint swap=0, res;\n\t\tip = PyObject_GetAttrString(op, \"__array_typestr__\");\n\t\tif (ip && PyString_Check(ip)) {\n\t\t\tres = _array_typecode_fromstr(PyString_AS_STRING(ip), \n\t\t\t\t\t\t &swap, outtype); \n\t\t\tif (res >= 0) {\n\t\t\t\tPy_DECREF(ip);\n\t\t\t\tchktype = outtype->type_num;\n\t\t\t\tchksize = outtype->itemsize;\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t}\n\t\tPy_XDECREF(ip);\n\t}\n\n if (PyString_Check(op)) {\n\t\tchktype = PyArray_STRING;\n\t\tchksize = PyString_GET_SIZE(op);\n\t\tgoto finish;\n }\n\n\tif (PyUnicode_Check(op)) {\n\t\tchktype = PyArray_UNICODE;\n\t\tchksize = PyUnicode_GET_DATA_SIZE(op);\n\t\tgoto finish;\n\t}\n\n\tif (PyBuffer_Check(op)) {\n\t\tchktype = PyArray_VOID;\n\t\tchksize = op->ob_type->tp_as_sequence->sq_length(op);\n\t\tPyErr_Clear();\n\t\tgoto finish;\n\t}\n\n\tif (PyInstance_Check(op)) goto deflt;\n\t\n if (PySequence_Check(op)) {\n\t\tPyArray_Typecode newtype;\n\t\tnewtype.type_num = mintype;\n\t\tnewtype.itemsize = minsize;\n\t\tnewtype.fortran = 0;\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 && mintype == 0) {\n\t\t\tnewtype.type_num = PyArray_INTP;\n\t\t\tnewtype.itemsize = sizeof(intp);\n\t\t}\n while (--l >= 0) {\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\t_array_find_type(ip, &newtype, outtype, max-1);\n\t\t\t_array_small_type(outtype->type_num,\n\t\t\t\t\t newtype.type_num, \n\t\t\t\t\t outtype->itemsize,\n\t\t\t\t\t newtype.itemsize,\n\t\t\t\t\t &newtype);\n Py_DECREF(ip);\n }\n\t\tchktype = newtype.type_num;\n\t\tchksize = newtype.itemsize;\n\t\tgoto finish;\n }\n\t\n\tif (PyBool_Check(op)) {\n\t\tchktype = PyArray_BOOL;\n\t\tchksize = sizeof(Bool);\n\t\tgoto finish;\t\t\n\t}\n else if (PyInt_Check(op)) {\n\t\tchktype = PyArray_LONG;\n\t\tchksize = sizeof(long);\n\t\tgoto finish;\n } else if (PyFloat_Check(op)) {\n\t\tchktype = PyArray_DOUBLE;\n\t\tchksize = sizeof(double);\n\t\tgoto finish;\n\t} else if (PyComplex_Check(op)) {\n\t\tchktype = PyArray_CDOUBLE;\n\t\tchksize = sizeof(cdouble);\n\t\tgoto finish;\n\t}\n\n deflt:\n\tchktype = PyArray_OBJECT;\n\tchksize = sizeof(void *);\n\n finish:\n\t_array_small_type(chktype, mintype, chksize, minsize, \n\t\t\t outtype);\n\treturn;\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\" */ \nstatic PyObject *\nArray_FromScalar(PyObject *op, PyArray_Typecode *typecode) \n{\n PyArrayObject *ret;\n\tint itemsize; \n\tint type;\n\t\n\titemsize = typecode->itemsize;\n\ttype = typecode->type_num;\n\n\tif (itemsize == 0 && PyTypeNum_ISFLEXIBLE(type)) {\n\t\titemsize = PyObject_Length(op);\n\t}\n\n\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, 0, NULL, type,\n\t\t\t\t\t NULL, NULL, itemsize, 0, NULL);\n\n\tif (ret == NULL) return NULL;\n\n ret->descr->setitem(op, ret->data, ret);\n\t\n if (PyErr_Occurred()) {\n array_dealloc(ret);\n return NULL;\n } else {\n return (PyObject *)ret;\n }\n}\n\n\nstatic PyObject *\nArray_FromSequence(PyObject *s, PyArray_Typecode *typecode, int min_depth, \n\t\t int max_depth)\n{\n PyArrayObject *r;\n int nd;\n\tintp *d;\n\tint stop_at_string;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->itemsize;\n\t\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 if (!((nd=discover_depth(s, MAX_DIMS+1, stop_at_string)) > 0)) {\n\t\tif (nd==0)\n\t\t\treturn Array_FromScalar(s, typecode);\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid input sequence\");\n return NULL;\n }\n\t\n if ((max_depth && nd > max_depth) ||\t\\\n\t (min_depth && nd < min_depth)) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid number of dimensions\");\n return NULL;\n }\n\t\n\tif ((d=PyDimMem_NEW(nd)) == NULL) {\n\t\treturn PyErr_NoMemory();\n }\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) {\n\t\tPyDimMem_FREE(d);\n\t\treturn NULL;\n\t}\n\tif (itemsize == 0 && PyTypeNum_ISFLEXIBLE(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) {\n\t\t\tPyDimMem_FREE(d);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n r=(PyArrayObject*)PyArray_New(&PyArray_Type, nd, d, \n\t\t\t\t type, NULL, NULL,\n\t\t\t\t itemsize, \n\t\t\t\t typecode->fortran, NULL);\n\n PyDimMem_FREE(d);\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\n\nstatic int \nPyArray_ValidType(int type) \n{\n\tPyArray_Descr *descr;\n\t\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr==NULL) return 0;\n\treturn 1;\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->itemsize;\n\tint nels = PyArray_BUFSIZE;\n\tint el;\n\tint inswap, outswap=0;\n\tint obuf=!PyArray_ISCARRAY(out);\n\tint oelsize = out->itemsize;\n\tPyArray_VectorUnaryFunc *castfunc;\n PyArray_CopySwapFunc *in_csn;\n PyArray_CopySwapFunc *out_csn;\n\tint retval = -1;\n\n\tcastfunc = in->descr->cast[out->descr->type_num];\n in_csn = in->descr->copyswap;\n out_csn = out->descr->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\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\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->itemsize * 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\n/* For backward compatibility */\n\nstatic PyObject *\nPyArray_Cast(PyArrayObject *mp, int type_num) \n{\n\tPyArray_Typecode type;\n\tPyArray_Descr *descr;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\ttype.itemsize = descr->elsize;\n\ttype.type_num = descr->type_num;\n\ttype.fortran = 0;\n\t\n\treturn PyArray_CastToType(mp, &type);\n}\n\nstatic PyObject * \nPyArray_CastToType(PyArrayObject *mp, PyArray_Typecode *at) \n{\n\tPyObject *out;\n\tint ret;\n\n\tif ((mp->descr->type_num == at->type_num) && \\\n\t (at->itemsize==0 || mp->itemsize == at->itemsize) &&\n\t PyArray_ISBEHAVED_RO(mp)) {\n\t\tPy_INCREF(mp);\n\t\treturn (PyObject *)mp;\n\t}\n\t\t\n\tif (at->itemsize == 0) {\n\t\tif (mp->descr->type_num == PyArray_STRING &&\t\\\n\t\t at->type_num == PyArray_UNICODE)\n\t\t\tat->itemsize = mp->itemsize*sizeof(Py_UNICODE);\n\t\tif (mp->descr->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING) \n\t\t\tat->itemsize = mp->itemsize/sizeof(Py_UNICODE);\n\t\tif (at->type_num == PyArray_VOID)\n\t\t\tat->itemsize = mp->itemsize;\n\t}\n\n\tout = PyArray_New(mp->ob_type, mp->nd, \n\t\t\t mp->dimensions, \n\t\t\t at->type_num,\n\t\t\t NULL, NULL, at->itemsize, \n\t\t\t at->fortran, (PyObject *)mp);\n\tif (out == NULL) return NULL;\n\tret = PyArray_CastTo((PyArrayObject *)out, mp);\n\tif (ret != -1) return out;\n\n\tPy_DECREF(out);\n\treturn NULL;\n\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\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\tsimple = ((PyArray_ISCARRAY(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY(mp) && PyArray_ISFARRAY(out)));\n\t\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->itemsize * outsize;\n\t\tintp ncopies = outsize / mpsize;\n\n\t\twhile(ncopies--) {\n\t\t\tinptr = mp->data;\n\t\t\tmp->descr->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\nstatic PyObject *\narray_fromarray(PyArrayObject *arr, PyArray_Typecode *typecode, int flags) \n{\n\t\n\tPyArrayObject *ret=NULL;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->itemsize;\n\tint copy = 0;\n\tint arrflags;\n\tPyArray_Typecode oldtype;\n\tchar *msg = \"cannot copy back to a read-only array\";\n PyTypeObject *subtype;\n\n\toldtype.type_num = PyArray_TYPE(arr);\n\toldtype.itemsize = PyArray_ITEMSIZE(arr);\n\toldtype.fortran = 0;\n\n subtype = arr->ob_type;\n\n\tif (type == PyArray_NOTYPE) type = arr->descr->type_num;\n\tif (itemsize == 0) itemsize = arr->itemsize;\n\ttypecode->type_num = type;\n\ttypecode->itemsize = itemsize;\n\n\t/* Don't copy if sizes are compatible */\n\tif (PyArray_EquivalentTypes(&oldtype, typecode)) {\n\t\tarrflags = arr->flags;\n\n\t\tcopy = (flags & ENSURECOPY) || \\\n\t\t\t((flags & CONTIGUOUS) && (!(arrflags & CONTIGUOUS))) \\\n\t\t\t|| (PyArray_ITEMSIZE(arr) != itemsize) || \\\n\t\t\t((flags & ALIGNED) && (!(arrflags & ALIGNED))) || \\\n\t\t\t((flags & NOTSWAPPED) && (!(arrflags & NOTSWAPPED))) \\\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 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_New(subtype, \n\t\t\t\t\t arr->nd, \n\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t type,\n\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t itemsize,\n\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t (PyObject *)arr);\n\t\t\tif (PyArray_CopyInto(ret, arr) == -1) 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 ret = (PyArrayObject *) \\\n PyArray_New(&PyArray_Type,\n arr->nd,\n arr->dimensions,\n arr->descr->type_num,\n arr->strides,\n arr->data,\n arr->itemsize,\n arr->flags,NULL);\n if (ret == NULL) return NULL;\n ret->base = (PyObject *)arr;\n ret->flags &= ~UPDATEIFCOPY;\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_CanCastSafely(PyArray_TYPE(arr), type)) {\n if ((flags & UPDATEIFCOPY) && \\\n (!PyArray_ISWRITEABLE(arr))) {\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_New(subtype, arr->nd,\n arr->dimensions, typecode->type_num,\n NULL, NULL, typecode->itemsize,\n typecode->fortran, \n (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\nstatic int\n_array_typecode_fromstr(char *str, int *swap, PyArray_Typecode *type)\n{\n int type_num;\n char typechar;\n int size;\n unsigned long number = 1;\n char *s;\n char msg[] = \"unsupported typestring\";\n \n s = (char *)&number; /* s[0] == 0 implies big-endian */\n\n *swap = 0;\n\n if (str[0] == '<' || str[0] == '>') {\n\tif ((str[0] == '<') && (s[0] == 0)) *swap = 1;\n\telse if ((str[0] == '>') && (s[0] != 0)) *swap = 1;\n }\n str += 1;\n \n#define _MY_FAIL {\t\t\t\t \\\n\t PyErr_SetString(PyExc_ValueError, msg); \\\n\t return -1;\t\t\t \\\n }\t\t\n\n typechar = str[0];\n size = atoi(str + 1);\n switch (typechar) {\n case 'b':\n\t if (size == sizeof(Bool))\n\t\t type_num = PyArray_BOOL;\t \n\t else _MY_FAIL \n\t break;\t\t \n case 'u':\n if (size == sizeof(uintp))\n type_num = PyArray_UINTP;\n\t else if (size == sizeof(char))\n\t\t type_num = PyArray_UBYTE;\n\t else if (size == sizeof(short)) \n\t\t type_num = PyArray_USHORT;\n\t else if (size == sizeof(int)) \n\t\t type_num = PyArray_UINT;\n\t else if (size == sizeof(ulong)) \n\t\t type_num = PyArray_ULONG;\n\t else if (size == sizeof(ulonglong))\n\t\t type_num = PyArray_ULONGLONG;\n\t else _MY_FAIL\n\t break;\t\t \n case 'i':\n if (size == sizeof(intp))\n type_num = PyArray_INTP;\n\t else if (size == sizeof(char)) \n\t\t type_num = PyArray_BYTE;\n\t else if (size == sizeof(short)) \n\t\t type_num = PyArray_SHORT;\n\t else if (size == sizeof(int))\n\t\t type_num = PyArray_INT;\n\t else if (size == sizeof(long)) \n\t\t type_num = PyArray_LONG;\n\t else if (size == sizeof(longlong))\n\t\t type_num = PyArray_LONGLONG;\n\t else _MY_FAIL\n\t break;\t\t \n case 'f':\n\t if (size == sizeof(float))\n\t\t type_num = PyArray_FLOAT;\n\t else if (size == sizeof(double))\n\t\t type_num = PyArray_DOUBLE;\n\t else if (size == sizeof(longdouble))\n\t\t type_num = PyArray_LONGDOUBLE;\n\t else _MY_FAIL\n\t break;\n case 'c':\n\t if (size == sizeof(float)*2)\n\t\t type_num = PyArray_CFLOAT;\n\t else if (size == sizeof(double)*2)\n\t\t type_num = PyArray_CDOUBLE;\n\t else if (size == sizeof(longdouble)*2)\n\t\t type_num = PyArray_CLONGDOUBLE;\n\t else _MY_FAIL\n\t break;\n case 'O':\n\t if (size == sizeof(PyObject *))\n\t\t type_num = PyArray_OBJECT;\n\t else _MY_FAIL\n\t break;\n case 'S':\n\t type_num = PyArray_STRING;\n\t break;\n case 'U':\n\t type_num = PyArray_UNICODE;\n\t size *= sizeof(Py_UNICODE);\n\t break;\t \n case 'V':\n\t type_num = PyArray_VOID;\n\t break;\n default:\n\t _MY_FAIL\n }\n\n#undef _MY_FAIL\n\n type->type_num = type_num;\n type->itemsize = size;\n type->fortran = 0;\n return 0;\n}\n\nstatic PyObject *\narray_frominterface(PyObject *input, PyArray_Typecode *intype, int flags)\n{\n\tPyObject *attr=NULL, *item=NULL, *r;\n\tPyArrayObject *ret=NULL;\n\tPyArray_Typecode type;\n\tchar *data;\n\tint buffer_len;\n\tint res, i, n;\n\tintp dims[MAX_DIMS], strides[MAX_DIMS];\n\tint swap;\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\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) {Py_XDECREF(attr); return NULL;}\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t}\n\telse {\n\t\tif (PyTuple_GET_SIZE(attr) != 2) {\n\t\t\tPy_DECREF(attr);\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\treturn NULL;\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\tPy_DECREF(attr);\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\treturn NULL;\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 = PyObject_GetAttrString(input, \"__array_typestr__\");\n\tif (!PyString_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_typestr__ must be a string\");\n\t\tPy_DECREF(attr);\n\t\treturn NULL;\t\n\t}\n\tres = _array_typecode_fromstr(PyString_AS_STRING(attr), &swap, &type);\n\tPy_DECREF(attr);\n\tif (res < 0) return NULL;\n \n\tattr = PyObject_GetAttrString(input, \"__array_shape__\");\n\tif (!PyTuple_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_shape__ must be a tuple\");\n\t\tPy_DECREF(attr);\n\t\treturn NULL;\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\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\treturn NULL;\n\t\t}\n\t\tfor (i=0; istrides, strides, n*sizeof(intp));\n\t}\n\n\tif (swap) {\n\t\tPyObject *tmp;\n tmp = PyArray_Byteswap(ret, TRUE);\n\t\tPy_DECREF(tmp);\n\t}\n\n\tPyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n\tr = array_fromarray(ret, intype, flags);\n\tPy_DECREF(ret);\n\treturn r;\n}\n\nstatic PyObject *\narray_fromattr(PyObject *op, PyArray_Typecode *typecode, int flags) \n{\n PyObject *new, *r;\n\t \n if (typecode->type_num == PyArray_NOTYPE) {\n new = PyObject_CallMethod(op, \"__array__\", NULL);\n } else {\n\t\tPyArray_Descr *descr;\n\t\tPyObject *obj;\n\n\t\tdescr = PyArray_DescrFromType(typecode->type_num);\n\t\tif (PyTypeNum_ISFLEXIBLE(typecode->type_num)) {\n\t\t\tobj = PyString_FromFormat(\"%c%d\", descr->type,\n\t\t\t\t\t\t typecode->itemsize);\n\t\t}\n\t\telse { \n\t\t\tobj = (PyObject *)(descr->typeobj); Py_INCREF(obj);\n\t\t}\n\t\tnew = PyObject_CallMethod(op, \"__array__\", \"N\", obj);\n }\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 r = array_fromarray((PyArrayObject *)new, typecode, flags);\n Py_DECREF(new);\n return r;\n} \n\n\nstatic PyObject *\narray_fromobject(PyObject *op, PyArray_Typecode *typecode, int min_depth, \n\t\t int max_depth, int flags) \n{\n /* This is the main code to make a NumPy array from a Python\n Object. It is called from lot's of different places which\n is why there are so many checks. The comments try to\n explain some of the checks. */\n\n\tint type = typecode->type_num;\n PyObject *r=NULL;\n\n\t/* Is input object already an array? */\n\t/* This is where the flags are used */\n if (PyArray_Check(op)) \n\t\tr = array_fromarray((PyArrayObject *)op, typecode, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, typecode);\n\t}\n\telse if (PyObject_HasAttrString(op, \"__array__\")) {\n\t\t/* Code that returns the object to convert for a non\n\t\t multiarray input object from the __array__ attribute of the\n\t\t object. */\n r = array_fromattr(op, typecode, flags);\n\t}\n\telse if (PyObject_HasAttrString(op, \"__array_shape__\") &&\n\t\t PyObject_HasAttrString(op, \"__array_typestr__\")) {\n\t\tr = array_frominterface(op, typecode, flags);\n\t}\n\telse {\n\t\tif (type == PyArray_NOTYPE) {\n\t\t\t_array_find_type(op, NULL, typecode, MAX_DIMS);\n\t\t}\n\t\tif (PySequence_Check(op))\n\t\t\tr = Array_FromSequence(op, typecode, \n\t\t\t\t\t min_depth, max_depth);\n\t\telse\n\t\t\tr = Array_FromScalar(op, typecode);\n\t}\n\n /* If we didn't succed return NULL */\n if (r == NULL) return NULL;\n\t\n\t/* Be sure we succeed here */\n\t\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"internal error: array_fromobject \"\\\n\t\t\t\t\"not producing an array\");\n\t\tPy_DECREF(r);\n return NULL;\n }\n\n if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {\n Py_DECREF(r);\n PyErr_SetString(PyExc_ValueError, \n \"object of too small depth for desired array\");\n return NULL;\n }\n if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {\n Py_DECREF(r);\n PyErr_SetString(PyExc_ValueError, \n \"object too deep for desired array\");\n return NULL;\n }\n return r;\n}\n\nstatic void\nPyArray_ArrayType(PyObject *op, PyArray_Typecode *intype, \n\t\t PyArray_Typecode *outtype) \n{\n\t_array_find_type(op, intype, outtype, MAX_DIMS);\n\treturn;\n}\n\nstatic int \nPyArray_ObjectType(PyObject *op, int minimum_type) \n{\n\tPyArray_Typecode intype, outtype;\n\tintype.type_num = minimum_type;\n\t_array_find_type(op, &intype, &outtype, MAX_DIMS);\n\treturn outtype.type_num;\n}\n\n\n\n/* flags is any of \n CONTIGUOUS, \n FORTRAN, (or set typecode->fortran=1)\n ALIGNED, \n NOTSWAPPED, \n WRITEABLE, \n ENSURECOPY, \n UPDATEIFCOPY,\n FORCECAST,\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, NOTSWAPPED, and WRITEABLE\n and therefore it is redundant to include those as well. \n\n BEHAVED_FLAGS == ALIGNED | NOTSWAPPED | WRITEABLE\n BEHAVED_FLAGS_RO == ALIGNED | NOTSWAPPED\n CARRAY_FLAGS = CONTIGUOUS | BEHAVED_FLAGS\n FARRAY_FLAGS = FORTRAN | BEHAVED_FLAGS\n \n By default, the returned array will be a copy of the object, \n (C) contiguous in memory, aligned, notswapped, and writeable.\n \n So CONTIGUOUS | ENSURECOPY passed in means that the returned\n array does not have to be CONTIGUOUS or a COPY but should be\n ALIGNED, NOTSWAPPED and WRITEABLE. \n\n typecode->fortran can be set to request a\n fortran-contiguous array. Fortran arrays are always behaved (aligned, \n notswapped, and writeable) and not (C) CONTIGUOUS. Note that either\n FORTRAN in the flag or typecode->fortran = 1 is enough to request\n a FORTRAN-style array. \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\nstatic PyObject *\nPyArray_FromAny(PyObject *op, PyArray_Typecode *typecode, int min_depth, \n\t\tint max_depth, int requires) \n{\n \tPyArray_Typecode mine = {PyArray_NOTYPE, 0, 0};\n\tPyArray_Typecode *type;\n\t\n\tif (typecode == NULL) type = &mine;\n\telse type = typecode;\n\t\t\n\tif (requires & ENSURECOPY) {\n\t\trequires |= DEFAULT_FLAGS;\n\t}\n\t/* Ensure that type->fortran and flags & FORTRAN are the\n\t same */\n\tif (requires & FORTRAN) typecode->fortran = 1;\n\tif (type->fortran == 1) {\n\t\trequires |= FARRAY_FLAGS;\n\t\tif (min_depth > 2) requires &= ~CONTIGUOUS;\n\t}\n\n\t/* make sure itemsize is not 0 unless warranted. */\n\tif ((type->itemsize == 0) && (type->type_num != PyArray_NOTYPE)) {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(type->type_num);\n\t\tif (descr != NULL) type->itemsize = descr->elsize;\n\t\telse return NULL;\n\t}\n\t\n\treturn array_fromobject(op, type, min_depth, max_depth, \n\t\t\t\trequires);\t\n}\n\n/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0, 0) */\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\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);\n Py_DECREF(op);\n return new;\n}\n\n/* These are all compressed into a single API */\n/* Deprecated calls -- Use PyArray_FromAny */\n\nstatic PyObject *\nPyArray_FromObject(PyObject *op, int type, int min_depth, int max_depth) \n{\n\tPyArray_Typecode typecode = {0, 0, 0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth,\n\t\t\t max_depth, BEHAVED_FLAGS | ENSUREARRAY);\n}\n\nstatic PyObject *\nPyArray_ContiguousFromObject(PyObject *op, int type, int min_depth, \n\t\t\t int max_depth) \n{\n\tPyArray_Typecode typecode = {0, 0, 0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth,\n\t\t\t max_depth, DEFAULT_FLAGS | ENSUREARRAY);\n}\n\nstatic PyObject *\nPyArray_CopyFromObject(PyObject *op, int type, int min_depth, \n\t\t int max_depth) \n{\n\tPyArray_Typecode typecode = {0, 0, 0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth, max_depth,\n\t\t\t ENSURECOPY | ENSUREARRAY);\n}\n\n/* End of deprecated */\n\nstatic PyObject *\nPyArray_ContiguousFromAny(PyObject *op, int type, int min_depth, \n\t\t\t int max_depth)\n{\n\tPyArray_Typecode typecode = {0,0,0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth,\n\t\t\t max_depth, DEFAULT_FLAGS);\n}\t\n\nstatic int \nPyArray_CanCastSafely(int fromtype, int totype) \n{\n\tPyArray_Descr *from, *to;\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\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 (to->elsize > from->elsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (to->elsize >= from->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (from->elsize < 8)\n return (to->elsize > from->elsize);\n else\n return (to->elsize >= from->elsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (from->elsize < 8)\n return ((to->elsize >> 1) > from->elsize);\n else\n return ((to->elsize >> 1) >= from->elsize);\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 (to->elsize > from->elsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (to->elsize >= from->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (from->elsize < 8)\n return (to->elsize > from->elsize);\n else\n return (to->elsize >= from->elsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (from->elsize < 8)\n return ((to->elsize >> 1) > from->elsize);\n else\n return ((to->elsize >> 1) >= from->elsize);\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 ((to->elsize >> 1) >= from->elsize);\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\nstatic Bool\nPyArray_CanCastTo(PyArray_Typecode *from, PyArray_Typecode *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->itemsize <= to->itemsize);\n\t\t\t}\n\t\t\telse if (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->itemsize * sizeof(Py_UNICODE)\\\n\t\t\t\t <= to->itemsize);\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->itemsize <= to->itemsize);\n\t\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 scipy's arraymap ****/\n/* and Python's array iterator ***/\n \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 = PyObject_GC_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 PyObject_GC_Track(it);\n return (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 PyObject_GC_UnTrack(it);\n Py_XDECREF(it->ao);\n PyObject_GC_Del(it);\n }\n\nstatic int\narrayiter_traverse(PyArrayIterObject *it, visitproc visit, void *arg)\n{\n if (it->ao != NULL)\n return visit((PyObject *)(it->ao), arg);\n return 0;\n}\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->itemsize;\n\tr = PyArray_New(self->ao->ob_type, 1, &count, \n\t\t\tself->ao->descr->type_num, NULL, NULL,\n\t\t\titemsize, 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->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->itemsize;\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\tr = PyArray_New(self->ao->ob_type, ind->nd, ind->dimensions,\n\t\t\tself->ao->descr->type_num, NULL, \n\t\t\tNULL, self->ao->itemsize, \n\t\t\t0, (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)->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\tint i;\n\tPyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tint 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\t\t\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\n\t/* Tuples 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\tr = PyArray_New(self->ao->ob_type, 1, &ii, \n\t\t\t\t\tself->ao->descr->type_num, NULL, \n\t\t\t\t\tNULL, self->ao->itemsize, 0,\n\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 */\n\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->itemsize;\n\t\tr = PyArray_New(self->ao->ob_type, 1, &n_steps, \n\t\t\t\tself->ao->descr->type_num, NULL, NULL,\n\t\t\t\tsize, 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)->copyswap;\n\t\twhile(n_steps--) {\n copyswap(dptr, self->dataptr, swap, size);\n\t\t\tfor(i=0; i< step_size; i++) \n\t\t\t\tPyArray_ITER_NEXT(self);\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\tif (PyArray_IsScalar(ind, Integer) || PyList_Check(ind)) {\n\t\tobj = PyArray_FromAny(ind, &indtype, 0, 0, FORCECAST);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tr = iter_subscript_Bool(self, (PyArrayObject *)obj);\n\t\t} \n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, &indtype, 0, 0, \n\t\t\t\t\t FORCECAST | BEHAVED_FLAGS);\n\t\t\tif (new==NULL) goto fail;\n\t\t\tobj = new;\n\t\t\tr = iter_subscript_int(self, (PyArrayObject *)obj);\n\t\t}\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\t\"unsupported iterator index\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPy_DECREF(obj);\n\t\treturn r;\n\t}\n\n\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\n fail:\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->itemsize;\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->copyswap;\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(self->dataptr, val->dataptr, swap,\n itemsize);\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t\tPyArray_ITER_NEXT(val);\n\t\tif (val->index==val->size) \n\t\t\tPyArray_ITER_RESET(val);\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_Typecode typecode;\n\tintp num;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\titemsize = typecode.itemsize = self->ao->itemsize;\n\ttypecode.type_num = self->ao->descr->type_num;\n copyswap = self->ao->descr->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\n\nstatic int\niter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val) \n{\n\tint i;\n\tPyObject *arrval=NULL;\n\tPyArrayIterObject *val_it=NULL;\n\tPyArray_Typecode type;\n\tPyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tint swap;\n\tint itemsize;\n\tint start, step_size;\n\tintp n_steps;\n\tPyObject *obj;\n PyArray_CopySwapFunc *copyswap;\n\t\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\ti = iter_ass_subscript(self, ind, val);\n\t\tPy_DECREF(ind);\n\t\treturn i;\n\t}\n\t\n\ttype.type_num = self->ao->descr->type_num;\n\titemsize = type.itemsize = self->ao->itemsize;\n\t\n\tarrval = PyArray_FromAny(val, &type, 0, 0, 0);\n\tif (arrval==NULL) return -1;\n\tval_it = (PyArrayIterObject *)PyArray_IterNew(arrval);\n\tif (val_it==NULL) goto fail;\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\n copyswap = PyArray_DESCR(arrval)->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\tgoto succeed;\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 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 copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, itemsize);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\tgoto succeed;\n\t\t}\n\t\twhile(n_steps--) {\n copyswap(self->dataptr, val_it->dataptr,\n swap, itemsize);\n\t\t\tfor(i=0; i < step_size; i++) \n\t\t\t\tPyArray_ITER_NEXT(self);\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\tgoto succeed;\n\t} \n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tif (PyArray_IsScalar(ind, Integer))\n\t\tobj = PyArray_FromScalar(ind, &indtype);\n\telse if (PyList_Check(ind)) {\n\t\tobj = PyArray_FromAny(ind, &indtype, 0, 0, FORCECAST);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tif (iter_ass_sub_Bool(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto fail;\n\t\t} \n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, &indtype, 0, 0, \n\t\t\t\t\t FORCECAST | BEHAVED_FLAGS);\n\t\t\tif (new==NULL) goto fail;\n\t\t\tPy_DECREF(obj);\n\t\t\tobj = new;\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 fail;\n\t\t}\n\t\telse goto fail;\n\t\tPy_DECREF(obj);\n\t\tgoto succeed;\n\t}\n\n\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\tgoto fail;\n\n succeed:\n\tPy_DECREF(val_it);\n\tPy_DECREF(arrval);\n\treturn 0;\n\n fail:\n\tPy_XDECREF(val_it);\n\tPy_XDECREF(arrval);\n\treturn -1;\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 if (PyArray_ISCONTIGUOUS(it->ao)) {\n r = PyArray_New(it->ao->ob_type, 1, &size, \n\t\t\t\tit->ao->descr->type_num,\n NULL, it->ao->data, it->ao->itemsize, \n\t\t\t\tit->ao->flags,\n (PyObject *)it->ao); \n\t\tif (r==NULL) return NULL;\n }\n else {\n r = PyArray_New(it->ao->ob_type, 1, &size, \n\t\t\t\tit->ao->descr->type_num,\n NULL, NULL, it->ao->itemsize, 0, \n (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\n\nstatic PyTypeObject PyArrayIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"scipy.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 | Py_TPFLAGS_HAVE_GC,/* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)arrayiter_traverse,\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)arrayiter_next,\t\t/* tp_iternext */\n iter_methods,\t\t\t\t/* tp_methods */\n};\n\n/** END of Array Iterator **/\n\n\n\n/*********************** Subscript Array Iterator *************************\n * *\n * This object handles subscript behavior for array objects. *\n * It is an iterator object with a next method *\n * It abstracts the n-dimensional mapping behavior to make the looping *\n * code more understandable (maybe) *\n * and so that indexing can be set up ahead of time *\n */ \n\n/* This checks the args for any fancy indexing objects */\n\n#define SOBJ_NOTFANCY 0 \n#define SOBJ_ISFANCY 1\n#define SOBJ_BADARRAY 2\n#define SOBJ_TOOMANY 3\n#define SOBJ_LISTTUP 4\n\nstatic int\nfancy_indexing_check(PyObject *args)\n{\n\tint i, n;\n\tPyObject *obj;\n\tint retval = SOBJ_NOTFANCY;\n\n\tif (PyTuple_Check(args)) {\n\t\tn = PyTuple_GET_SIZE(args);\n\t\tif (n >= MAX_DIMS) return SOBJ_TOOMANY;\n\t\tfor (i=0; i=MAX_DIMS) return SOBJ_ISFANCY;\n\t\tfor (i=0; i SOBJ_ISFANCY) return retval;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* convert an indexing object to an INTP indexing array iterator\n if possible -- otherwise, it is a Slice or Ellipsis object\n and has to be interpreted on bind to a particular \n array so leave it NULL for now.\n */\nstatic int\n_convert_obj(PyObject *obj, PyArrayIterObject **iter)\n{\n\tPyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tPyObject *arr;\n\n\tif (PySlice_Check(obj) || (obj == Py_Ellipsis))\n\t\t*iter = NULL;\n\telse {\n\t\tarr = PyArray_FromAny(obj, &indtype, 0, 0, FORCECAST);\n\t\tif (arr == NULL) return -1;\n\t\t*iter = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (*iter == NULL) return -1;\n\t}\n\treturn 0;\n}\n\n/* Adjust dimensionality and strides for index object iterators \n --- i.e. broadcast\n */\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->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->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=NULL, *obj=NULL;\n\tint i, j, n, curraxis, ellipexp, noellip;\n\tPyArrayIterObject *it;\n\tintp dimsize;\n\tintp *indptr;\n\n\t/* Remove old binding if any */\n\tPy_XDECREF(mit->ait);\n\tmit->ait = NULL;\n\n\tPy_XDECREF(mit->subspace);\n\tmit->subspace = NULL;\n\t\n\tsubnd = arr->nd - mit->numiter;\n\tif (subnd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"too many indices for array\");\n\t\treturn;\n\t}\n\n\tmit->ait = (PyArrayIterObject *)PyArray_IterNew((PyObject *)arr);\n\tif (mit->ait == NULL) return;\n\n\t/* If this is just a view, then do nothing more */\n\t/* views are handled by just adjusting the strides\n\t and dimensions of the object.\n\t*/\n\t \n\tif (mit->view) return;\n\n\t/* no subspace iteration needed. 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\tif (mit->subspace == NULL) goto fail;\n\tPy_DECREF(sub);\n\n\t/* Expand dimensions of result */\n\tn = mit->subspace->ao->nd;\n\tfor (i=0; idimensions[mit->nd+i] = mit->subspace->ao->dimensions[i];\n\tmit->nd += n;\n\n\t/* Now, we still need to interpret the ellipsis and slice objects \n\t to determine which axes the indexing arrays are referring to\n\t*/\n\tn = PyTuple_GET_SIZE(mit->indexobj);\n\n\t/* The number of dimensions an ellipsis takes up */\n\tellipexp = arr->nd - n + 1;\n\t/* Now fill in iteraxes -- remember indexing arrays have been \n converted to 0's in mit->indexobj */\n\tcurraxis = 0;\n\tj = 0;\n\tnoellip = 1; /* Only expand the first ellipsis */\n\tmemset(mit->bscoord, 0, sizeof(intp)*arr->nd);\n\tfor (i=0; iindexobj, i);\n\t\tif (PyInt_Check(obj) || PyLong_Check(obj)) \n\t\t\tmit->iteraxes[j++] = curraxis++;\n\t\telse if (noellip && obj == Py_Ellipsis) {\n\t\t\tcurraxis += ellipexp;\n\t\t\tnoellip = 0;\n\t\t}\n\t\telse {\n\t\t\tint start=0;\n\t\t\tint 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}\t\t\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn;\n\n fail:\n\tPy_XDECREF(sub);\n\tPy_XDECREF(mit->ait);\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_Typecode typecode = {PyArray_BOOL, 0, 0};\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\tba = (PyArrayObject *)PyArray_FromAny(myBool, &typecode, 0, 0, \n\t\t\t\t\t CARRAY_FLAGS);\n\tif (ba == NULL) return -1;\n\tnd = ba->nd;\n\tfor (j=0; jdata;\n\tcount = 0;\n\n\t/* pre-determine how many nonzero entries there are */\n\tfor (i=0; iao->data;\n\t\tcoords[j] = 0;\n\t\tdims_m1[j] = ba->dimensions[j]-1;\n\t}\n\n\tptr = (Bool *)ba->data;\n\n\tif (count == 0) return nd;\n\n\t/* Loop through the Boolean array and copy coordinates\n\t for non-zero entries */\n\tfor (i=0; i=0; j--) {\n\t\t\tif (coords[j] < dims_m1[j]) {\n\t\t\t\tcoords[j]++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcoords[j] = 0;\n\t\t\t}\n\t\t}\n\t}\n\treturn nd;\n\n fail:\n\tfor (j=0; jiters[i] = NULL;\n \tmit->view = 0;\n \tmit->index = 0;\n \tmit->ait = NULL;\n \tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tfancy = fancy_indexing_check(indexobj);\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\tif (fancy == SOBJ_NOTFANCY) { /* bail out */\n\t\tmit->view = 1;\n\t\tgoto ret;\n\t}\n\n\tif (fancy == SOBJ_BADARRAY) {\n\t\tPyErr_SetString(PyExc_TypeError,\t\t\t\\\n\t\t\t\t\"arrays used as indexes must be of \" \\\n\t\t\t\t\"integer type\");\n\t\tgoto fail;\n\t}\n\tif (fancy == SOBJ_TOOMANY) {\n\t\tPyErr_SetString(PyExc_TypeError, \"too many indicies\");\n\t\tgoto fail;\n\t}\n\n\tif (fancy == SOBJ_LISTTUP) {\n\t\tPyObject *newobj;\n\t\tnewobj = PySequence_Tuple(indexobj);\n\t\tif (newobj == NULL) goto fail;\n\t\tPy_DECREF(indexobj);\n\t\tindexobj = newobj;\n\t\tmit->indexobj = indexobj;\n\t}\n\n#undef SOBJ_NOTFANCY \n#undef SOBJ_ISFANCY \n#undef SOBJ_BADARRAY \n#undef SOBJ_TOOMANY \n#undef SOBJ_LISTTUP \n\n\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\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 (PyList_Check(indexobj) || PyArray_Check(indexobj)) {\n\t\tmit->numiter = 1;\n\t\tarr = PyArray_FromAny(indexobj, &indtype, 0, 0, FORCECAST);\n\t\tif (arr == NULL) goto fail;\n\t\tmit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (mit->iters[0] == NULL) 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(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\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = new;\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\t/* Store the number of iterators actually converted */\n\t\t/* These will be mapped to actual axes at bind time */\n\t\tif (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)\n\t\t\tgoto fail;\n\t}\n\n ret:\n PyObject_GC_Track(mit);\n return (PyObject *)mit;\n \n fail:\n\tPy_XDECREF(arr);\n\tPy_XDECREF(mit->indexobj);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n PyObject_GC_Del(mit);\n\treturn NULL;\n}\n\n\n/* return unbound mapiter object */\n\nstatic PyObject *\narraymapiter_new(PyTypeObject *type, PyObject *args, PyObject *kwds) \n{\n\tPyObject *newtup, *res;\n\tint n;\n\n\tif (!PyTuple_Check(args)) {\n\t\tPyErr_BadInternalCall();\n\t\treturn NULL;\n\t}\n\n\tn = PyTuple_GET_SIZE(args);\n\t\n\tif (n < 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"must be initialized with >= 1 argument\");\n\t\treturn NULL;\n\t}\n\t\n\tif (n > 1) {\n\t\tnewtup = PyTuple_GetSlice(args, 0, n);\n\t\tif (newtup == NULL) return NULL;\n\t\tres = PyArray_MapIterNew(newtup);\n\t\tPy_DECREF(newtup);\n\t}\n\telse { /* n == 1 */\n\t\tnewtup = PyTuple_GET_ITEM(args, 0);\n\t\tres = PyArray_MapIterNew(newtup);\n\t}\n\n\treturn res; \t\n}\n\n\n/* Returns a 0-dim array holding the element desired */\n/*\nstatic PyObject *\narraymapiter_next(PyArrayMapIterObject *mit)\n{\n\tPyObject *ret;\n\tif (mit->ait == NULL) return NULL;\n\tif (mit->view) return NULL;\n\tif (mit->index < mit->size) {\n\t\tret = PyArray_ToScalar(mit->dataptr, mit->ait->ao);\n\t\tPyArray_MapIterNext(mit);\n\t\treturn ret;\n\t}\n return NULL;\n}\n*/\n\nstatic void\narraymapiter_dealloc(PyArrayMapIterObject *mit)\n{\n\tint i;\n PyObject_GC_UnTrack(mit);\n Py_XDECREF(mit->ait);\n\tPy_XDECREF(mit->indexobj);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n PyObject_GC_Del(mit);\n}\n\nstatic int\narraymapiter_traverse(PyArrayMapIterObject *mit, visitproc visit, void *arg)\n{\n\tint ret, i;\n if (mit->ait != NULL)\n if ((ret = visit((PyObject *)(mit->ait), arg)) != 0) \n\t\t\treturn ret;\t\n\n\tif (mit->iters != NULL) \n\t\tfor (i=0; inumiter; i++) \n\t\t\tif (mit->iters[i] != NULL) \n\t\t\t\tif ((ret=visit((PyObject *)mit->iters[i], \n\t\t\t\t\t arg)) != 0)\n\t\t\t\t\treturn ret;\n\n\tif (mit->indexobj != NULL)\n\t\tif ((ret = visit(mit->indexobj, arg)) != 0) return ret;\n\t\n return 0;\n}\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 MapIterNew must be \n that does not work. 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 char doc_mapiter_bind[] = \"obj.bind(a)\\n Bind an array to the \"\\\n\t\"mapiter object\";\n\nstatic PyObject *\nmapiter_bind(PyArrayMapIterObject *mit, PyObject *args)\n{\n\tPyArrayObject *arr;\n\n if (!PyArg_ParseTuple(args, \"O!\", &PyArray_Type, &arr)) return NULL;\n\n \tPyArray_MapIterBind(mit, arr);\n\n\tif (mit->ait == NULL) return NULL;\n\t\n \tPyArray_MapIterReset(mit);\n\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyMethodDef mapiter_methods[] = {\n\t{\"bind\", (PyCFunction)mapiter_bind, 1, doc_mapiter_bind},\n {NULL,\t\tNULL}\t\t\n};\n*/\n\n\nstatic PyTypeObject PyArrayMapIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"scipy.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 | Py_TPFLAGS_HAVE_GC,/* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)arraymapiter_traverse,\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, /*arraymapiter_next,*/\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 (newfunc)arraymapiter_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n\n};\n\n/** END of Subscript Iterator **/\n\n\n\n", "source_code_before": " /*\n Provide multidimensional arrays as a basic object type in python. \n\nBased on Original Numeric implementation\nCopyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\nwith contributions from many Numeric Python developers 1995-2004 *\n\nHeavily modified in 2005 with inspiration from Numarray \n\nby\n\nTravis Oliphant\nAssistant Professor at\nBrigham Young University \n\nmaintainer email: oliphant.travis@ieee.org\n\nNumarray design (which provided guidance) by \nSpace Science Telescope Institute \n (J. Todd Miller, Perry Greenfield, Rick White)\n\n*/\n\n/* $Id: arrayobject.c,v 1.59 2005/09/14 00:14:00 teoliphant Exp $ */\n\n/*\n#include \"Python.h\"\n#include \"structmember.h\"\n\n#define _MULTIARRAYMODULE\n#include \"Numeric3/arrayobject.h\"\n*/\n\n/* Helper functions */\n\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\n\nstatic intp\nPyArray_PyIntAsIntp(PyObject *o)\n{\n\tlonglong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr=NULL;\n\tPyArray_Typecode typecode = {PyArray_INTP, 0, 0};\n\tintp ret;\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\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\tarr = PyArray_CastToType((PyArrayObject *)o, &typecode);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tarr = PyArray_FromScalar(o, &typecode);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((intp *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\t\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONGLONG != SIZEOF_PY_INTPTR_T)\n\tif ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C intp\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (intp) long_value;\n}\n\n\nstatic PyObject *array_int(PyArrayObject *v);\n\nstatic int\nPyArray_PyIntAsInt(PyObject *o)\n{\n\tlong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr=NULL;\n\tPyArray_Typecode typecode = {PyArray_INT, 0, 0};\n\tint ret;\n\t\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\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\tarr = PyArray_CastToType((PyArrayObject *)o, &typecode);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tarr = PyArray_FromScalar(o, &typecode);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((int *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONG != SIZEOF_INT)\n\tif ((long_value < INT_MIN) || (long_value > INT_MAX)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C int\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (int) long_value;\n}\n\n\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\nstatic char *\nPyArray_Zero(PyArrayObject *arr)\n{\n char *zeroval;\n char *buf;\n int buf_len;\n PyObject *obj, *ret;\n\n zeroval = PyDataMem_NEW(arr->itemsize);\n if (zeroval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n if (PyArray_ISOBJECT(arr)) {\n obj=PyInt_FromLong((long) 0);\n memcpy(zeroval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return zeroval;\n }\n ret = PyObject_GetAttrString((PyObject *)arr, \"_zero\");\n if (ret != NULL) {\n if (PyObject_AsReadBuffer(ret, (const void **)&buf, \n &buf_len) < 0) {\n PyErr_SetString(PyExc_ValueError, \n \"_zero not returning \" \\\n \"writeable buffer\");\n Py_DECREF(ret);\n return NULL;\n }\n memcpy(zeroval, buf, buf_len);\n Py_DECREF(ret);\n }\n if (PyErr_Occurred()) PyErr_Clear();\n memset(zeroval, 0, arr->itemsize);\n return zeroval;\n}\n\nstatic char *\nPyArray_One(PyArrayObject *arr)\n{\n char *oneval;\n char *buf;\n int buf_len, ret2;\n PyObject *obj, *ret;\n\n oneval = PyDataMem_NEW(arr->itemsize);\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 ret = PyObject_GetAttrString((PyObject *)arr, \"_one\");\n if (ret != NULL) {\n if (PyObject_AsReadBuffer(ret, (const void **)&buf, \n &buf_len) < 0) {\n PyErr_SetString(PyExc_ValueError, \n \"_one not returning \" \\\n \"writeable buffer\");\n Py_DECREF(ret);\n PyDataMem_FREE(oneval);\n return NULL;\n }\n memcpy(oneval, buf, buf_len);\n Py_DECREF(ret);\n }\n if (PyErr_Occurred()) PyErr_Clear();\n\n ret2 = arr->descr->setitem(obj, oneval, arr);\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->itemsize;\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 *)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 { free(new_data); return NULL; }\n}\n\n/* end Helper functions */\n\n\nstatic PyObject *PyArray_New(PyTypeObject *, int nd, intp *, \n int, intp *, char *, 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. */\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/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\n\nstatic char *\nindex2ptr(PyArrayObject *mp, int i) \n{\n\tif (i==0 && (mp->nd == 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\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\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->copyswap;\n\tcopyswapn = dest->descr->copyswapn;\n\n elsize = dest->itemsize;\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->itemsize;\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\tPyArray_Typecode typecode;\n\n\n\ttypecode.type_num = dest->descr->type_num;\n\ttypecode.itemsize = dest->itemsize;\n\ttypecode.fortran = PyArray_ISFORTRAN(dest);\n\t\t\t\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n\t\t\t\t\t &typecode, 0,\n\t\t\t\t\t dest->nd, 0);\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\nstatic PyObject *\nPyArray_FromDimsAndDataAndDescr(int nd, int *d, \n PyArray_Descr *descr,\n char *data) {\n\tPyObject *ret;\n\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\n\tintp newd[MAX_DIMS];\n\t\n\tfor (i=0; itype_num, NULL, data, descr->elsize, \n\t\t\t CARRAY_FLAGS, NULL);\n#else\n\tret = PyArray_New(&PyArray_Type, nd, (intp *)d, \n descr->type_num, NULL, data, descr->elsize, \n\t\t\t CARRAY_FLAGS, NULL);\n#endif\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_FromDimsAndData(int nd, int *d, int type, char *data) \n{\n\tPyObject *ret;\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\t\n\tintp newd[MAX_DIMS];\n\n\tfor (i=0; iob_type, m1->nd, \n\t\t\t\t\t m1->dimensions,\n\t\t\t\t\t m1->descr->type_num,\n\t\t\t\t\t NULL, NULL, m1->itemsize,\n\t\t\t\t\t 0, (PyObject *)m1);\n\t\n if (PyArray_CopyInto(ret, m1) == -1) return NULL;\n\t\n return (PyObject *)ret;\n}\n\n\nstatic PyObject *array_item(PyArrayObject *, int);\n\nstatic PyObject *\nPyArray_Scalar(char *data, int type_num, int itemsize, int swap)\n{\n PyArray_Descr *descr;\n\tPyTypeObject *type;\n\tPyObject *obj;\t\n\tchar *destptr;\n PyArray_CopySwapFunc *copyswap;\n\n descr = PyArray_DescrFromType(type_num);\n if (descr == NULL) return NULL;\n type = descr->typeobj;\n copyswap = descr->copyswap;\n\tif (type_num == PyArray_STRING) \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_ISFLEXIBLE(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 {\n\t\t\tdestptr = PyDataMem_NEW(itemsize);\n\t\t\tif (destptr == NULL) {\n\t\t\t\tPyObject_Del(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tif (type_num == PyArray_UNICODE) {\n\t\t\t\tPyUnicode_AS_UNICODE(obj) = \\\n\t\t\t\t\t(Py_UNICODE *)destptr;\n\t\t\t\t((PyUnicodeObject*)obj)->length = itemsize / \\\n\t\t\t\t\tsizeof(Py_UNICODE);\n\t\t\t\t((PyUnicodeObject*)obj)->hash = -1;\n\t\t\t}\n\t\t\telse {\n\t\t\t\t((PyVoidScalarObject *)obj)->obval = destptr;\n\t\t\t\t((PyVoidScalarObject *)obj)->ob_size = itemsize;\n\t\t\t}\n\t\t}\n\t}\n\telse {\n\t\tdestptr = &(((PyScalarObject*)obj)->obval);\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*/\nstatic PyObject *\nPyArray_ToScalar(char *data, PyArrayObject *arr)\n{\n\tint type_num = arr->descr->type_num;\n\tint itemsize = arr->itemsize;\n int swap = !(PyArray_ISNOTSWAPPED(arr));\n\n\treturn PyArray_Scalar(data, type_num, itemsize, swap);\n}\n\n\n/* Return Python scalar if 0-d array object is encountered */\n\nstatic PyObject *\nPyArray_Return(PyArrayObject *mp) \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((PyObject *)mp) && 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*/\nstatic int \nPyArray_RegisterDataType(PyTypeObject *type)\n{\n\tPyArray_Descr *descr;\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 = malloc(sizeof(PyArray_Descr));\n\tmemcpy(descr, PyArray_DescrFromType(PyArray_VOID), \n\t sizeof(PyArray_Descr));\n\ttypenum = PyArray_USERDEF + PyArray_NUMUSERTYPES;\n\tdescr->type_num = typenum;\n\tdescr->typeobj = 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 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 frees the copy of the Descr_table already there.\n places a pointer to the new one into the slot.\n*/\nstatic int\nPyArray_RegisterDescrForType(int typenum, PyArray_Descr *descr)\n{\n\tPyArray_Descr *old;\n\tint i;\n\n\tif (!PyTypeNum_ISUSERDEF(typenum)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"data type not registered\");\n\t\treturn -1;\n\t}\n\told = userdescrs[typenum-PyArray_USERDEF];\n\tdescr->typeobj = old->typeobj;\n\tdescr->type_num = typenum;\n\n#define _NULL_CHECK(member) \\\n\tif (descr->member == NULL) descr->member = old->member\n\n\tfor (i=0; imember == 0) descr->member = old->member\n\n\t_ZERO_CHECK(kind);\n\t_ZERO_CHECK(type);\n\t_ZERO_CHECK(elsize);\n\t_ZERO_CHECK(alignment);\n#undef _ZERO_CHECK\n\n\tfree(old);\n\tuserdescrs[typenum-PyArray_USERDEF] = descr;\n\treturn 0;\n}\n\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 n3 = strlen((const char *)sep);\n if (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 \"\\\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->itemsize,\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->itemsize,\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 = strlen((const char *)format);\n while(it->index < it->size) {\n obj = self->descr->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\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->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\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 if (PyArray_TYPE(self) == PyArray_OBJECT) {\n PyErr_SetString(PyExc_ValueError, \"a string for the data\"\\\n\t\t\t\t\"in an object array is not appropriate\");\n return NULL;\n }\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->itemsize;\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 != NULL)) {\n\t\t/* Free internal references if an Object array */\n\t\tPyArray_XDECREF(self);\n\n PyDataMem_FREE(self->data);\n }\n\t\n if (self->dimensions != NULL) {\n PyDimMem_FREE(self->dimensions); \n\t}\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\n\nstatic PyObject *\narray_item(PyArrayObject *self, int i) \n{\n char *item;\n PyArrayObject *r;\n\n\n\tif(self->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n if ((item = index2ptr(self, i)) == NULL) return NULL;\n\n\tr = (PyArrayObject *)PyArray_New(self->ob_type, \n\t\t\t\t\t self->nd-1, self->dimensions+1, \n\t\t\t\t\t self->descr->type_num, \n\t\t\t\t\t self->strides+1, item, \n\t\t\t\t\t self->itemsize, self->flags,\n\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_item(self, i));\n}\n\n\nstatic int \narray_ass_item(PyArrayObject *self, int 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\n if (i < 0) i = i+self->dimensions[0];\n\n if (self->nd > 1) {\n if((tmp = (PyArrayObject *)array_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->setitem(v, item, self) == -1) return -1;\n return 0;\n}\n\n/* -------------------------------------------------------------- */\nstatic int\nslice_coerce_index(PyObject *o, int *v)\n{\n\t*v = PyArray_PyIntAsInt(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, int length,\n int *start, int *stop, int *step,\n intp *slicelength)\n{\n\tint 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 int\nparse_subindex(PyObject *op, int *step_size, intp *n_steps, int max)\n{\n\tint 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\tint 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_PyIntAsInt(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, start, offset, n_add, n_pseudo;\n int step_size;\n\tintp n_steps;\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, *tup;\n\tint n1, n2, n3, val;\n\tint i;\n\n\ttup = PyTuple_New(mit->nd);\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\tPyTuple_SET_ITEM(tup, i++, PyInt_FromLong((long)val++));\n\tval = 0;\n\twhile(val < n1)\n\t\tPyTuple_SET_ITEM(tup, i++, PyInt_FromLong((long)val++));\n\tval = n1+n2;\n\twhile(val < n3)\n\t\tPyTuple_SET_ITEM(tup, i++, PyInt_FromLong((long)val++));\n\n\tnew = PyArray_Transpose(*ret, tup);\n\tPy_DECREF(tup);\n\tPy_DECREF(*ret);\n\t*ret = (PyArrayObject *)new;\n}\n\n\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\tret = (PyArrayObject *)\\\n\t\tPyArray_New(temp->ob_type, mit->nd, mit->dimensions, \n\t\t\t temp->descr->type_num, NULL, NULL, \n\t\t\t temp->itemsize, \n\t\t\t PyArray_ISFORTRAN(temp),\n\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\treturn NULL;\n\tindex = it->size;\n\tswap = ((temp->flags & NOTSWAPPED) != (ret->flags & NOTSWAPPED));\n copyswap = ret->descr->copyswap;\n\tPyArray_MapIterReset(mit);\n\twhile (index--) {\n copyswap(it->dataptr, mit->dataptr, swap, ret->itemsize);\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\tPyArray_Typecode typecode = {0, 0, 0};\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Unbound Map Iterator */\n\tif (mit->ait == NULL) return -1;\n\n\ttypecode.type_num = mit->ait->ao->descr->type_num;\n\ttypecode.itemsize = mit->ait->ao->itemsize;\n\n\tarr = PyArray_FromAny(op, &typecode, \n\t\t\t 0, 0, FORCECAST);\n\tif (arr == NULL) return -1;\n\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, (PyArrayObject **)&arr);\n\t\t}\n\t}\n\t\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) \n\t\treturn -1;\n\n\tindex = mit->size;\n\tswap = ((mit->ait->ao->flags & NOTSWAPPED) != \\\n\t\t(PyArray_FLAGS(arr) & NOTSWAPPED));\n\n copyswap = PyArray_DESCR(arr)->copyswap;\n\tPyArray_MapIterReset(mit);\n /* Need to decref OBJECT arrays */\n if (PyTypeNum_ISOBJECT(typecode.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 copyswap(mit->dataptr, NULL, swap, \n sizeof(PyObject *));\n PyArray_MapIterNext(mit);\n PyArray_ITER_NEXT(it);\n if (it->index == it->size)\n PyArray_ITER_RESET(it);\n }\n return 0;\n }\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\treturn 0;\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 0-dimensional arrays */\n\nstatic PyObject *\narray_subscript(PyArrayObject *self, PyObject *op) \n{\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n\tintp offset;\n int nd, i;\n PyArrayObject *other;\n\tPyArrayMapIterObject *mit;\n\n if (PyArray_IsScalar(op, Integer) || PyInt_Check(op) || \\\n PyLong_Check(op)) {\n intp value;\n value = PyArray_PyIntAsIntp(op);\n if (PyErr_Occurred())\n PyErr_Clear();\n else if (value >= 0) {\n if (value <= MAX_INT)\n return array_item(self, (int) value);\n }\n else if (value < 0) {\n if (value >= -MAX_INT) {\n if (self->nd > 0) value += self->dimensions[0];\n return array_item(self, (int) value);\n }\n }\n }\n\n\tif (PyArrayMapIter_Check(op)) {\n\t\tmit = (PyArrayMapIterObject *)op;\n\t\t/* bind to current array */\n\t\tPyArray_MapIterBind(mit, self);\n\t\t\n\t\t/* If the mapiterator was created with standard indexing\n\t\t behavior, fall through to view-based code */\n\t\tif (!mit->view) return PyArray_GetMap(mit);\n\t\top = mit->indexobj;\n\t}\n\telse { /* wrap arguments into a mapiter object */\n\t\tmit = (PyArrayMapIterObject *)PyArray_MapIterNew(op);\n\t\tif (mit == NULL) return NULL;\n\t\tif (!mit->view) { /* fancy indexing */\n\t\t\tPyArray_MapIterBind(mit, self);\n\t\t\tother = (PyArrayObject *)PyArray_GetMap(mit);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn (PyObject *)other;\n\t\t}\n\t\tPy_DECREF(mit);\n\t}\n\n\ti = PyArray_PyIntAsInt(op);\n\tif (!error_converting(i)) {\n\t\tif (i < 0 && self->nd > 0) i = i+self->dimensions[0];\n\t\treturn array_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\tif ((other = (PyArrayObject *)\t\t\t\t\t\\\n\t PyArray_New(self->ob_type, nd, dimensions, self->descr->type_num,\n\t\t\t strides, self->data+offset, \n\t\t\t self->itemsize, self->flags,\n\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 \narray_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op) \n{\n int ret, 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\n\tif (PyArrayMapIter_Check(index)) {\n\t\tmit = (PyArrayMapIterObject *)index;\n\t\t/* bind behavior to current array */\n\t\tPyArray_MapIterBind(mit, self);\n\t\t\t\n\t\t/* fall through if standard view-based map iterator */\n\t\tif (!mit->view) return PyArray_SetMap(mit, op);\n\t\tindex = mit->indexobj;\n\t}\n\telse {\n\t\tmit = (PyArrayMapIterObject *)PyArray_MapIterNew(index);\n\t\tif (mit == NULL) return -1;\n\t\tif (!mit->view) {\n\t\t\tPyArray_MapIterBind(mit, self);\n\t\t\tret = PyArray_SetMap(mit, op);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn ret;\n\t\t}\n\t\tPy_DECREF((PyObject*)mit);\n\t}\n\n\ti = PyArray_PyIntAsInt(index);\n\tif (!error_converting(i)) {\n\t\treturn array_ass_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 ret = PyArray_CopyObject(tmp, op);\n Py_DECREF(tmp);\n\t\n return ret;\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 \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\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}\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}\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 PyObject *args, *ret;\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n args = Py_BuildValue(\"(OO)\", m1, m2);\n ret = PyObject_Call(op, args, NULL);\n Py_DECREF(args);\n return ret;\n}\n\nstatic PyObject *\nPyArray_GenericUnaryFunction(PyArrayObject *m1, PyObject *op) \n{\n PyObject *args, *ret;\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n args = Py_BuildValue(\"(O)\", m1);\n ret = PyObject_Call(op, args, NULL);\n Py_DECREF(args);\n return ret;\n}\n\nstatic PyObject *\nPyArray_GenericInplaceBinaryFunction(PyArrayObject *m1, \n\t\t\t\t PyObject *m2, PyObject *op) \n{\n PyObject *args, *ret;\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n args = Py_BuildValue(\"(OOO)\", m1, m2, m1);\n ret = PyObject_Call(op, args, NULL);\n Py_DECREF(args);\n return ret;\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_all_nonzero(PyArrayObject *mp) \n{\n\tintp index;\n\tPyArrayIterObject *it;\n\tBool anyTRUE = 0;\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->nonzero(it->dataptr, mp)) {\n\t\t\tanyTRUE = 1;\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 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->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->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->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->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->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_all_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 r = (PyArrayObject *)\\\n\t\tPyArray_New(self->ob_type, self->nd, self->dimensions, \n\t\t\t self->descr->type_num, self->strides, data,\n\t\t\t self->itemsize, 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 any(self == el) */\n\n return PyObject_RichCompareBool((PyObject *)self, el, Py_EQ);\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 *)realloc(*string, *max_n); }\n\t\n if (nd == 0) {\n\t\t\n if ((op = descr->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\tfree(string); return NULL; \n\t}\n\t\n\tif (PyArray_ISFLEXIBLE(self)) {\n\t\tchar buf[100];\n\t\tsnprintf(buf, sizeof(buf), \"%d\", self->itemsize);\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 free(string);\n return ret;\n}\n\nstatic PyObject *PyArray_StrFunction=NULL;\nstatic PyObject *PyArray_ReprFunction=NULL;\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\n\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) \n{\n PyObject *array_other, *result;\n\n switch (cmp_op) \n {\n case Py_LT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less);\n case Py_LE:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less_equal);\n case Py_EQ:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then return the integer\n\t\t\t object 0. This fixes code that used to\n\t\t\t allow equality comparisons between arrays\n\t\t\t and other objects which would give a result\n\t\t\t of 0\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n result = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.equal);\n /* If the comparison results in NULL, then the \n\t\t\t two array objects can not be compared together so \n\t\t\t return zero \n */\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n return result;\n case Py_NE:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then objects cannot be \n\t\t\t compared and cannot be equal, therefore, \n\t\t\t return True;\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n result = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.not_equal);\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n return result;\n case Py_GT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.greater);\n case Py_GE:\n return PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t other, \n\t\t\t\t\t \t n_ops.greater_equal);\n }\n return NULL;\n}\n\nstatic PyObject *\n_check_axis(PyArrayObject *arr, int *axis, int flags)\n{\n\tPyObject *temp;\n\tint n = arr->nd;\n\n\tif ((*axis >= MAX_DIMS) || (n==0)) {\n\t\ttemp = PyArray_Ravel(arr,0);\n\t\t*axis = 0;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_FromAny((PyObject *)arr, NULL, \n\t\t\t\t\t 0, 0, flags);\n\t\t\tif (temp == NULL) return NULL;\n\t\t}\n\t\telse {\n\t\t\tPy_INCREF(arr);\n\t\t\ttemp = (PyObject *)arr;\n\t\t}\n\t}\n\tif (*axis < 0) *axis += n;\n\tif ((*axis < 0) || (*axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", *axis);\n\t\tPy_DECREF(temp);\n\t\treturn NULL;\n\t}\n\treturn temp;\n}\n\n#include \"arraymethods.c\"\n\n/* Lifted from numarray */\nstatic PyObject *\nPyArray_IntTupleFromIntp(int len, intp *vals)\n{\n\tint i;\n PyObject *intTuple = PyTuple_New(len);\n if (!intTuple) goto fail;\n for(i=0; ind == 0) return 1;\n\tsd = ap->itemsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\n\t}\n\treturn 1;\n}\n\n\nstatic int \n_IsFortranContiguous(PyArrayObject *ap) \n{\n\tint sd;\n\tint i;\n\t\n\tif (ap->nd == 0) return 1;\n\tsd = ap->itemsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i=0; i< ap->nd; ++i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\n\t}\n\treturn 1;\n}\n\nstatic int\n_IsAligned(PyArrayObject *ap) \n{\n\tint i, alignment, aligned=1;\n\tintp ptr;\n\tint type = ap->descr->type_num;\n\n\tif ((type == PyArray_STRING) || (type == PyArray_VOID))\n\t\treturn 1;\n\n\talignment = ap->descr->alignment;\n\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\tPyBufferProcs *pb;\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\tpb = base->ob_type->tp_as_buffer;\n\tif (pb == NULL || pb->bf_getwritebuffer == NULL)\n\t\treturn FALSE;\n\t\n\treturn TRUE;\n}\n\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\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not \n walk outside of the memory implied by either numbytes or\n a single segment array of the provided dimensions and element size if\n numbytes is 0 */\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, \n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\t\n\tif (numbytes == 0) \n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\t\n\tfor (i=0; i numbytes) {\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\treturn TRUE;\n\t\n}\n\n\n/* This is the main array creation routine. */\n\n/* Flags argument has multiple related meanings \n depending on data and strides: \n\n If data is given, then flags is flags associated with data. \n If strides is not given, then a contiguous strides array will be created\n and the CONTIGUOUS bit will be set. If the flags argument \n has the FORTRAN bit set, then a FORTRAN-style strides array will be\n created (and of course the FORTRAN flag bit will be set). \n\n If data is not given but created here, then flags will be DEFAULT_FLAGS\n and a non-zero flags argument can be used to indicate a FORTRAN style\n array is desired. \n*/\n\nstatic intp\n_array_fill_strides(intp *strides, intp *dims, int nd, intp itemsize, \n\t\t int inflag, int *objflags) \n{\n\tint i;\n\t/* Only make Fortran strides if not contiguous as well */\n\tif ((inflag & FORTRAN) && !(inflag & CONTIGUOUS)) {\n\t\tfor (i=0; i 1) *objflags &= ~CONTIGUOUS;\n\t\telse *objflags |= CONTIGUOUS;\n\t}\n\telse {\n\t\tfor (i=nd-1;i>=0;i--) {\n\t\t\tstrides[i] = itemsize;\n\t\t\titemsize *= dims[i] ? dims[i] : 1;\n\t\t}\n\t\t*objflags |= CONTIGUOUS;\n\t\tif (nd > 1) *objflags &= ~FORTRAN;\n\t\telse *objflags |= FORTRAN;\n\t}\n\treturn itemsize;\n}\n\n\t\nstatic PyObject *\nPyArray_New(PyTypeObject *subtype, int nd, intp *dims, int type_num,\n intp *strides, char *data, int itemsize, int flags,\n\t PyObject *obj)\n{\n\tPyArrayObject *self;\n\tPyArray_Descr *descr;\n\tregister int i;\n\tintp sd, temp=-1;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\tif (descr == NULL) return NULL;\n\n\tif (nd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"number of dimensions must be >=0\");\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 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\treturn NULL;\n\t\t}\n\t}\n\t\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) return NULL;\t\n\tself->descr = descr;\n\tself->dimensions = 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\n\tif (PyTypeNum_ISFLEXIBLE(type_num)) {\n\t\tif (itemsize < 1) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"type must provide an itemsize\");\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn NULL;\n\t\t}\n\t\tself->itemsize = itemsize;\n\t\t/* Guarantee that these kind of arrays are never byteswapped\n\t\t unknowingly. \n\t\t*/\n\t\tif (type_num != PyArray_UNICODE)\n\t\t\tself->flags |= NOTSWAPPED;\n\t}\n\telse self->itemsize = descr->elsize; \n\t\t\n\tsd = self->itemsize;\n\t\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn PyErr_NoMemory();\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\tPyDimMem_FREE(self->dimensions);\n\t\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\t\treturn NULL;\n\t\t\t}\t\t\t\t\n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t}\n \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 (a.data) doesn't work\n\t\t as it should. */\n\n\t\tif (sd==0) sd = sizeof(intp);\n\n\t\tif ((data = PyDataMem_NEW(sd))==NULL) {\n\t\t\tPyDimMem_FREE(self->dimensions);\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn PyErr_NoMemory();\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\n\t\t/* It is bad to have unitialized OBJECT pointers */\n\t\t/* We shouldn't need to check for the OBJECT Letter\n\t\t but perhaps it's best. */\n\t\tif (type_num == PyArray_OBJECT || \\\n\t\t type_num == PyArray_OBJECTLTR) {\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\tself->nd = nd;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\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;\n\t\tif (temp==-1) { /* 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\tres = PyObject_CallMethod((PyObject *)self, \n\t\t\t\t\t \"__array_finalize__\",\n\t\t\t\t\t \"O\", obj);\n\t\tif (res == NULL) {\n\t\t\tPyDimMem_FREE(self->dimensions);\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn NULL;\n\t\t}\n\t\telse Py_DECREF(res);\n\t}\n\n\treturn (PyObject *)self;\n}\n\n\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\n newsize = PyArray_MultiplyList(new_dimensions, new_nd);\n\n if (newsize == 0) {\n PyErr_SetString(PyExc_ValueError, \n \"newsize is zero; cannot delete an array \"\\\n \"in this way\");\n return NULL;\n }\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 = (((PyObject *)self)->ob_refcnt);\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\n\t\t/* Reallocate space if needed */\n\t\tnew_data = PyDataMem_RENEW(self->data, \n\t\t\t\t\t newsize*(self->itemsize));\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->itemsize;\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->itemsize;\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 */\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; idataptr, fromptr, itemsize);\n\t\t\tPyArray_ITER_NEXT(iter);\n\t\t}\n\n\t\tPy_DECREF(iter);\n\t\tPy_DECREF(behaved);\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\", \"strides\", \n \"swap\", \"fortran\", NULL};\n\tint itemsize = 0;\n\tPyArray_Typecode typecode = {PyArray_NOTYPE, 0, 0};\n\tint type_num = PyArray_NOTYPE;\n PyArray_Dims dims = {NULL, 0};\n PyArray_Dims strides = {NULL, 0};\n PyArray_Chunk buffer;\n\tint fortran = 0;\n int swapped = 0;\n\tPyArrayObject *ret;\n\n\tbuffer.ptr = NULL; \n /* Usually called with shape and type\n but can also be called with buffer, strides, and swapped info\n */\n\n\t/* For now, let's just use this to create an empty, contiguous \n\t array of a specific type and shape. \n\t*/\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&O&ii\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &dims, \n PyArray_TypecodeConverter,\n\t\t\t\t\t &typecode, \n PyArray_BufferConverter,\n &buffer,\n &PyArray_IntpConverter, \n &strides,\n &swapped, &fortran)) \n\t\treturn NULL;\n\t\n if (typecode.type_num ==PyArray_NOTYPE) {\n\t\ttypecode.type_num = PyArray_DOUBLE;\n\t\ttypecode.itemsize = sizeof(double);\n\t}\n\ttype_num = typecode.type_num;\n\titemsize = typecode.itemsize;\n\n\n if (dims.ptr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"need to give a \"\\\n \"valid shape as the first argument\");\n goto fail;\n }\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)PyArray_New(subtype, (int)dims.len, \n dims.ptr, type_num,\n NULL, NULL, itemsize, \n fortran, NULL);\n \n if (ret == NULL) goto fail;\n if (type_num == PyArray_OBJECT) { /* place Py_None */\n PyArray_FillObjectArray(ret, Py_None);\n }\n }\n else { /* buffer given -- use it */\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = buffer.len / itemsize;\n }\n else if (buffer.len < itemsize* \\\n PyArray_MultiplyList(dims.ptr, dims.len)) {\n PyErr_SetString(PyExc_TypeError, \n \"buffer is too small for \" \\\n \"requested array\");\n goto fail;\n }\n if (strides.ptr != NULL) {\n\t\t\tif (strides.len != dims.len) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides, if given, must be \"\\\n\t\t\t\t\t\t\"the same length as shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CheckStrides(itemsize, strides.len, \n\t\t\t\t\t\t buffer.len,\n\t\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides is incompatible \"\\\n\t\t\t\t\t\t\"with shape of requested\"\\\n\t\t\t\t\t\t\"array and size of buffer\");\n\t\t\t\tgoto fail;\n\t\t\t}\n }\n if (type_num == PyArray_OBJECT) {\n PyErr_SetString(PyExc_TypeError, \"cannot construct \"\\\n \"an object array from buffer data\");\n goto fail;\n }\n /* get writeable and aligned */\n if (fortran) buffer.flags |= FORTRAN;\n if (!(swapped)) buffer.flags |= NOTSWAPPED;\n ret = (PyArrayObject *)PyArray_New(subtype, dims.len, \n dims.ptr, type_num,\n strides.ptr,\n (char *)buffer.ptr, \n itemsize, \n buffer.flags, NULL); \n if (ret == 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 PyArray_Return(ret);\n \n fail:\n if (dims.ptr) PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return NULL;\n}\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 static PyObject *module=NULL;\n\n if (module==NULL) {\n module = PyImport_ImportModule(\"scipy.base._internal\");\n if (module == NULL) return NULL;\n }\n return PyObject_CallMethod(module, \"flagsobj\", \"Oii\", \n self, self->flags, 0);\n}\n\n/*\nstatic int\narray_flags_set(PyArrayObject *self, PyObject *obj) \n{\n\tint flagback = self->flags;\n\n if (PyDict_Check(obj)) {\n PyObject *new;\n\t\tnew = PyDict_GetItemString(obj, \"ALIGNED\");\n\t\tif (new) {\n\t\t\tif (PyObject_Not(new)) self->flags &= ~ALIGNED;\n\t\t\telse if (_IsAligned(self)) self->flags |= ALIGNED;\n\t\t\telse {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"cannot set aligned flag of \" \\\n\t\t\t\t\t\t\"mis-aligned array to True\");\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t}\n new = PyDict_GetItemString(obj, \"UPDATEIFCOPY\");\n if (new) {\n if (PyObject_Not(new)) {\n self->flags &= ~UPDATEIFCOPY;\n Py_DECREF(self->base);\n self->base = NULL;\n }\n else {\n\t\t\t\tself->flags = flagback;\n PyErr_SetString(PyExc_ValueError, \n \"cannot set UPDATEIFCOPY \" \\\n \"flag to True\");\n return -1;\n }\n }\n new = PyDict_GetItemString(obj, \"WRITEABLE\");\n if (new) {\n\t\t\tif (PyObject_IsTrue(new)) {\n\t\t\t\tif (_IsWriteable(self)) {\n\t\t\t\t\tself->flags |= WRITEABLE;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tself->flags = flagback;\n\t\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\t\"cannot set \"\t\\\n\t\t\t\t\t\t\t\"WRITEABLE \"\t\\\n\t\t\t\t\t\t\t\"flag to True of \"\\\n\t\t\t\t\t\t\t\"this array \");\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n else\n self->flags &= ~WRITEABLE;\n }\n new = PyDict_GetItemString(obj, \"NOTSWAPPED\");\n if (new) {\n if (PyObject_IsTrue(new))\n self->flags |= NOTSWAPPED;\n else {\n self->flags &= ~NOTSWAPPED;\n\t\t\t}\n\t\t}\n return 0;\n }\n PyErr_SetString(PyExc_ValueError, \n \"object must be a dictionary\");\n return -1;\n}\n*/\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\tif (!PyTuple_Check(val)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"shape must be a tuple\");\n\t\treturn -1;\n\t}\n\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\n\t\n\tif (self->nd > 0) { /* Free old dimensions and strides */\n\t\tPyDimMem_FREE(self->dimensions);\n\t}\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;\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\treturn -1;\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->itemsize;\n\t\n\tif (!PyArray_CheckStrides(self->itemsize, self->nd, numbytes, \n\t\t\t\t self->dimensions, newstrides.ptr)) {\n\t\tPyErr_SetString(PyExc_ValueError, \"strides is not \"\\\n\t\t\t\t\"compatible with available memory\");\n\t\treturn -1;\n\t}\n\tmemcpy(self->strides, newstrides.ptr, sizeof(intp)*newstrides.len);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\treturn 0;\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->itemsize);\n}\n\nstatic PyObject *\narray_size_get(PyArrayObject *self)\n{\n\tlonglong size=PyArray_SIZE(self);\n\tif (size > MAX_INT || size < MIN_INT)\n\t\treturn PyLong_FromLongLong(size);\n\telse \n\t\treturn PyInt_FromLong((long) size);\n}\n\n\nstatic PyObject *\narray_typechar_get(PyArrayObject *self)\n{\n\tif PyArray_ISFLEXIBLE(self) \n\t\treturn PyString_FromFormat(\"%c%d\", (self->descr->type),\n\t\t\t\t\t self->itemsize);\n\telse \n\t\treturn PyString_FromStringAndSize(&(self->descr->type), 1);\n}\n\nstatic PyObject *\narray_typestr_get(PyArrayObject *self)\n{\n\tstatic char endians[] = \"<>\";\n\tchar endian;\n\tint which;\n\tunsigned long val = 1;\n\tchar *s;\n\tchar basic_=self->descr->kind;\n\n\ts = (char *)&val; /* s[0] == 0 implies big-endian */\n\twhich = (PyArray_ISNOTSWAPPED(self) ? 0 : 1);\n\tif (s[0] == 0) which = 1 - which;\n\tendian = endians[which]; \n\t\n\tif ((basic_==PyArray_VOIDLTR) || (basic_==PyArray_STRINGLTR) || \\\n\t (basic_==PyArray_OBJECTLTR) || (self->itemsize == 1))\n\t\treturn PyString_FromFormat(\"|%c%d\", basic_, self->itemsize);\n\telse\n\t\treturn PyString_FromFormat(\"%c%c%d\", endian, basic_,\n\t\t\t\t\t self->itemsize);\n}\n\nstatic PyObject *\narray_descr_get(PyArrayObject *self)\n{\n\tPyObject *res;\n\tPyObject *dobj;\n\n\t/* hand this off to the typeobject */\n\t/* or give default */\n\tif (PyArray_ISUSERDEF(self)) {\n\t\tres = PyObject_GetAttrString((PyObject *)self->descr->typeobj, \n\t\t\t\t\t \"__array_descr__\");\n\t\tif (res) return res;\n\t\tPyErr_Clear();\n\t}\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\n\nstatic PyObject *\narray_type_get(PyArrayObject *self)\n{\n\treturn PyArray_TypeObjectFromType(self->descr->type_num);\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*/\n\nstatic int\narray_type_set(PyArrayObject *self, PyObject *arg)\n{\n PyArray_Typecode newtype = {PyArray_NOTYPE, 0, 0};\n intp newdim;\n int index;\n char *msg = \"new type not compatible with array.\";\n\n if ((PyArray_TypecodeConverter(arg, &newtype) < 0) ||\n newtype.type_num == PyArray_NOTYPE) {\n PyErr_SetString(PyExc_TypeError, \"invalid type for array\");\n return -1;\n }\n if (!(PyArray_ISONESEGMENT(self) ||\t\t\\\n\t (newtype.itemsize != self->itemsize))) {\n PyErr_SetString(PyExc_ValueError, msg);\n return -1; \n }\n\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\n if (newtype.itemsize < self->itemsize) {\n /* if it is compatible increase the size of the dimension\n at end (or at the front for FORTRAN)\n */\n if (self->itemsize % newtype.itemsize != 0) {\n PyErr_SetString(PyExc_ValueError, msg);\n return -1;\n }\n newdim = self->itemsize / newtype.itemsize;\n\t\tself->dimensions[index] *= newdim;\n self->strides[index] = newtype.itemsize;\n\t}\n \n else if (newtype.itemsize > self->itemsize) {\n \n /* Determine if last (or first if FORTRAN) dimension\n is compatible */\n\n\t\tnewdim = self->dimensions[index] * self->itemsize;\n if ((newdim % newtype.itemsize) != 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, msg);\n return -1;\n }\n\t\t\n self->dimensions[index] = newdim / newtype.itemsize;\n self->strides[index] = newtype.itemsize;\n\t\t\n }\n\t\n \n /* fall through -- adjust type*/\n\n self->descr = PyArray_DescrFromType(newtype.type_num);\n self->itemsize = newtype.itemsize;\n PyArray_UpdateFlags(self, ALIGNED);\n return 0;\n\n}\n\n\n\nstatic PyObject *\narray_base_get(PyArrayObject *self)\n{\n\tif (self->base == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\telse {\n\t\tPy_INCREF(self->base);\n\t\treturn self->base;\n\t}\n}\n\n\nstatic PyObject *\narray_real_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *)ret;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n}\n\n\nstatic int\narray_real_set(PyArrayObject *self, PyObject *val)\n{\n\tPyArrayObject *ret;\n\tPyArrayObject *new;\n\tint rint;\n\n\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0);\n\tif (new == NULL) return -1;\n\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) 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\treturn rint;\n}\n\nstatic PyObject *\narray_imag_get(PyArrayObject *self)\n{\t\n\tPyArrayObject *ret;\n\tint itemsize;\n\tint typenum;\n PyArray_Typecode type;\n\t\n\ttype.type_num = self->descr->type_num;\n\ttype.itemsize = self->itemsize;\n\ttype.fortran = PyArray_ISFORTRAN(self);\n\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\titemsize = self->itemsize >> 1;\n\t\ttypenum = self->descr->type_num - PyArray_NUM_FLOATTYPE;\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 typenum,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data + itemsize,\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\tret = (PyArrayObject *)PyArray_Zeros(self->nd, \n\t\t\t\t\t\t self->dimensions, &type);\n\t\tret->flags &= ~WRITEABLE;\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic int\narray_imag_set(PyArrayObject *self, PyObject *val)\n{\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyArrayObject *ret;\n\t\tPyArrayObject *new;\n\t\tint rint;\n\n\t\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0); \n\t\tif (new == NULL) return -1;\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides+ \\\n\t\t\t\t\t\t (self->itemsize >> 1) ,\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) {\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_Typecode typecode;\n int swap;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode.type_num = self->descr->type_num;\n\ttypecode.itemsize = self->itemsize;\n\ttypecode.fortran = PyArray_ISFORTRAN(self);\n\t\n\tarr = PyArray_FromAny(val, &typecode, \n\t\t\t 0, 0, FORCECAST);\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->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 copyswap(selfit->dataptr, NULL, swap, \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->itemsize);\n copyswap(selfit->dataptr, NULL, swap, self->itemsize);\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\t{\"base\",\n\t (getter)array_base_get,\n\t NULL,\n\t \"base object\"},\n {\"dtype\", \n\t (getter)array_type_get, \n\t (setter)array_type_set,\n\t \"get array type class\"},\n\t{\"dtypechar\",\n\t (getter)array_typechar_get,\n\t NULL,\n\t \"get array type character code\"},\n\t{\"dtypestr\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"get array type string\"},\n {\"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_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\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\n\nstatic char Arraytype__doc__[] = \n \"A array object represents a multidimensional, homogeneous array\\n\"\n\t\" of basic values. Arrays are sequence, mapping and numeric\\n\"\n\t\" objects. More information is available in the scipy module and\\n\"\n\t\" by looking at the methods and attributes of an array.\";\n\nstatic PyTypeObject PyBigArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"scipy.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 \n offsetof(PyArrayObject, weakreflist), /*tp_weaklistoffset */\n\n /* Iterator support (use standard) */\n\n (getiterfunc)0, \t\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 0,\t /* tp_alloc */ \n (newfunc)array_new,\t\t /* tp_new */\n 0,\t \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 \"scipy.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) \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 if (PySequence_Length(s) == 0) \n\t\treturn 1;\n\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);\n\t\tif(d >= 0) d++;\n\t}\n Py_DECREF(e);\n return d;\n}\n\nstatic int\ndiscover_itemsize(PyObject *s, int nd, int *itemsize) \n{\n\tint n, r, i;\n\tPyObject *e;\n\t\n\tn = PyObject_Length(s);\n\n\tif ((nd == 0) || PyString_Check(s) ||\t\t\\\n\t PyUnicode_Check(s) || PyBuffer_Check(s)) {\n\t\tif PyUnicode_Check(s) \n\t\t\t*itemsize = MAX(*itemsize, sizeof(Py_UNICODE)*n);\n\t\telse\n\t\t\t*itemsize = MAX(*itemsize, n);\n\t\treturn 0;\n\t}\n\tfor (i=0; i n_lower) n_lower = d[1];\n }\n d[1] = n_lower;\n\t\n return 0;\n}\n\nstatic void\n_array_small_type(int chktype, int mintype, int chksize, int minsize, \n\t\t PyArray_Typecode *outtype)\n{\n\touttype->type_num = MAX(chktype, mintype);\n\tif (PyTypeNum_ISFLEXIBLE(outtype->type_num) &&\t\\\n\t PyTypeNum_ISFLEXIBLE(mintype)) {\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 == PyArray_STRING) {\n\t\t\touttype->itemsize = MAX(chksize, 2*minsize);\n\t\t}\n\t\telse {\n\t\t\touttype->itemsize = MAX(chksize, minsize);\n\t\t}\n\t}\n\telse {\n\t\touttype->itemsize = chksize;\n\t}\n\treturn;\t\n}\n\nstatic void\n_array_find_type(PyObject *op, PyArray_Typecode *minitype, \n\t\t PyArray_Typecode *outtype, int max)\n{\n int l;\n PyObject *ip;\n\tint chktype=0;\n\tint chksize=0;\n\tint mintype, minsize;\n\n\tif (minitype == NULL) {\n\t\tmintype = PyArray_BOOL;\n\t\tminsize = sizeof(Bool);\n\t}\n\telse {\n\t\tmintype = minitype->type_num;\n\t\tminsize = minitype->itemsize;\n\t}\n\n \n if (max < 0 || mintype == -1) goto deflt;\n\t\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_TYPE(op);\n\t\tchksize = PyArray_ITEMSIZE(op);\n\t\tgoto finish;\n\t}\n\t\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tPyArray_TypecodeFromScalar(op, outtype);\n\t\tchktype = outtype->type_num;\n\t\tchksize = outtype->itemsize;\n\t\tgoto finish;\n\t}\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_TYPE(ip);\n\t\t\tchksize = PyArray_ITEMSIZE(ip);\n\t\t\tgoto finish;\n\t\t}\n } \n\t\n\tif (PyObject_HasAttrString(op, \"__array_typestr__\")) {\n\t\tint swap=0, res;\n\t\tip = PyObject_GetAttrString(op, \"__array_typestr__\");\n\t\tif (ip && PyString_Check(ip)) {\n\t\t\tres = _array_typecode_fromstr(PyString_AS_STRING(ip), \n\t\t\t\t\t\t &swap, outtype); \n\t\t\tif (res >= 0) {\n\t\t\t\tPy_DECREF(ip);\n\t\t\t\tchktype = outtype->type_num;\n\t\t\t\tchksize = outtype->itemsize;\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t}\n\t\tPy_XDECREF(ip);\n\t}\n\n if (PyString_Check(op)) {\n\t\tchktype = PyArray_STRING;\n\t\tchksize = PyString_GET_SIZE(op);\n\t\tgoto finish;\n }\n\n\tif (PyUnicode_Check(op)) {\n\t\tchktype = PyArray_UNICODE;\n\t\tchksize = PyUnicode_GET_DATA_SIZE(op);\n\t\tgoto finish;\n\t}\n\n\tif (PyBuffer_Check(op)) {\n\t\tchktype = PyArray_VOID;\n\t\tchksize = op->ob_type->tp_as_sequence->sq_length(op);\n\t\tPyErr_Clear();\n\t\tgoto finish;\n\t}\n\n\tif (PyInstance_Check(op)) goto deflt;\n\t\n if (PySequence_Check(op)) {\n\t\tPyArray_Typecode newtype;\n\t\tnewtype.type_num = mintype;\n\t\tnewtype.itemsize = minsize;\n\t\tnewtype.fortran = 0;\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 && mintype == 0) {\n\t\t\tnewtype.type_num = PyArray_INTP;\n\t\t\tnewtype.itemsize = sizeof(intp);\n\t\t}\n while (--l >= 0) {\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\t_array_find_type(ip, &newtype, outtype, max-1);\n\t\t\t_array_small_type(outtype->type_num,\n\t\t\t\t\t newtype.type_num, \n\t\t\t\t\t outtype->itemsize,\n\t\t\t\t\t newtype.itemsize,\n\t\t\t\t\t &newtype);\n Py_DECREF(ip);\n }\n\t\tchktype = newtype.type_num;\n\t\tchksize = newtype.itemsize;\n\t\tgoto finish;\n }\n\t\n\tif (PyBool_Check(op)) {\n\t\tchktype = PyArray_BOOL;\n\t\tchksize = sizeof(Bool);\n\t\tgoto finish;\t\t\n\t}\n else if (PyInt_Check(op)) {\n\t\tchktype = PyArray_LONG;\n\t\tchksize = sizeof(long);\n\t\tgoto finish;\n } else if (PyFloat_Check(op)) {\n\t\tchktype = PyArray_DOUBLE;\n\t\tchksize = sizeof(double);\n\t\tgoto finish;\n\t} else if (PyComplex_Check(op)) {\n\t\tchktype = PyArray_CDOUBLE;\n\t\tchksize = sizeof(cdouble);\n\t\tgoto finish;\n\t}\n\n deflt:\n\tchktype = PyArray_OBJECT;\n\tchksize = sizeof(void *);\n\n finish:\n\t_array_small_type(chktype, mintype, chksize, minsize, \n\t\t\t outtype);\n\treturn;\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\" */ \nstatic PyObject *\nArray_FromScalar(PyObject *op, PyArray_Typecode *typecode) \n{\n PyArrayObject *ret;\n\tint itemsize; \n\tint type;\n\t\n\titemsize = typecode->itemsize;\n\ttype = typecode->type_num;\n\n\tif (itemsize == 0 && PyTypeNum_ISFLEXIBLE(type)) {\n\t\titemsize = PyObject_Length(op);\n\t}\n\n\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, 0, NULL, type,\n\t\t\t\t\t NULL, NULL, itemsize, 0, NULL);\n\n\tif (ret == NULL) return NULL;\n\n ret->descr->setitem(op, ret->data, ret);\n\t\n if (PyErr_Occurred()) {\n array_dealloc(ret);\n return NULL;\n } else {\n return (PyObject *)ret;\n }\n}\n\n\nstatic PyObject *\nArray_FromSequence(PyObject *s, PyArray_Typecode *typecode, int min_depth, \n\t\t int max_depth)\n{\n PyArrayObject *r;\n int nd;\n\tintp *d;\n\tint stop_at_string;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->itemsize;\n\t\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 if (!((nd=discover_depth(s, MAX_DIMS+1, stop_at_string)) > 0)) {\n\t\tif (nd==0)\n\t\t\treturn Array_FromScalar(s, typecode);\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid input sequence\");\n return NULL;\n }\n\t\n if ((max_depth && nd > max_depth) ||\t\\\n\t (min_depth && nd < min_depth)) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid number of dimensions\");\n return NULL;\n }\n\t\n\tif ((d=PyDimMem_NEW(nd)) == NULL) {\n\t\treturn PyErr_NoMemory();\n }\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) {\n\t\tPyDimMem_FREE(d);\n\t\treturn NULL;\n\t}\n\tif (itemsize == 0 && PyTypeNum_ISFLEXIBLE(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) {\n\t\t\tPyDimMem_FREE(d);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n r=(PyArrayObject*)PyArray_New(&PyArray_Type, nd, d, \n\t\t\t\t type, NULL, NULL,\n\t\t\t\t itemsize, \n\t\t\t\t typecode->fortran, NULL);\n\n PyDimMem_FREE(d);\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\n\nstatic int \nPyArray_ValidType(int type) \n{\n\tPyArray_Descr *descr;\n\t\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr==NULL) return 0;\n\treturn 1;\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->itemsize;\n\tint nels = PyArray_BUFSIZE;\n\tint el;\n\tint inswap, outswap=0;\n\tint obuf=!PyArray_ISCARRAY(out);\n\tint oelsize = out->itemsize;\n\tPyArray_VectorUnaryFunc *castfunc;\n PyArray_CopySwapFunc *in_csn;\n PyArray_CopySwapFunc *out_csn;\n\tint retval = -1;\n\n\tcastfunc = in->descr->cast[out->descr->type_num];\n in_csn = in->descr->copyswap;\n out_csn = out->descr->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\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\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->itemsize * 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\n/* For backward compatibility */\n\nstatic PyObject *\nPyArray_Cast(PyArrayObject *mp, int type_num) \n{\n\tPyArray_Typecode type;\n\tPyArray_Descr *descr;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\ttype.itemsize = descr->elsize;\n\ttype.type_num = descr->type_num;\n\ttype.fortran = 0;\n\t\n\treturn PyArray_CastToType(mp, &type);\n}\n\nstatic PyObject * \nPyArray_CastToType(PyArrayObject *mp, PyArray_Typecode *at) \n{\n\tPyObject *out;\n\tint ret;\n\n\tif ((mp->descr->type_num == at->type_num) && \\\n\t (at->itemsize==0 || mp->itemsize == at->itemsize) &&\n\t PyArray_ISBEHAVED_RO(mp)) {\n\t\tPy_INCREF(mp);\n\t\treturn (PyObject *)mp;\n\t}\n\t\t\n\tif (at->itemsize == 0) {\n\t\tif (mp->descr->type_num == PyArray_STRING &&\t\\\n\t\t at->type_num == PyArray_UNICODE)\n\t\t\tat->itemsize = mp->itemsize*sizeof(Py_UNICODE);\n\t\tif (mp->descr->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING) \n\t\t\tat->itemsize = mp->itemsize/sizeof(Py_UNICODE);\n\t\tif (at->type_num == PyArray_VOID)\n\t\t\tat->itemsize = mp->itemsize;\n\t}\n\n\tout = PyArray_New(mp->ob_type, mp->nd, \n\t\t\t mp->dimensions, \n\t\t\t at->type_num,\n\t\t\t NULL, NULL, at->itemsize, \n\t\t\t at->fortran, (PyObject *)mp);\n\tif (out == NULL) return NULL;\n\tret = PyArray_CastTo((PyArrayObject *)out, mp);\n\tif (ret != -1) return out;\n\n\tPy_DECREF(out);\n\treturn NULL;\n\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\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\tsimple = ((PyArray_ISCARRAY(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY(mp) && PyArray_ISFARRAY(out)));\n\t\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->itemsize * outsize;\n\t\tintp ncopies = outsize / mpsize;\n\n\t\twhile(ncopies--) {\n\t\t\tinptr = mp->data;\n\t\t\tmp->descr->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\nstatic PyObject *\narray_fromarray(PyArrayObject *arr, PyArray_Typecode *typecode, int flags) \n{\n\t\n\tPyArrayObject *ret=NULL;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->itemsize;\n\tint copy = 0;\n\tint arrflags;\n\tPyArray_Typecode oldtype;\n\tchar *msg = \"cannot copy back to a read-only array\";\n PyTypeObject *subtype;\n\n\toldtype.type_num = PyArray_TYPE(arr);\n\toldtype.itemsize = PyArray_ITEMSIZE(arr);\n\toldtype.fortran = 0;\n\n subtype = arr->ob_type;\n\n\tif (type == PyArray_NOTYPE) type = arr->descr->type_num;\n\tif (itemsize == 0) itemsize = arr->itemsize;\n\ttypecode->type_num = type;\n\ttypecode->itemsize = itemsize;\n\n\t/* Don't copy if sizes are compatible */\n\tif (PyArray_EquivalentTypes(&oldtype, typecode)) {\n\t\tarrflags = arr->flags;\n\n\t\tcopy = (flags & ENSURECOPY) || \\\n\t\t\t((flags & CONTIGUOUS) && (!(arrflags & CONTIGUOUS))) \\\n\t\t\t|| (PyArray_ITEMSIZE(arr) != itemsize) || \\\n\t\t\t((flags & ALIGNED) && (!(arrflags & ALIGNED))) || \\\n\t\t\t((flags & NOTSWAPPED) && (!(arrflags & NOTSWAPPED))) \\\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 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_New(subtype, \n\t\t\t\t\t arr->nd, \n\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t type,\n\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t itemsize,\n\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t (PyObject *)arr);\n\t\t\tif (PyArray_CopyInto(ret, arr) == -1) 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 ret = (PyArrayObject *) \\\n PyArray_New(&PyArray_Type,\n arr->nd,\n arr->dimensions,\n arr->descr->type_num,\n arr->strides,\n arr->data,\n arr->itemsize,\n arr->flags,NULL);\n if (ret == NULL) return NULL;\n ret->base = (PyObject *)arr;\n ret->flags &= ~UPDATEIFCOPY;\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_CanCastSafely(PyArray_TYPE(arr), type)) {\n if ((flags & UPDATEIFCOPY) && \\\n (!PyArray_ISWRITEABLE(arr))) {\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_New(subtype, arr->nd,\n arr->dimensions, typecode->type_num,\n NULL, NULL, typecode->itemsize,\n typecode->fortran, \n (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\nstatic int\n_array_typecode_fromstr(char *str, int *swap, PyArray_Typecode *type)\n{\n int type_num;\n char typechar;\n int size;\n unsigned long number = 1;\n char *s;\n char msg[] = \"unsupported typestring\";\n \n s = (char *)&number; /* s[0] == 0 implies big-endian */\n\n *swap = 0;\n\n if (str[0] == '<' || str[0] == '>') {\n\tif ((str[0] == '<') && (s[0] == 0)) *swap = 1;\n\telse if ((str[0] == '>') && (s[0] != 0)) *swap = 1;\n }\n str += 1;\n \n#define _MY_FAIL {\t\t\t\t \\\n\t PyErr_SetString(PyExc_ValueError, msg); \\\n\t return -1;\t\t\t \\\n }\t\t\n\n typechar = str[0];\n size = atoi(str + 1);\n switch (typechar) {\n case 'b':\n\t if (size == sizeof(Bool))\n\t\t type_num = PyArray_BOOL;\t \n\t else _MY_FAIL \n\t break;\t\t \n case 'u':\n if (size == sizeof(uintp))\n type_num = PyArray_UINTP;\n\t else if (size == sizeof(char))\n\t\t type_num = PyArray_UBYTE;\n\t else if (size == sizeof(short)) \n\t\t type_num = PyArray_USHORT;\n\t else if (size == sizeof(int)) \n\t\t type_num = PyArray_UINT;\n\t else if (size == sizeof(ulong)) \n\t\t type_num = PyArray_ULONG;\n\t else if (size == sizeof(ulonglong))\n\t\t type_num = PyArray_ULONGLONG;\n\t else _MY_FAIL\n\t break;\t\t \n case 'i':\n if (size == sizeof(intp))\n type_num = PyArray_INTP;\n\t else if (size == sizeof(char)) \n\t\t type_num = PyArray_BYTE;\n\t else if (size == sizeof(short)) \n\t\t type_num = PyArray_SHORT;\n\t else if (size == sizeof(int))\n\t\t type_num = PyArray_INT;\n\t else if (size == sizeof(long)) \n\t\t type_num = PyArray_LONG;\n\t else if (size == sizeof(longlong))\n\t\t type_num = PyArray_LONGLONG;\n\t else _MY_FAIL\n\t break;\t\t \n case 'f':\n\t if (size == sizeof(float))\n\t\t type_num = PyArray_FLOAT;\n\t else if (size == sizeof(double))\n\t\t type_num = PyArray_DOUBLE;\n\t else if (size == sizeof(longdouble))\n\t\t type_num = PyArray_LONGDOUBLE;\n\t else _MY_FAIL\n\t break;\n case 'c':\n\t if (size == sizeof(float)*2)\n\t\t type_num = PyArray_CFLOAT;\n\t else if (size == sizeof(double)*2)\n\t\t type_num = PyArray_CDOUBLE;\n\t else if (size == sizeof(longdouble)*2)\n\t\t type_num = PyArray_CLONGDOUBLE;\n\t else _MY_FAIL\n\t break;\n case 'O':\n\t if (size == sizeof(PyObject *))\n\t\t type_num = PyArray_OBJECT;\n\t else _MY_FAIL\n\t break;\n case 'S':\n\t type_num = PyArray_STRING;\n\t break;\n case 'U':\n\t type_num = PyArray_UNICODE;\n\t size *= sizeof(Py_UNICODE);\n\t break;\t \n case 'V':\n\t type_num = PyArray_VOID;\n\t break;\n default:\n\t _MY_FAIL\n }\n\n#undef _MY_FAIL\n\n type->type_num = type_num;\n type->itemsize = size;\n type->fortran = 0;\n return 0;\n}\n\nstatic PyObject *\narray_frominterface(PyObject *input, PyArray_Typecode *intype, int flags)\n{\n\tPyObject *attr=NULL, *item=NULL, *r;\n\tPyArrayObject *ret=NULL;\n\tPyArray_Typecode type;\n\tchar *data;\n\tint buffer_len;\n\tint res, i, n;\n\tintp dims[MAX_DIMS], strides[MAX_DIMS];\n\tint swap;\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\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) {Py_XDECREF(attr); return NULL;}\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t}\n\telse {\n\t\tif (PyTuple_GET_SIZE(attr) != 2) {\n\t\t\tPy_DECREF(attr);\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\treturn NULL;\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\tPy_DECREF(attr);\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\treturn NULL;\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 = PyObject_GetAttrString(input, \"__array_typestr__\");\n\tif (!PyString_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_typestr__ must be a string\");\n\t\tPy_DECREF(attr);\n\t\treturn NULL;\t\n\t}\n\tres = _array_typecode_fromstr(PyString_AS_STRING(attr), &swap, &type);\n\tPy_DECREF(attr);\n\tif (res < 0) return NULL;\n \n\tattr = PyObject_GetAttrString(input, \"__array_shape__\");\n\tif (!PyTuple_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_shape__ must be a tuple\");\n\t\tPy_DECREF(attr);\n\t\treturn NULL;\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\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\treturn NULL;\n\t\t}\n\t\tfor (i=0; istrides, strides, n*sizeof(intp));\n\t}\n\n\tif (swap) {\n\t\tPyObject *tmp;\n tmp = PyArray_Byteswap(ret, TRUE);\n\t\tPy_DECREF(tmp);\n\t}\n\n\tPyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n\tr = array_fromarray(ret, intype, flags);\n\tPy_DECREF(ret);\n\treturn r;\n}\n\nstatic PyObject *\narray_fromattr(PyObject *op, PyArray_Typecode *typecode, int flags) \n{\n PyObject *new, *r;\n\t \n if (typecode->type_num == PyArray_NOTYPE) {\n new = PyObject_CallMethod(op, \"__array__\", NULL);\n } else {\n\t\tPyArray_Descr *descr;\n\t\tPyObject *obj;\n\n\t\tdescr = PyArray_DescrFromType(typecode->type_num);\n\t\tif (PyTypeNum_ISFLEXIBLE(typecode->type_num)) {\n\t\t\tobj = PyString_FromFormat(\"%c%d\", descr->type,\n\t\t\t\t\t\t typecode->itemsize);\n\t\t}\n\t\telse { \n\t\t\tobj = (PyObject *)(descr->typeobj); Py_INCREF(obj);\n\t\t}\n\t\tnew = PyObject_CallMethod(op, \"__array__\", \"N\", obj);\n }\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 r = array_fromarray((PyArrayObject *)new, typecode, flags);\n Py_DECREF(new);\n return r;\n} \n\n\nstatic PyObject *\narray_fromobject(PyObject *op, PyArray_Typecode *typecode, int min_depth, \n\t\t int max_depth, int flags) \n{\n /* This is the main code to make a NumPy array from a Python\n Object. It is called from lot's of different places which\n is why there are so many checks. The comments try to\n explain some of the checks. */\n\n\tint type = typecode->type_num;\n PyObject *r=NULL;\n\n\t/* Is input object already an array? */\n\t/* This is where the flags are used */\n if (PyArray_Check(op)) \n\t\tr = array_fromarray((PyArrayObject *)op, typecode, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, typecode);\n\t}\n\telse if (PyObject_HasAttrString(op, \"__array__\")) {\n\t\t/* Code that returns the object to convert for a non\n\t\t multiarray input object from the __array__ attribute of the\n\t\t object. */\n r = array_fromattr(op, typecode, flags);\n\t}\n\telse if (PyObject_HasAttrString(op, \"__array_shape__\") &&\n\t\t PyObject_HasAttrString(op, \"__array_typestr__\")) {\n\t\tr = array_frominterface(op, typecode, flags);\n\t}\n\telse {\n\t\tif (type == PyArray_NOTYPE) {\n\t\t\t_array_find_type(op, NULL, typecode, MAX_DIMS);\n\t\t}\n\t\tif (PySequence_Check(op))\n\t\t\tr = Array_FromSequence(op, typecode, \n\t\t\t\t\t min_depth, max_depth);\n\t\telse\n\t\t\tr = Array_FromScalar(op, typecode);\n\t}\n\n /* If we didn't succed return NULL */\n if (r == NULL) return NULL;\n\t\n\t/* Be sure we succeed here */\n\t\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"internal error: array_fromobject \"\\\n\t\t\t\t\"not producing an array\");\n\t\tPy_DECREF(r);\n return NULL;\n }\n\n if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {\n Py_DECREF(r);\n PyErr_SetString(PyExc_ValueError, \n \"object of too small depth for desired array\");\n return NULL;\n }\n if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {\n Py_DECREF(r);\n PyErr_SetString(PyExc_ValueError, \n \"object too deep for desired array\");\n return NULL;\n }\n return r;\n}\n\nstatic void\nPyArray_ArrayType(PyObject *op, PyArray_Typecode *intype, \n\t\t PyArray_Typecode *outtype) \n{\n\t_array_find_type(op, intype, outtype, MAX_DIMS);\n\treturn;\n}\n\nstatic int \nPyArray_ObjectType(PyObject *op, int minimum_type) \n{\n\tPyArray_Typecode intype, outtype;\n\tintype.type_num = minimum_type;\n\t_array_find_type(op, &intype, &outtype, MAX_DIMS);\n\treturn outtype.type_num;\n}\n\n\n\n/* flags is any of \n CONTIGUOUS, \n FORTRAN, (or set typecode->fortran=1)\n ALIGNED, \n NOTSWAPPED, \n WRITEABLE, \n ENSURECOPY, \n UPDATEIFCOPY,\n FORCECAST,\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, NOTSWAPPED, and WRITEABLE\n and therefore it is redundant to include those as well. \n\n BEHAVED_FLAGS == ALIGNED | NOTSWAPPED | WRITEABLE\n BEHAVED_FLAGS_RO == ALIGNED | NOTSWAPPED\n CARRAY_FLAGS = CONTIGUOUS | BEHAVED_FLAGS\n FARRAY_FLAGS = FORTRAN | BEHAVED_FLAGS\n \n By default, the returned array will be a copy of the object, \n (C) contiguous in memory, aligned, notswapped, and writeable.\n \n So CONTIGUOUS | ENSURECOPY passed in means that the returned\n array does not have to be CONTIGUOUS or a COPY but should be\n ALIGNED, NOTSWAPPED and WRITEABLE. \n\n typecode->fortran can be set to request a\n fortran-contiguous array. Fortran arrays are always behaved (aligned, \n notswapped, and writeable) and not (C) CONTIGUOUS. Note that either\n FORTRAN in the flag or typecode->fortran = 1 is enough to request\n a FORTRAN-style array. \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\nstatic PyObject *\nPyArray_FromAny(PyObject *op, PyArray_Typecode *typecode, int min_depth, \n\t\tint max_depth, int requires) \n{\n \tPyArray_Typecode mine = {PyArray_NOTYPE, 0, 0};\n\tPyArray_Typecode *type;\n\t\n\tif (typecode == NULL) type = &mine;\n\telse type = typecode;\n\t\t\n\tif (requires & ENSURECOPY) {\n\t\trequires |= DEFAULT_FLAGS;\n\t}\n\t/* Ensure that type->fortran and flags & FORTRAN are the\n\t same */\n\tif (requires & FORTRAN) typecode->fortran = 1;\n\tif (type->fortran == 1) {\n\t\trequires |= FARRAY_FLAGS;\n\t\tif (min_depth > 2) requires &= ~CONTIGUOUS;\n\t}\n\n\t/* make sure itemsize is not 0 unless warranted. */\n\tif ((type->itemsize == 0) && (type->type_num != PyArray_NOTYPE)) {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(type->type_num);\n\t\tif (descr != NULL) type->itemsize = descr->elsize;\n\t\telse return NULL;\n\t}\n\t\n\treturn array_fromobject(op, type, min_depth, max_depth, \n\t\t\t\trequires);\t\n}\n\n/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0, 0) */\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\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);\n Py_DECREF(op);\n return new;\n}\n\n/* These are all compressed into a single API */\n/* Deprecated calls -- Use PyArray_FromAny */\n\nstatic PyObject *\nPyArray_FromObject(PyObject *op, int type, int min_depth, int max_depth) \n{\n\tPyArray_Typecode typecode = {0, 0, 0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth,\n\t\t\t max_depth, BEHAVED_FLAGS | ENSUREARRAY);\n}\n\nstatic PyObject *\nPyArray_ContiguousFromObject(PyObject *op, int type, int min_depth, \n\t\t\t int max_depth) \n{\n\tPyArray_Typecode typecode = {0, 0, 0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth,\n\t\t\t max_depth, DEFAULT_FLAGS | ENSUREARRAY);\n}\n\nstatic PyObject *\nPyArray_CopyFromObject(PyObject *op, int type, int min_depth, \n\t\t int max_depth) \n{\n\tPyArray_Typecode typecode = {0, 0, 0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth, max_depth,\n\t\t\t ENSURECOPY | ENSUREARRAY);\n}\n\n/* End of deprecated */\n\nstatic PyObject *\nPyArray_ContiguousFromAny(PyObject *op, int type, int min_depth, \n\t\t\t int max_depth)\n{\n\tPyArray_Typecode typecode = {0,0,0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth,\n\t\t\t max_depth, DEFAULT_FLAGS);\n}\t\n\nstatic int \nPyArray_CanCastSafely(int fromtype, int totype) \n{\n\tPyArray_Descr *from, *to;\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\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 (to->elsize > from->elsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (to->elsize >= from->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (from->elsize < 8)\n return (to->elsize > from->elsize);\n else\n return (to->elsize >= from->elsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (from->elsize < 8)\n return ((to->elsize >> 1) > from->elsize);\n else\n return ((to->elsize >> 1) >= from->elsize);\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 (to->elsize > from->elsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (to->elsize >= from->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (from->elsize < 8)\n return (to->elsize > from->elsize);\n else\n return (to->elsize >= from->elsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (from->elsize < 8)\n return ((to->elsize >> 1) > from->elsize);\n else\n return ((to->elsize >> 1) >= from->elsize);\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 ((to->elsize >> 1) >= from->elsize);\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\nstatic Bool\nPyArray_CanCastTo(PyArray_Typecode *from, PyArray_Typecode *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->itemsize <= to->itemsize);\n\t\t\t}\n\t\t\telse if (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->itemsize * sizeof(Py_UNICODE)\\\n\t\t\t\t <= to->itemsize);\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->itemsize <= to->itemsize);\n\t\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 scipy's arraymap ****/\n/* and Python's array iterator ***/\n \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 = PyObject_GC_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 PyObject_GC_Track(it);\n return (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 PyObject_GC_UnTrack(it);\n Py_XDECREF(it->ao);\n PyObject_GC_Del(it);\n }\n\nstatic int\narrayiter_traverse(PyArrayIterObject *it, visitproc visit, void *arg)\n{\n if (it->ao != NULL)\n return visit((PyObject *)(it->ao), arg);\n return 0;\n}\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->itemsize;\n\tr = PyArray_New(self->ao->ob_type, 1, &count, \n\t\t\tself->ao->descr->type_num, NULL, NULL,\n\t\t\titemsize, 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->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->itemsize;\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\tr = PyArray_New(self->ao->ob_type, ind->nd, ind->dimensions,\n\t\t\tself->ao->descr->type_num, NULL, \n\t\t\tNULL, self->ao->itemsize, \n\t\t\t0, (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)->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\tint i;\n\tPyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tint 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\t\t\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\n\t/* Tuples 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\tr = PyArray_New(self->ao->ob_type, 1, &ii, \n\t\t\t\t\tself->ao->descr->type_num, NULL, \n\t\t\t\t\tNULL, self->ao->itemsize, 0,\n\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 */\n\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->itemsize;\n\t\tr = PyArray_New(self->ao->ob_type, 1, &n_steps, \n\t\t\t\tself->ao->descr->type_num, NULL, NULL,\n\t\t\t\tsize, 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)->copyswap;\n\t\twhile(n_steps--) {\n copyswap(dptr, self->dataptr, swap, size);\n\t\t\tfor(i=0; i< step_size; i++) \n\t\t\t\tPyArray_ITER_NEXT(self);\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\tif (PyArray_IsScalar(ind, Integer) || PyList_Check(ind)) {\n\t\tobj = PyArray_FromAny(ind, &indtype, 0, 0, FORCECAST);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tr = iter_subscript_Bool(self, (PyArrayObject *)obj);\n\t\t} \n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, &indtype, 0, 0, \n\t\t\t\t\t FORCECAST | BEHAVED_FLAGS);\n\t\t\tif (new==NULL) goto fail;\n\t\t\tobj = new;\n\t\t\tr = iter_subscript_int(self, (PyArrayObject *)obj);\n\t\t}\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\t\"unsupported iterator index\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPy_DECREF(obj);\n\t\treturn r;\n\t}\n\n\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\n fail:\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->itemsize;\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->copyswap;\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(self->dataptr, val->dataptr, swap,\n itemsize);\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t\tPyArray_ITER_NEXT(val);\n\t\tif (val->index==val->size) \n\t\t\tPyArray_ITER_RESET(val);\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_Typecode typecode;\n\tintp num;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\titemsize = typecode.itemsize = self->ao->itemsize;\n\ttypecode.type_num = self->ao->descr->type_num;\n copyswap = self->ao->descr->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\n\nstatic int\niter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val) \n{\n\tint i;\n\tPyObject *arrval=NULL;\n\tPyArrayIterObject *val_it=NULL;\n\tPyArray_Typecode type;\n\tPyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tint swap;\n\tint itemsize;\n\tint start, step_size;\n\tintp n_steps;\n\tPyObject *obj;\n PyArray_CopySwapFunc *copyswap;\n\t\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\ti = iter_ass_subscript(self, ind, val);\n\t\tPy_DECREF(ind);\n\t\treturn i;\n\t}\n\t\n\ttype.type_num = self->ao->descr->type_num;\n\titemsize = type.itemsize = self->ao->itemsize;\n\t\n\tarrval = PyArray_FromAny(val, &type, 0, 0, 0);\n\tif (arrval==NULL) return -1;\n\tval_it = (PyArrayIterObject *)PyArray_IterNew(arrval);\n\tif (val_it==NULL) goto fail;\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\n copyswap = PyArray_DESCR(arrval)->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\tgoto succeed;\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 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 copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, itemsize);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\tgoto succeed;\n\t\t}\n\t\twhile(n_steps--) {\n copyswap(self->dataptr, val_it->dataptr,\n swap, itemsize);\n\t\t\tfor(i=0; i < step_size; i++) \n\t\t\t\tPyArray_ITER_NEXT(self);\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\tgoto succeed;\n\t} \n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tif (PyArray_IsScalar(ind, Integer))\n\t\tobj = PyArray_FromScalar(ind, &indtype);\n\telse if (PyList_Check(ind)) {\n\t\tobj = PyArray_FromAny(ind, &indtype, 0, 0, FORCECAST);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tif (iter_ass_sub_Bool(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto fail;\n\t\t} \n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, &indtype, 0, 0, \n\t\t\t\t\t FORCECAST | BEHAVED_FLAGS);\n\t\t\tif (new==NULL) goto fail;\n\t\t\tPy_DECREF(obj);\n\t\t\tobj = new;\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 fail;\n\t\t}\n\t\telse goto fail;\n\t\tPy_DECREF(obj);\n\t\tgoto succeed;\n\t}\n\n\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\tgoto fail;\n\n succeed:\n\tPy_DECREF(val_it);\n\tPy_DECREF(arrval);\n\treturn 0;\n\n fail:\n\tPy_XDECREF(val_it);\n\tPy_XDECREF(arrval);\n\treturn -1;\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 if (PyArray_ISCONTIGUOUS(it->ao)) {\n r = PyArray_New(it->ao->ob_type, 1, &size, \n\t\t\t\tit->ao->descr->type_num,\n NULL, it->ao->data, it->ao->itemsize, \n\t\t\t\tit->ao->flags,\n (PyObject *)it->ao); \n\t\tif (r==NULL) return NULL;\n }\n else {\n r = PyArray_New(it->ao->ob_type, 1, &size, \n\t\t\t\tit->ao->descr->type_num,\n NULL, NULL, it->ao->itemsize, 0, \n (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\n\nstatic PyTypeObject PyArrayIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"scipy.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 | Py_TPFLAGS_HAVE_GC,/* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)arrayiter_traverse,\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)arrayiter_next,\t\t/* tp_iternext */\n iter_methods,\t\t\t\t/* tp_methods */\n};\n\n/** END of Array Iterator **/\n\n\n\n/*********************** Subscript Array Iterator *************************\n * *\n * This object handles subscript behavior for array objects. *\n * It is an iterator object with a next method *\n * It abstracts the n-dimensional mapping behavior to make the looping *\n * code more understandable (maybe) *\n * and so that indexing can be set up ahead of time *\n */ \n\n/* This checks the args for any fancy indexing objects */\n\n#define SOBJ_NOTFANCY 0 \n#define SOBJ_ISFANCY 1\n#define SOBJ_BADARRAY 2\n#define SOBJ_TOOMANY 3\n#define SOBJ_LISTTUP 4\n\nstatic int\nfancy_indexing_check(PyObject *args)\n{\n\tint i, n;\n\tPyObject *obj;\n\tint retval = SOBJ_NOTFANCY;\n\n\tif (PyTuple_Check(args)) {\n\t\tn = PyTuple_GET_SIZE(args);\n\t\tif (n >= MAX_DIMS) return SOBJ_TOOMANY;\n\t\tfor (i=0; i=MAX_DIMS) return SOBJ_ISFANCY;\n\t\tfor (i=0; i SOBJ_ISFANCY) return retval;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* convert an indexing object to an INTP indexing array iterator\n if possible -- otherwise, it is a Slice or Ellipsis object\n and has to be interpreted on bind to a particular \n array so leave it NULL for now.\n */\nstatic int\n_convert_obj(PyObject *obj, PyArrayIterObject **iter)\n{\n\tPyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tPyObject *arr;\n\n\tif (PySlice_Check(obj) || (obj == Py_Ellipsis))\n\t\t*iter = NULL;\n\telse {\n\t\tarr = PyArray_FromAny(obj, &indtype, 0, 0, FORCECAST);\n\t\tif (arr == NULL) return -1;\n\t\t*iter = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (*iter == NULL) return -1;\n\t}\n\treturn 0;\n}\n\n/* Adjust dimensionality and strides for index object iterators \n --- i.e. broadcast\n */\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->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->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=NULL, *obj=NULL;\n\tint i, j, n, curraxis, ellipexp, noellip;\n\tPyArrayIterObject *it;\n\tintp dimsize;\n\tintp *indptr;\n\n\t/* Remove old binding if any */\n\tPy_XDECREF(mit->ait);\n\tmit->ait = NULL;\n\n\tPy_XDECREF(mit->subspace);\n\tmit->subspace = NULL;\n\t\n\tsubnd = arr->nd - mit->numiter;\n\tif (subnd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"too many indices for array\");\n\t\treturn;\n\t}\n\n\tmit->ait = (PyArrayIterObject *)PyArray_IterNew((PyObject *)arr);\n\tif (mit->ait == NULL) return;\n\n\t/* If this is just a view, then do nothing more */\n\t/* views are handled by just adjusting the strides\n\t and dimensions of the object.\n\t*/\n\t \n\tif (mit->view) return;\n\n\t/* no subspace iteration needed. 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\tif (mit->subspace == NULL) goto fail;\n\tPy_DECREF(sub);\n\n\t/* Expand dimensions of result */\n\tn = mit->subspace->ao->nd;\n\tfor (i=0; idimensions[mit->nd+i] = mit->subspace->ao->dimensions[i];\n\tmit->nd += n;\n\n\t/* Now, we still need to interpret the ellipsis and slice objects \n\t to determine which axes the indexing arrays are referring to\n\t*/\n\tn = PyTuple_GET_SIZE(mit->indexobj);\n\n\t/* The number of dimensions an ellipsis takes up */\n\tellipexp = arr->nd - n + 1;\n\t/* Now fill in iteraxes -- remember indexing arrays have been \n converted to 0's in mit->indexobj */\n\tcurraxis = 0;\n\tj = 0;\n\tnoellip = 1; /* Only expand the first ellipsis */\n\tmemset(mit->bscoord, 0, sizeof(intp)*arr->nd);\n\tfor (i=0; iindexobj, i);\n\t\tif (PyInt_Check(obj) || PyLong_Check(obj)) \n\t\t\tmit->iteraxes[j++] = curraxis++;\n\t\telse if (noellip && obj == Py_Ellipsis) {\n\t\t\tcurraxis += ellipexp;\n\t\t\tnoellip = 0;\n\t\t}\n\t\telse {\n\t\t\tint start=0;\n\t\t\tint 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}\t\t\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn;\n\n fail:\n\tPy_XDECREF(sub);\n\tPy_XDECREF(mit->ait);\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_Typecode typecode = {PyArray_BOOL, 0, 0};\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\tba = (PyArrayObject *)PyArray_FromAny(myBool, &typecode, 0, 0, \n\t\t\t\t\t CARRAY_FLAGS);\n\tif (ba == NULL) return -1;\n\tnd = ba->nd;\n\tfor (j=0; jdata;\n\tcount = 0;\n\n\t/* pre-determine how many nonzero entries there are */\n\tfor (i=0; iao->data;\n\t\tcoords[j] = 0;\n\t\tdims_m1[j] = ba->dimensions[j]-1;\n\t}\n\n\tptr = (Bool *)ba->data;\n\n\tif (count == 0) return nd;\n\n\t/* Loop through the Boolean array and copy coordinates\n\t for non-zero entries */\n\tfor (i=0; i=0; j--) {\n\t\t\tif (coords[j] < dims_m1[j]) {\n\t\t\t\tcoords[j]++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcoords[j] = 0;\n\t\t\t}\n\t\t}\n\t}\n\treturn nd;\n\n fail:\n\tfor (j=0; jiters[i] = NULL;\n \tmit->view = 0;\n \tmit->index = 0;\n \tmit->ait = NULL;\n \tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tfancy = fancy_indexing_check(indexobj);\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\tif (fancy == SOBJ_NOTFANCY) { /* bail out */\n\t\tmit->view = 1;\n\t\tgoto ret;\n\t}\n\n\tif (fancy == SOBJ_BADARRAY) {\n\t\tPyErr_SetString(PyExc_TypeError,\t\t\t\\\n\t\t\t\t\"arrays used as indexes must be of \" \\\n\t\t\t\t\"integer type\");\n\t\tgoto fail;\n\t}\n\tif (fancy == SOBJ_TOOMANY) {\n\t\tPyErr_SetString(PyExc_TypeError, \"too many indicies\");\n\t\tgoto fail;\n\t}\n\n\tif (fancy == SOBJ_LISTTUP) {\n\t\tPyObject *newobj;\n\t\tnewobj = PySequence_Tuple(indexobj);\n\t\tif (newobj == NULL) goto fail;\n\t\tPy_DECREF(indexobj);\n\t\tindexobj = newobj;\n\t\tmit->indexobj = indexobj;\n\t}\n\n#undef SOBJ_NOTFANCY \n#undef SOBJ_ISFANCY \n#undef SOBJ_BADARRAY \n#undef SOBJ_TOOMANY \n#undef SOBJ_LISTTUP \n\n\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\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 (PyList_Check(indexobj) || PyArray_Check(indexobj)) {\n\t\tmit->numiter = 1;\n\t\tarr = PyArray_FromAny(indexobj, &indtype, 0, 0, FORCECAST);\n\t\tif (arr == NULL) goto fail;\n\t\tmit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (mit->iters[0] == NULL) 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(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\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = new;\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\t/* Store the number of iterators actually converted */\n\t\t/* These will be mapped to actual axes at bind time */\n\t\tif (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)\n\t\t\tgoto fail;\n\t}\n\n ret:\n PyObject_GC_Track(mit);\n return (PyObject *)mit;\n \n fail:\n\tPy_XDECREF(arr);\n\tPy_XDECREF(mit->indexobj);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n PyObject_GC_Del(mit);\n\treturn NULL;\n}\n\n\n/* return unbound mapiter object */\n\nstatic PyObject *\narraymapiter_new(PyTypeObject *type, PyObject *args, PyObject *kwds) \n{\n\tPyObject *newtup, *res;\n\tint n;\n\n\tif (!PyTuple_Check(args)) {\n\t\tPyErr_BadInternalCall();\n\t\treturn NULL;\n\t}\n\n\tn = PyTuple_GET_SIZE(args);\n\t\n\tif (n < 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"must be initialized with >= 1 argument\");\n\t\treturn NULL;\n\t}\n\t\n\tif (n > 1) {\n\t\tnewtup = PyTuple_GetSlice(args, 0, n);\n\t\tif (newtup == NULL) return NULL;\n\t\tres = PyArray_MapIterNew(newtup);\n\t\tPy_DECREF(newtup);\n\t}\n\telse { /* n == 1 */\n\t\tnewtup = PyTuple_GET_ITEM(args, 0);\n\t\tres = PyArray_MapIterNew(newtup);\n\t}\n\n\treturn res; \t\n}\n\n\n/* Returns a 0-dim array holding the element desired */\n/*\nstatic PyObject *\narraymapiter_next(PyArrayMapIterObject *mit)\n{\n\tPyObject *ret;\n\tif (mit->ait == NULL) return NULL;\n\tif (mit->view) return NULL;\n\tif (mit->index < mit->size) {\n\t\tret = PyArray_ToScalar(mit->dataptr, mit->ait->ao);\n\t\tPyArray_MapIterNext(mit);\n\t\treturn ret;\n\t}\n return NULL;\n}\n*/\n\nstatic void\narraymapiter_dealloc(PyArrayMapIterObject *mit)\n{\n\tint i;\n PyObject_GC_UnTrack(mit);\n Py_XDECREF(mit->ait);\n\tPy_XDECREF(mit->indexobj);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n PyObject_GC_Del(mit);\n}\n\nstatic int\narraymapiter_traverse(PyArrayMapIterObject *mit, visitproc visit, void *arg)\n{\n\tint ret, i;\n if (mit->ait != NULL)\n if ((ret = visit((PyObject *)(mit->ait), arg)) != 0) \n\t\t\treturn ret;\t\n\n\tif (mit->iters != NULL) \n\t\tfor (i=0; inumiter; i++) \n\t\t\tif (mit->iters[i] != NULL) \n\t\t\t\tif ((ret=visit((PyObject *)mit->iters[i], \n\t\t\t\t\t arg)) != 0)\n\t\t\t\t\treturn ret;\n\n\tif (mit->indexobj != NULL)\n\t\tif ((ret = visit(mit->indexobj, arg)) != 0) return ret;\n\t\n return 0;\n}\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 MapIterNew must be \n that does not work. 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 char doc_mapiter_bind[] = \"obj.bind(a)\\n Bind an array to the \"\\\n\t\"mapiter object\";\n\nstatic PyObject *\nmapiter_bind(PyArrayMapIterObject *mit, PyObject *args)\n{\n\tPyArrayObject *arr;\n\n if (!PyArg_ParseTuple(args, \"O!\", &PyArray_Type, &arr)) return NULL;\n\n \tPyArray_MapIterBind(mit, arr);\n\n\tif (mit->ait == NULL) return NULL;\n\t\n \tPyArray_MapIterReset(mit);\n\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyMethodDef mapiter_methods[] = {\n\t{\"bind\", (PyCFunction)mapiter_bind, 1, doc_mapiter_bind},\n {NULL,\t\tNULL}\t\t\n};\n*/\n\n\nstatic PyTypeObject PyArrayMapIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"scipy.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 | Py_TPFLAGS_HAVE_GC,/* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)arraymapiter_traverse,\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, /*arraymapiter_next,*/\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 (newfunc)arraymapiter_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n\n};\n\n/** END of Subscript Iterator **/\n\n\n\n", "methods": [ { "name": "PyArray_PyIntAsIntp", "long_name": "PyArray_PyIntAsIntp( PyObject * o)", "filename": "arrayobject.c", "nloc": 59, "complexity": 19, "token_count": 385, "parameters": [ "o" ], "start_line": 40, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 64, "top_nesting_level": 0 }, { "name": "PyArray_PyIntAsInt", "long_name": "PyArray_PyIntAsInt( PyObject * o)", "filename": "arrayobject.c", "nloc": 57, "complexity": 19, "token_count": 389, "parameters": [ "o" ], "start_line": 109, "end_line": 169, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 61, "top_nesting_level": 0 }, { "name": "PyArray_GetPriority", "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", "filename": "arrayobject.c", "nloc": 17, "complexity": 5, "token_count": 86, "parameters": [ "obj", "default_" ], "start_line": 173, "end_line": 191, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "PyArray_Zero", "long_name": "PyArray_Zero( PyArrayObject * arr)", "filename": "arrayobject.c", "nloc": 34, "complexity": 6, "token_count": 190, "parameters": [ "arr" ], "start_line": 208, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "PyArray_One", "long_name": "PyArray_One( PyArrayObject * arr)", "filename": "arrayobject.c", "nloc": 40, "complexity": 7, "token_count": 222, "parameters": [ "arr" ], "start_line": 246, "end_line": 289, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "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": 295, "end_line": 345, "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": 368, "end_line": 399, "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": 213, "parameters": [ "src" ], "start_line": 402, "end_line": 436, "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": 449, "end_line": 471, "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": 474, "end_line": 495, "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": 499, "end_line": 537, "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": 542, "end_line": 562, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "index2ptr", "long_name": "index2ptr( PyArrayObject * mp , intp i)", "filename": "arrayobject.c", "nloc": 10, "complexity": 7, "token_count": 86, "parameters": [ "mp", "i" ], "start_line": 570, "end_line": 580, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "PyArray_Size", "long_name": "PyArray_Size( PyObject * op)", "filename": "arrayobject.c", "nloc": 9, "complexity": 2, "token_count": 33, "parameters": [ "op" ], "start_line": 583, "end_line": 591, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "PyArray_CopyInto", "long_name": "PyArray_CopyInto( PyArrayObject * dest , PyArrayObject * src)", "filename": "arrayobject.c", "nloc": 71, "complexity": 16, "token_count": 427, "parameters": [ "dest", "src" ], "start_line": 604, "end_line": 684, "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": 16, "complexity": 2, "token_count": 98, "parameters": [ "dest", "src_object" ], "start_line": 688, "end_line": 707, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "PyArray_FromDimsAndDataAndDescr", "long_name": "PyArray_FromDimsAndDataAndDescr( int nd , int * d , PyArray_Descr * descr , char * data)", "filename": "arrayobject.c", "nloc": 15, "complexity": 3, "token_count": 121, "parameters": [ "nd", "d", "descr", "data" ], "start_line": 715, "end_line": 734, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "PyArray_FromDimsAndData", "long_name": "PyArray_FromDimsAndData( int nd , int * d , int type , char * data)", "filename": "arrayobject.c", "nloc": 14, "complexity": 3, "token_count": 112, "parameters": [ "nd", "d", "type", "data" ], "start_line": 738, "end_line": 755, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "PyArray_FromDims", "long_name": "PyArray_FromDims( int nd , int * d , int type)", "filename": "arrayobject.c", "nloc": 14, "complexity": 5, "token_count": 133, "parameters": [ "nd", "d", "type" ], "start_line": 759, "end_line": 776, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "PyArray_Copy", "long_name": "PyArray_Copy( PyArrayObject * m1)", "filename": "arrayobject.c", "nloc": 11, "complexity": 2, "token_count": 77, "parameters": [ "m1" ], "start_line": 782, "end_line": 794, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "PyArray_Scalar", "long_name": "PyArray_Scalar( char * data , int type_num , int itemsize , int swap)", "filename": "arrayobject.c", "nloc": 48, "complexity": 8, "token_count": 289, "parameters": [ "data", "type_num", "itemsize", "swap" ], "start_line": 800, "end_line": 849, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "top_nesting_level": 0 }, { "name": "PyArray_ToScalar", "long_name": "PyArray_ToScalar( char * data , PyArrayObject * arr)", "filename": "arrayobject.c", "nloc": 7, "complexity": 1, "token_count": 51, "parameters": [ "data", "arr" ], "start_line": 856, "end_line": 863, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_Return", "long_name": "PyArray_Return( PyArrayObject * mp)", "filename": "arrayobject.c", "nloc": 17, "complexity": 5, "token_count": 85, "parameters": [ "mp" ], "start_line": 869, "end_line": 888, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "PyArray_RegisterDataType", "long_name": "PyArray_RegisterDataType( PyTypeObject * type)", "filename": "arrayobject.c", "nloc": 31, "complexity": 6, "token_count": 177, "parameters": [ "type" ], "start_line": 899, "end_line": 931, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "PyArray_RegisterDescrForType", "long_name": "PyArray_RegisterDescrForType( int typenum , PyArray_Descr * descr)", "filename": "arrayobject.c", "nloc": 32, "complexity": 3, "token_count": 167, "parameters": [ "typenum", "descr" ], "start_line": 941, "end_line": 984, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "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": 16, "token_count": 577, "parameters": [ "self", "fp", "sep", "format" ], "start_line": 988, "end_line": 1079, "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": 24, "complexity": 5, "token_count": 151, "parameters": [ "self" ], "start_line": 1082, "end_line": 1110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "PyArray_ToString", "long_name": "PyArray_ToString( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 34, "complexity": 6, "token_count": 191, "parameters": [ "self" ], "start_line": 1113, "end_line": 1148, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "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": 1157, "end_line": 1194, "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": 1201, "end_line": 1209, "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": 22, "complexity": 4, "token_count": 150, "parameters": [ "self", "i" ], "start_line": 1213, "end_line": 1237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "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": 1240, "end_line": 1243, "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": 27, "complexity": 8, "token_count": 177, "parameters": [ "self", "i", "v" ], "start_line": 1247, "end_line": 1277, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "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": 1283, "end_line": 1286, "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 , int * v)", "filename": "arrayobject.c", "nloc": 9, "complexity": 2, "token_count": 40, "parameters": [ "o", "v" ], "start_line": 1292, "end_line": 1300, "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 , int length , int * start , int * stop , int * step , intp * slicelength)", "filename": "arrayobject.c", "nloc": 45, "complexity": 24, "token_count": 376, "parameters": [ "r", "length", "start", "stop", "step", "slicelength" ], "start_line": 1306, "end_line": 1356, "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 , int * step_size , intp * n_steps , int max)", "filename": "arrayobject.c", "nloc": 45, "complexity": 11, "token_count": 223, "parameters": [ "op", "step_size", "n_steps", "max" ], "start_line": 1363, "end_line": 1408, "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": 89, "complexity": 20, "token_count": 540, "parameters": [ "self", "op", "dimensions", "strides", "offset_ptr" ], "start_line": 1412, "end_line": 1507, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 96, "top_nesting_level": 0 }, { "name": "_swap_axes", "long_name": "_swap_axes( PyArrayMapIterObject * mit , PyArrayObject ** ret)", "filename": "arrayobject.c", "nloc": 24, "complexity": 4, "token_count": 187, "parameters": [ "mit", "ret" ], "start_line": 1510, "end_line": 1544, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "PyArray_GetMap", "long_name": "PyArray_GetMap( PyArrayMapIterObject * mit)", "filename": "arrayobject.c", "nloc": 36, "complexity": 8, "token_count": 252, "parameters": [ "mit" ], "start_line": 1549, "end_line": 1598, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "top_nesting_level": 0 }, { "name": "PyArray_SetMap", "long_name": "PyArray_SetMap( PyArrayMapIterObject * mit , PyObject * op)", "filename": "arrayobject.c", "nloc": 50, "complexity": 12, "token_count": 392, "parameters": [ "mit", "op" ], "start_line": 1601, "end_line": 1660, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 60, "top_nesting_level": 0 }, { "name": "array_subscript", "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", "filename": "arrayobject.c", "nloc": 62, "complexity": 19, "token_count": 420, "parameters": [ "self", "op" ], "start_line": 1681, "end_line": 1757, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 77, "top_nesting_level": 0 }, { "name": "array_ass_sub", "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", "filename": "arrayobject.c", "nloc": 44, "complexity": 9, "token_count": 252, "parameters": [ "self", "index", "op" ], "start_line": 1770, "end_line": 1823, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "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": 1831, "end_line": 1834, "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": 1853, "end_line": 1865, "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": 1868, "end_line": 1883, "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": 1887, "end_line": 1896, "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": 1899, "end_line": 1910, "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": 1978, "end_line": 2011, "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": 2018, "end_line": 2057, "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": 23, "complexity": 5, "token_count": 136, "parameters": [ "m1", "op", "axis", "rtype" ], "start_line": 2060, "end_line": 2082, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "PyArray_GenericAccumulateFunction", "long_name": "PyArray_GenericAccumulateFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", "filename": "arrayobject.c", "nloc": 23, "complexity": 5, "token_count": 136, "parameters": [ "m1", "op", "axis", "rtype" ], "start_line": 2086, "end_line": 2108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "PyArray_GenericBinaryFunction", "long_name": "PyArray_GenericBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", "filename": "arrayobject.c", "nloc": 12, "complexity": 2, "token_count": 69, "parameters": [ "m1", "m2", "op" ], "start_line": 2112, "end_line": 2123, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_GenericUnaryFunction", "long_name": "PyArray_GenericUnaryFunction( PyArrayObject * m1 , PyObject * op)", "filename": "arrayobject.c", "nloc": 12, "complexity": 2, "token_count": 63, "parameters": [ "m1", "op" ], "start_line": 2126, "end_line": 2137, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_GenericInplaceBinaryFunction", "long_name": "PyArray_GenericInplaceBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", "filename": "arrayobject.c", "nloc": 13, "complexity": 2, "token_count": 71, "parameters": [ "m1", "m2", "op" ], "start_line": 2140, "end_line": 2152, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 2155, "end_line": 2158, "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": 2161, "end_line": 2164, "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": 2167, "end_line": 2170, "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": 2173, "end_line": 2176, "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": 2179, "end_line": 2182, "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": 2185, "end_line": 2188, "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": 2191, "end_line": 2194, "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": 2197, "end_line": 2200, "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": 2203, "end_line": 2206, "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": 2209, "end_line": 2212, "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": 2215, "end_line": 2218, "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": 2221, "end_line": 2224, "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": 2227, "end_line": 2230, "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": 2233, "end_line": 2236, "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": 2239, "end_line": 2242, "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": 2245, "end_line": 2248, "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": 2251, "end_line": 2254, "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": 2257, "end_line": 2260, "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": 2263, "end_line": 2266, "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": 2269, "end_line": 2272, "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": 2275, "end_line": 2278, "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": 2281, "end_line": 2284, "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": 2287, "end_line": 2290, "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": 2293, "end_line": 2296, "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": 2299, "end_line": 2302, "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": 2305, "end_line": 2308, "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": 2311, "end_line": 2314, "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": 2317, "end_line": 2321, "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": 2324, "end_line": 2328, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "array_all_nonzero", "long_name": "array_all_nonzero( PyArrayObject * mp)", "filename": "arrayobject.c", "nloc": 18, "complexity": 4, "token_count": 93, "parameters": [ "mp" ], "start_line": 2332, "end_line": 2350, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "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": 2353, "end_line": 2368, "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": 143, "parameters": [ "v" ], "start_line": 2372, "end_line": 2398, "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": 143, "parameters": [ "v" ], "start_line": 2401, "end_line": 2426, "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": 124, "parameters": [ "v" ], "start_line": 2429, "end_line": 2451, "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": 124, "parameters": [ "v" ], "start_line": 2454, "end_line": 2476, "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": 124, "parameters": [ "v" ], "start_line": 2479, "end_line": 2501, "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": 2504, "end_line": 2508, "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": 34, "complexity": 11, "token_count": 258, "parameters": [ "self", "ilow", "ihigh" ], "start_line": 2569, "end_line": 2607, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "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": 2611, "end_line": 2632, "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": 4, "complexity": 1, "token_count": 26, "parameters": [ "self", "el" ], "start_line": 2635, "end_line": 2640, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "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": 308, "parameters": [ "string", "n", "max_n", "data", "nd", "dimensions", "strides", "self" ], "start_line": 2661, "end_line": 2708, "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": 222, "parameters": [ "self" ], "start_line": 2711, "end_line": 2747, "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": 2753, "end_line": 2770, "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": 2773, "end_line": 2785, "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": 2788, "end_line": 2800, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "array_richcompare", "long_name": "array_richcompare( PyArrayObject * self , PyObject * other , int cmp_op)", "filename": "arrayobject.c", "nloc": 61, "complexity": 13, "token_count": 273, "parameters": [ "self", "other", "cmp_op" ], "start_line": 2804, "end_line": 2881, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 78, "top_nesting_level": 0 }, { "name": "_check_axis", "long_name": "_check_axis( PyArrayObject * arr , int * axis , int flags)", "filename": "arrayobject.c", "nloc": 29, "complexity": 8, "token_count": 164, "parameters": [ "arr", "axis", "flags" ], "start_line": 2884, "end_line": 2913, "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": 17, "complexity": 4, "token_count": 91, "parameters": [ "len", "vals" ], "start_line": 2919, "end_line": 2935, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "PyArray_IntpFromSequence", "long_name": "PyArray_IntpFromSequence( PyObject * seq , intp * vals , int maxvals)", "filename": "arrayobject.c", "nloc": 21, "complexity": 7, "token_count": 161, "parameters": [ "seq", "vals", "maxvals" ], "start_line": 2940, "end_line": 2963, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "_IsContiguous", "long_name": "_IsContiguous( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 14, "complexity": 6, "token_count": 109, "parameters": [ "ap" ], "start_line": 2969, "end_line": 2985, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_IsFortranContiguous", "long_name": "_IsFortranContiguous( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 14, "complexity": 6, "token_count": 107, "parameters": [ "ap" ], "start_line": 2989, "end_line": 3005, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_IsAligned", "long_name": "_IsAligned( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 14, "complexity": 4, "token_count": 110, "parameters": [ "ap" ], "start_line": 3008, "end_line": 3024, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_IsWriteable", "long_name": "_IsWriteable( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 16, "complexity": 8, "token_count": 109, "parameters": [ "ap" ], "start_line": 3027, "end_line": 3060, "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": 22, "complexity": 9, "token_count": 129, "parameters": [ "ret", "flagmask" ], "start_line": 3064, "end_line": 3086, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "PyArray_CheckStrides", "long_name": "PyArray_CheckStrides( int elsize , int nd , intp numbytes , intp * dims , intp * newstrides)", "filename": "arrayobject.c", "nloc": 13, "complexity": 4, "token_count": 84, "parameters": [ "elsize", "nd", "numbytes", "dims", "newstrides" ], "start_line": 3093, "end_line": 3108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "_array_fill_strides", "long_name": "_array_fill_strides( intp * strides , intp * dims , int nd , intp itemsize , int inflag , int * objflags)", "filename": "arrayobject.c", "nloc": 24, "complexity": 9, "token_count": 171, "parameters": [ "strides", "dims", "nd", "itemsize", "inflag", "objflags" ], "start_line": 3128, "end_line": 3152, "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 , char * data , int itemsize , int flags , PyObject * obj)", "filename": "arrayobject.c", "nloc": 117, "complexity": 27, "token_count": 713, "parameters": [ "subtype", "nd", "dims", "type_num", "strides", "data", "itemsize", "flags", "obj" ], "start_line": 3156, "end_line": 3306, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 151, "top_nesting_level": 0 }, { "name": "PyArray_Resize", "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape)", "filename": "arrayobject.c", "nloc": 87, "complexity": 15, "token_count": 501, "parameters": [ "self", "newshape" ], "start_line": 3311, "end_line": 3416, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 106, "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": 3421, "end_line": 3438, "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": 47, "complexity": 7, "token_count": 261, "parameters": [ "arr", "obj" ], "start_line": 3441, "end_line": 3493, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "top_nesting_level": 0 }, { "name": "array_new", "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", "filename": "arrayobject.c", "nloc": 100, "complexity": 20, "token_count": 589, "parameters": [ "subtype", "args", "kwds" ], "start_line": 3496, "end_line": 3611, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 116, "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": 3618, "end_line": 3621, "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": 10, "complexity": 3, "token_count": 57, "parameters": [ "self" ], "start_line": 3624, "end_line": 3634, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "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": 3707, "end_line": 3710, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "array_shape_set", "long_name": "array_shape_set( PyArrayObject * self , PyObject * val)", "filename": "arrayobject.c", "nloc": 33, "complexity": 6, "token_count": 206, "parameters": [ "self", "val" ], "start_line": 3714, "end_line": 3748, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "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": 3752, "end_line": 3755, "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": 32, "complexity": 7, "token_count": 209, "parameters": [ "self", "obj" ], "start_line": 3758, "end_line": 3791, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "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": 3795, "end_line": 3802, "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": 3805, "end_line": 3813, "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": 3817, "end_line": 3823, "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": 3826, "end_line": 3840, "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": 3843, "end_line": 3887, "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": 19, "parameters": [ "self" ], "start_line": 3891, "end_line": 3894, "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": 8, "complexity": 3, "token_count": 42, "parameters": [ "self" ], "start_line": 3897, "end_line": 3904, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "array_typechar_get", "long_name": "array_typechar_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 8, "complexity": 2, "token_count": 47, "parameters": [ "self" ], "start_line": 3908, "end_line": 3915, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "array_typestr_get", "long_name": "array_typestr_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 19, "complexity": 7, "token_count": 141, "parameters": [ "self" ], "start_line": 3918, "end_line": 3938, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "array_descr_get", "long_name": "array_descr_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 19, "complexity": 5, "token_count": 128, "parameters": [ "self" ], "start_line": 3941, "end_line": 3963, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "array_type_get", "long_name": "array_type_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 4, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 3967, "end_line": 3970, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "array_type_set", "long_name": "array_type_set( PyArrayObject * self , PyObject * arg)", "filename": "arrayobject.c", "nloc": 41, "complexity": 10, "token_count": 294, "parameters": [ "self", "arg" ], "start_line": 3982, "end_line": 4040, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 59, "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": 4045, "end_line": 4055, "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": 4059, "end_line": 4084, "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": 31, "complexity": 4, "token_count": 177, "parameters": [ "self", "val" ], "start_line": 4088, "end_line": 4120, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "array_imag_get", "long_name": "array_imag_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 34, "complexity": 3, "token_count": 200, "parameters": [ "self" ], "start_line": 4123, "end_line": 4158, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "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": 203, "parameters": [ "self", "val" ], "start_line": 4161, "end_line": 4198, "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": 4201, "end_line": 4204, "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": 51, "complexity": 9, "token_count": 368, "parameters": [ "self", "val" ], "start_line": 4207, "end_line": 4261, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 55, "top_nesting_level": 0 }, { "name": "discover_depth", "long_name": "discover_depth( PyObject * s , int max , int stop_at_string)", "filename": "arrayobject.c", "nloc": 23, "complexity": 14, "token_count": 169, "parameters": [ "s", "max", "stop_at_string" ], "start_line": 4436, "end_line": 4461, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "discover_itemsize", "long_name": "discover_itemsize( PyObject * s , int nd , int * itemsize)", "filename": "arrayobject.c", "nloc": 21, "complexity": 9, "token_count": 161, "parameters": [ "s", "nd", "itemsize" ], "start_line": 4464, "end_line": 4486, "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": 4493, "end_line": 4519, "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( int chktype , int mintype , int chksize , int minsize , PyArray_Typecode * outtype)", "filename": "arrayobject.c", "nloc": 19, "complexity": 5, "token_count": 100, "parameters": [ "chktype", "mintype", "chksize", "minsize", "outtype" ], "start_line": 4522, "end_line": 4542, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "_array_find_type", "long_name": "_array_find_type( PyObject * op , PyArray_Typecode * minitype , PyArray_Typecode * outtype , int max)", "filename": "arrayobject.c", "nloc": 126, "complexity": 28, "token_count": 671, "parameters": [ "op", "minitype", "outtype", "max" ], "start_line": 4545, "end_line": 4686, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 142, "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": 4689, "end_line": 4712, "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_Typecode * typecode)", "filename": "arrayobject.c", "nloc": 21, "complexity": 5, "token_count": 132, "parameters": [ "op", "typecode" ], "start_line": 4716, "end_line": 4742, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 0 }, { "name": "Array_FromSequence", "long_name": "Array_FromSequence( PyObject * s , PyArray_Typecode * typecode , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 51, "complexity": 17, "token_count": 313, "parameters": [ "s", "typecode", "min_depth", "max_depth" ], "start_line": 4746, "end_line": 4803, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 58, "top_nesting_level": 0 }, { "name": "PyArray_ValidType", "long_name": "PyArray_ValidType( int type)", "filename": "arrayobject.c", "nloc": 7, "complexity": 2, "token_count": 30, "parameters": [ "type" ], "start_line": 4807, "end_line": 4814, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "_bufferedcast", "long_name": "_bufferedcast( PyArrayObject * out , PyArrayObject * in)", "filename": "arrayobject.c", "nloc": 75, "complexity": 16, "token_count": 477, "parameters": [ "out", "in" ], "start_line": 4820, "end_line": 4910, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 91, "top_nesting_level": 0 }, { "name": "PyArray_Cast", "long_name": "PyArray_Cast( PyArrayObject * mp , int type_num)", "filename": "arrayobject.c", "nloc": 10, "complexity": 1, "token_count": 56, "parameters": [ "mp", "type_num" ], "start_line": 4916, "end_line": 4927, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_CastToType", "long_name": "PyArray_CastToType( PyArrayObject * mp , PyArray_Typecode * at)", "filename": "arrayobject.c", "nloc": 31, "complexity": 13, "token_count": 233, "parameters": [ "mp", "at" ], "start_line": 4930, "end_line": 4965, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "PyArray_CastTo", "long_name": "PyArray_CastTo( PyArrayObject * out , PyArrayObject * mp)", "filename": "arrayobject.c", "nloc": 40, "complexity": 10, "token_count": 214, "parameters": [ "out", "mp" ], "start_line": 4972, "end_line": 5018, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "array_fromarray", "long_name": "array_fromarray( PyArrayObject * arr , PyArray_Typecode * typecode , int flags)", "filename": "arrayobject.c", "nloc": 116, "complexity": 35, "token_count": 721, "parameters": [ "arr", "typecode", "flags" ], "start_line": 5021, "end_line": 5152, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 132, "top_nesting_level": 0 }, { "name": "_array_typecode_fromstr", "long_name": "_array_typecode_fromstr( char * str , int * swap , PyArray_Typecode * type)", "filename": "arrayobject.c", "nloc": 94, "complexity": 36, "token_count": 533, "parameters": [ "str", "swap", "type" ], "start_line": 5156, "end_line": 5261, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 106, "top_nesting_level": 0 }, { "name": "array_frominterface", "long_name": "array_frominterface( PyObject * input , PyArray_Typecode * intype , int flags)", "filename": "arrayobject.c", "nloc": 113, "complexity": 26, "token_count": 715, "parameters": [ "input", "intype", "flags" ], "start_line": 5264, "end_line": 5387, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 124, "top_nesting_level": 0 }, { "name": "array_fromattr", "long_name": "array_fromattr( PyObject * op , PyArray_Typecode * typecode , int flags)", "filename": "arrayobject.c", "nloc": 30, "complexity": 5, "token_count": 181, "parameters": [ "op", "typecode", "flags" ], "start_line": 5390, "end_line": 5421, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "array_fromobject", "long_name": "array_fromobject( PyObject * op , PyArray_Typecode * typecode , int min_depth , int max_depth , int flags)", "filename": "arrayobject.c", "nloc": 49, "complexity": 14, "token_count": 291, "parameters": [ "op", "typecode", "min_depth", "max_depth", "flags" ], "start_line": 5425, "end_line": 5490, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 66, "top_nesting_level": 0 }, { "name": "PyArray_ArrayType", "long_name": "PyArray_ArrayType( PyObject * op , PyArray_Typecode * intype , PyArray_Typecode * outtype)", "filename": "arrayobject.c", "nloc": 6, "complexity": 1, "token_count": 29, "parameters": [ "op", "intype", "outtype" ], "start_line": 5493, "end_line": 5498, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "PyArray_ObjectType", "long_name": "PyArray_ObjectType( PyObject * op , int minimum_type)", "filename": "arrayobject.c", "nloc": 7, "complexity": 1, "token_count": 40, "parameters": [ "op", "minimum_type" ], "start_line": 5501, "end_line": 5507, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "PyArray_FromAny", "long_name": "PyArray_FromAny( PyObject * op , PyArray_Typecode * typecode , int min_depth , int max_depth , int requires)", "filename": "arrayobject.c", "nloc": 24, "complexity": 9, "token_count": 165, "parameters": [ "op", "typecode", "min_depth", "max_depth", "requires" ], "start_line": 5561, "end_line": 5591, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "PyArray_EnsureArray", "long_name": "PyArray_EnsureArray( PyObject * op)", "filename": "arrayobject.c", "nloc": 14, "complexity": 5, "token_count": 87, "parameters": [ "op" ], "start_line": 5602, "end_line": 5618, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "PyArray_FromObject", "long_name": "PyArray_FromObject( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 7, "complexity": 1, "token_count": 51, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5624, "end_line": 5630, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "PyArray_ContiguousFromObject", "long_name": "PyArray_ContiguousFromObject( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 8, "complexity": 1, "token_count": 51, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5633, "end_line": 5640, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_CopyFromObject", "long_name": "PyArray_CopyFromObject( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 8, "complexity": 1, "token_count": 51, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5643, "end_line": 5650, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_ContiguousFromAny", "long_name": "PyArray_ContiguousFromAny( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 8, "complexity": 1, "token_count": 49, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5655, "end_line": 5662, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_CanCastSafely", "long_name": "PyArray_CanCastSafely( int fromtype , int totype)", "filename": "arrayobject.c", "nloc": 81, "complexity": 39, "token_count": 476, "parameters": [ "fromtype", "totype" ], "start_line": 5665, "end_line": 5748, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 84, "top_nesting_level": 0 }, { "name": "PyArray_CanCastTo", "long_name": "PyArray_CanCastTo( PyArray_Typecode * from , PyArray_Typecode * to)", "filename": "arrayobject.c", "nloc": 24, "complexity": 7, "token_count": 134, "parameters": [ "from", "to" ], "start_line": 5751, "end_line": 5775, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 }, { "name": "PyArray_IterNew", "long_name": "PyArray_IterNew( PyObject * obj)", "filename": "arrayobject.c", "nloc": 34, "complexity": 6, "token_count": 258, "parameters": [ "obj" ], "start_line": 5785, "end_line": 5822, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "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": 5827, "end_line": 5837, "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": 6, "complexity": 1, "token_count": 25, "parameters": [ "it" ], "start_line": 5840, "end_line": 5845, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "arrayiter_traverse", "long_name": "arrayiter_traverse( PyArrayIterObject * it , visitproc visit , * arg)", "filename": "arrayobject.c", "nloc": 6, "complexity": 2, "token_count": 42, "parameters": [ "it", "visit", "arg" ], "start_line": 5848, "end_line": 5853, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "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": 5857, "end_line": 5860, "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": 42, "complexity": 7, "token_count": 272, "parameters": [ "self", "ind" ], "start_line": 5864, "end_line": 5912, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "iter_subscript_int", "long_name": "iter_subscript_int( PyArrayIterObject * self , PyArrayObject * ind)", "filename": "arrayobject.c", "nloc": 51, "complexity": 8, "token_count": 347, "parameters": [ "self", "ind" ], "start_line": 5915, "end_line": 5968, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 0 }, { "name": "iter_subscript", "long_name": "iter_subscript( PyArrayIterObject * self , PyObject * ind)", "filename": "arrayobject.c", "nloc": 97, "complexity": 20, "token_count": 593, "parameters": [ "self", "ind" ], "start_line": 5972, "end_line": 6091, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 120, "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": 176, "parameters": [ "self", "ind", "val", "swap" ], "start_line": 6095, "end_line": 6127, "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": 289, "parameters": [ "self", "ind", "val", "swap" ], "start_line": 6130, "end_line": 6172, "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": 103, "complexity": 24, "token_count": 636, "parameters": [ "self", "ind", "val" ], "start_line": 6176, "end_line": 6298, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 123, "top_nesting_level": 0 }, { "name": "iter_array", "long_name": "iter_array( PyArrayIterObject * it , PyObject * op)", "filename": "arrayobject.c", "nloc": 30, "complexity": 5, "token_count": 221, "parameters": [ "it", "op" ], "start_line": 6311, "end_line": 6353, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "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": 6358, "end_line": 6362, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "fancy_indexing_check", "long_name": "fancy_indexing_check( PyObject * args)", "filename": "arrayobject.c", "nloc": 55, "complexity": 22, "token_count": 293, "parameters": [ "args" ], "start_line": 6427, "end_line": 6488, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 62, "top_nesting_level": 0 }, { "name": "_convert_obj", "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", "filename": "arrayobject.c", "nloc": 15, "complexity": 5, "token_count": 105, "parameters": [ "obj", "iter" ], "start_line": 6496, "end_line": 6511, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "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": 6517, "end_line": 6586, "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": 261, "parameters": [ "mit" ], "start_line": 6590, "end_line": 6627, "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": 296, "parameters": [ "mit" ], "start_line": 6633, "end_line": 6677, "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": 102, "complexity": 22, "token_count": 690, "parameters": [ "mit", "arr" ], "start_line": 6695, "end_line": 6831, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 137, "top_nesting_level": 0 }, { "name": "_nonzero_indices", "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", "filename": "arrayobject.c", "nloc": 57, "complexity": 15, "token_count": 454, "parameters": [ "myBool", "iters" ], "start_line": 6837, "end_line": 6906, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 70, "top_nesting_level": 0 }, { "name": "PyArray_MapIterNew", "long_name": "PyArray_MapIterNew( PyObject * indexobj)", "filename": "arrayobject.c", "nloc": 111, "complexity": 24, "token_count": 745, "parameters": [ "indexobj" ], "start_line": 6909, "end_line": 7042, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 134, "top_nesting_level": 0 }, { "name": "arraymapiter_new", "long_name": "arraymapiter_new( PyTypeObject * type , PyObject * args , PyObject * kwds)", "filename": "arrayobject.c", "nloc": 26, "complexity": 5, "token_count": 130, "parameters": [ "type", "args", "kwds" ], "start_line": 7048, "end_line": 7078, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "arraymapiter_dealloc", "long_name": "arraymapiter_dealloc( PyArrayMapIterObject * mit)", "filename": "arrayobject.c", "nloc": 10, "complexity": 2, "token_count": 60, "parameters": [ "mit" ], "start_line": 7099, "end_line": 7108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "arraymapiter_traverse", "long_name": "arraymapiter_traverse( PyArrayMapIterObject * mit , visitproc visit , * arg)", "filename": "arrayobject.c", "nloc": 16, "complexity": 9, "token_count": 146, "parameters": [ "mit", "visit", "arg" ], "start_line": 7111, "end_line": 7129, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 } ], "methods_before": [ { "name": "PyArray_PyIntAsIntp", "long_name": "PyArray_PyIntAsIntp( PyObject * o)", "filename": "arrayobject.c", "nloc": 59, "complexity": 19, "token_count": 385, "parameters": [ "o" ], "start_line": 40, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 64, "top_nesting_level": 0 }, { "name": "PyArray_PyIntAsInt", "long_name": "PyArray_PyIntAsInt( PyObject * o)", "filename": "arrayobject.c", "nloc": 57, "complexity": 19, "token_count": 389, "parameters": [ "o" ], "start_line": 109, "end_line": 169, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 61, "top_nesting_level": 0 }, { "name": "PyArray_GetPriority", "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", "filename": "arrayobject.c", "nloc": 17, "complexity": 5, "token_count": 86, "parameters": [ "obj", "default_" ], "start_line": 173, "end_line": 191, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "PyArray_Zero", "long_name": "PyArray_Zero( PyArrayObject * arr)", "filename": "arrayobject.c", "nloc": 34, "complexity": 6, "token_count": 190, "parameters": [ "arr" ], "start_line": 208, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "PyArray_One", "long_name": "PyArray_One( PyArrayObject * arr)", "filename": "arrayobject.c", "nloc": 40, "complexity": 7, "token_count": 222, "parameters": [ "arr" ], "start_line": 246, "end_line": 289, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "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": 295, "end_line": 345, "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": 368, "end_line": 399, "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": 213, "parameters": [ "src" ], "start_line": 402, "end_line": 436, "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": 449, "end_line": 471, "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": 474, "end_line": 495, "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": 499, "end_line": 537, "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": 542, "end_line": 562, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "index2ptr", "long_name": "index2ptr( PyArrayObject * mp , int i)", "filename": "arrayobject.c", "nloc": 10, "complexity": 7, "token_count": 86, "parameters": [ "mp", "i" ], "start_line": 570, "end_line": 580, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "PyArray_Size", "long_name": "PyArray_Size( PyObject * op)", "filename": "arrayobject.c", "nloc": 9, "complexity": 2, "token_count": 33, "parameters": [ "op" ], "start_line": 583, "end_line": 591, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "PyArray_CopyInto", "long_name": "PyArray_CopyInto( PyArrayObject * dest , PyArrayObject * src)", "filename": "arrayobject.c", "nloc": 71, "complexity": 16, "token_count": 427, "parameters": [ "dest", "src" ], "start_line": 604, "end_line": 684, "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": 16, "complexity": 2, "token_count": 98, "parameters": [ "dest", "src_object" ], "start_line": 688, "end_line": 707, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "PyArray_FromDimsAndDataAndDescr", "long_name": "PyArray_FromDimsAndDataAndDescr( int nd , int * d , PyArray_Descr * descr , char * data)", "filename": "arrayobject.c", "nloc": 15, "complexity": 3, "token_count": 121, "parameters": [ "nd", "d", "descr", "data" ], "start_line": 715, "end_line": 734, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "PyArray_FromDimsAndData", "long_name": "PyArray_FromDimsAndData( int nd , int * d , int type , char * data)", "filename": "arrayobject.c", "nloc": 14, "complexity": 3, "token_count": 112, "parameters": [ "nd", "d", "type", "data" ], "start_line": 738, "end_line": 755, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "PyArray_FromDims", "long_name": "PyArray_FromDims( int nd , int * d , int type)", "filename": "arrayobject.c", "nloc": 14, "complexity": 5, "token_count": 133, "parameters": [ "nd", "d", "type" ], "start_line": 759, "end_line": 776, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "PyArray_Copy", "long_name": "PyArray_Copy( PyArrayObject * m1)", "filename": "arrayobject.c", "nloc": 11, "complexity": 2, "token_count": 77, "parameters": [ "m1" ], "start_line": 782, "end_line": 794, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "PyArray_Scalar", "long_name": "PyArray_Scalar( char * data , int type_num , int itemsize , int swap)", "filename": "arrayobject.c", "nloc": 48, "complexity": 8, "token_count": 289, "parameters": [ "data", "type_num", "itemsize", "swap" ], "start_line": 800, "end_line": 849, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "top_nesting_level": 0 }, { "name": "PyArray_ToScalar", "long_name": "PyArray_ToScalar( char * data , PyArrayObject * arr)", "filename": "arrayobject.c", "nloc": 7, "complexity": 1, "token_count": 51, "parameters": [ "data", "arr" ], "start_line": 856, "end_line": 863, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_Return", "long_name": "PyArray_Return( PyArrayObject * mp)", "filename": "arrayobject.c", "nloc": 17, "complexity": 5, "token_count": 85, "parameters": [ "mp" ], "start_line": 869, "end_line": 888, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "PyArray_RegisterDataType", "long_name": "PyArray_RegisterDataType( PyTypeObject * type)", "filename": "arrayobject.c", "nloc": 31, "complexity": 6, "token_count": 177, "parameters": [ "type" ], "start_line": 899, "end_line": 931, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "PyArray_RegisterDescrForType", "long_name": "PyArray_RegisterDescrForType( int typenum , PyArray_Descr * descr)", "filename": "arrayobject.c", "nloc": 32, "complexity": 3, "token_count": 167, "parameters": [ "typenum", "descr" ], "start_line": 941, "end_line": 984, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "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": 16, "token_count": 577, "parameters": [ "self", "fp", "sep", "format" ], "start_line": 988, "end_line": 1079, "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": 24, "complexity": 5, "token_count": 151, "parameters": [ "self" ], "start_line": 1082, "end_line": 1110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "PyArray_ToString", "long_name": "PyArray_ToString( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 34, "complexity": 6, "token_count": 191, "parameters": [ "self" ], "start_line": 1113, "end_line": 1148, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "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": 1157, "end_line": 1194, "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": 1201, "end_line": 1209, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "array_item", "long_name": "array_item( PyArrayObject * self , int i)", "filename": "arrayobject.c", "nloc": 22, "complexity": 4, "token_count": 150, "parameters": [ "self", "i" ], "start_line": 1213, "end_line": 1237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "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": 26, "parameters": [ "self", "i" ], "start_line": 1240, "end_line": 1243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "array_ass_item", "long_name": "array_ass_item( PyArrayObject * self , int i , PyObject * v)", "filename": "arrayobject.c", "nloc": 27, "complexity": 8, "token_count": 177, "parameters": [ "self", "i", "v" ], "start_line": 1247, "end_line": 1277, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "slice_coerce_index", "long_name": "slice_coerce_index( PyObject * o , int * v)", "filename": "arrayobject.c", "nloc": 9, "complexity": 2, "token_count": 40, "parameters": [ "o", "v" ], "start_line": 1281, "end_line": 1289, "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 , int length , int * start , int * stop , int * step , intp * slicelength)", "filename": "arrayobject.c", "nloc": 45, "complexity": 24, "token_count": 376, "parameters": [ "r", "length", "start", "stop", "step", "slicelength" ], "start_line": 1295, "end_line": 1345, "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 , int * step_size , intp * n_steps , int max)", "filename": "arrayobject.c", "nloc": 45, "complexity": 11, "token_count": 223, "parameters": [ "op", "step_size", "n_steps", "max" ], "start_line": 1352, "end_line": 1397, "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": 89, "complexity": 20, "token_count": 540, "parameters": [ "self", "op", "dimensions", "strides", "offset_ptr" ], "start_line": 1401, "end_line": 1496, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 96, "top_nesting_level": 0 }, { "name": "_swap_axes", "long_name": "_swap_axes( PyArrayMapIterObject * mit , PyArrayObject ** ret)", "filename": "arrayobject.c", "nloc": 24, "complexity": 4, "token_count": 187, "parameters": [ "mit", "ret" ], "start_line": 1499, "end_line": 1533, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "PyArray_GetMap", "long_name": "PyArray_GetMap( PyArrayMapIterObject * mit)", "filename": "arrayobject.c", "nloc": 36, "complexity": 8, "token_count": 252, "parameters": [ "mit" ], "start_line": 1538, "end_line": 1587, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "top_nesting_level": 0 }, { "name": "PyArray_SetMap", "long_name": "PyArray_SetMap( PyArrayMapIterObject * mit , PyObject * op)", "filename": "arrayobject.c", "nloc": 50, "complexity": 12, "token_count": 392, "parameters": [ "mit", "op" ], "start_line": 1590, "end_line": 1649, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 60, "top_nesting_level": 0 }, { "name": "array_subscript", "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", "filename": "arrayobject.c", "nloc": 61, "complexity": 19, "token_count": 425, "parameters": [ "self", "op" ], "start_line": 1670, "end_line": 1745, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 76, "top_nesting_level": 0 }, { "name": "array_ass_sub", "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", "filename": "arrayobject.c", "nloc": 43, "complexity": 9, "token_count": 251, "parameters": [ "self", "index", "op" ], "start_line": 1758, "end_line": 1810, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "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": 1818, "end_line": 1821, "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": 1840, "end_line": 1852, "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": 1855, "end_line": 1870, "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": 1874, "end_line": 1883, "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": 1886, "end_line": 1897, "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": 1965, "end_line": 1998, "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": 2005, "end_line": 2044, "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": 23, "complexity": 5, "token_count": 136, "parameters": [ "m1", "op", "axis", "rtype" ], "start_line": 2047, "end_line": 2069, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "PyArray_GenericAccumulateFunction", "long_name": "PyArray_GenericAccumulateFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", "filename": "arrayobject.c", "nloc": 23, "complexity": 5, "token_count": 136, "parameters": [ "m1", "op", "axis", "rtype" ], "start_line": 2073, "end_line": 2095, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "PyArray_GenericBinaryFunction", "long_name": "PyArray_GenericBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", "filename": "arrayobject.c", "nloc": 12, "complexity": 2, "token_count": 69, "parameters": [ "m1", "m2", "op" ], "start_line": 2099, "end_line": 2110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_GenericUnaryFunction", "long_name": "PyArray_GenericUnaryFunction( PyArrayObject * m1 , PyObject * op)", "filename": "arrayobject.c", "nloc": 12, "complexity": 2, "token_count": 63, "parameters": [ "m1", "op" ], "start_line": 2113, "end_line": 2124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_GenericInplaceBinaryFunction", "long_name": "PyArray_GenericInplaceBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", "filename": "arrayobject.c", "nloc": 13, "complexity": 2, "token_count": 71, "parameters": [ "m1", "m2", "op" ], "start_line": 2127, "end_line": 2139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 2142, "end_line": 2145, "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": 2148, "end_line": 2151, "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": 2154, "end_line": 2157, "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": 2160, "end_line": 2163, "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": 2166, "end_line": 2169, "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": 2172, "end_line": 2175, "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": 2178, "end_line": 2181, "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": 2184, "end_line": 2187, "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": 2190, "end_line": 2193, "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": 2196, "end_line": 2199, "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": 2202, "end_line": 2205, "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": 2208, "end_line": 2211, "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": 2214, "end_line": 2217, "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": 2220, "end_line": 2223, "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": 2226, "end_line": 2229, "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": 2232, "end_line": 2235, "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": 2238, "end_line": 2241, "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": 2244, "end_line": 2247, "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": 2250, "end_line": 2253, "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": 2256, "end_line": 2259, "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": 2262, "end_line": 2265, "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": 2268, "end_line": 2271, "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": 2274, "end_line": 2277, "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": 2280, "end_line": 2283, "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": 2286, "end_line": 2289, "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": 2292, "end_line": 2295, "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": 2298, "end_line": 2301, "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": 2304, "end_line": 2308, "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": 2311, "end_line": 2315, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "array_all_nonzero", "long_name": "array_all_nonzero( PyArrayObject * mp)", "filename": "arrayobject.c", "nloc": 18, "complexity": 4, "token_count": 93, "parameters": [ "mp" ], "start_line": 2319, "end_line": 2337, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "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": 2340, "end_line": 2355, "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": 143, "parameters": [ "v" ], "start_line": 2359, "end_line": 2385, "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": 143, "parameters": [ "v" ], "start_line": 2388, "end_line": 2413, "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": 124, "parameters": [ "v" ], "start_line": 2416, "end_line": 2438, "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": 124, "parameters": [ "v" ], "start_line": 2441, "end_line": 2463, "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": 124, "parameters": [ "v" ], "start_line": 2466, "end_line": 2488, "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": 2491, "end_line": 2495, "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": 34, "complexity": 11, "token_count": 258, "parameters": [ "self", "ilow", "ihigh" ], "start_line": 2556, "end_line": 2594, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "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": 2598, "end_line": 2619, "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": 4, "complexity": 1, "token_count": 26, "parameters": [ "self", "el" ], "start_line": 2622, "end_line": 2627, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "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": 308, "parameters": [ "string", "n", "max_n", "data", "nd", "dimensions", "strides", "self" ], "start_line": 2648, "end_line": 2695, "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": 222, "parameters": [ "self" ], "start_line": 2698, "end_line": 2734, "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": 2740, "end_line": 2757, "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": 2760, "end_line": 2772, "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": 2775, "end_line": 2787, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "array_richcompare", "long_name": "array_richcompare( PyArrayObject * self , PyObject * other , int cmp_op)", "filename": "arrayobject.c", "nloc": 61, "complexity": 13, "token_count": 273, "parameters": [ "self", "other", "cmp_op" ], "start_line": 2791, "end_line": 2868, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 78, "top_nesting_level": 0 }, { "name": "_check_axis", "long_name": "_check_axis( PyArrayObject * arr , int * axis , int flags)", "filename": "arrayobject.c", "nloc": 29, "complexity": 8, "token_count": 164, "parameters": [ "arr", "axis", "flags" ], "start_line": 2871, "end_line": 2900, "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": 17, "complexity": 4, "token_count": 91, "parameters": [ "len", "vals" ], "start_line": 2906, "end_line": 2922, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "PyArray_IntpFromSequence", "long_name": "PyArray_IntpFromSequence( PyObject * seq , intp * vals , int maxvals)", "filename": "arrayobject.c", "nloc": 21, "complexity": 7, "token_count": 161, "parameters": [ "seq", "vals", "maxvals" ], "start_line": 2927, "end_line": 2950, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "_IsContiguous", "long_name": "_IsContiguous( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 14, "complexity": 6, "token_count": 109, "parameters": [ "ap" ], "start_line": 2956, "end_line": 2972, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_IsFortranContiguous", "long_name": "_IsFortranContiguous( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 14, "complexity": 6, "token_count": 107, "parameters": [ "ap" ], "start_line": 2976, "end_line": 2992, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_IsAligned", "long_name": "_IsAligned( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 14, "complexity": 4, "token_count": 110, "parameters": [ "ap" ], "start_line": 2995, "end_line": 3011, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_IsWriteable", "long_name": "_IsWriteable( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 16, "complexity": 8, "token_count": 109, "parameters": [ "ap" ], "start_line": 3014, "end_line": 3047, "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": 22, "complexity": 9, "token_count": 129, "parameters": [ "ret", "flagmask" ], "start_line": 3051, "end_line": 3073, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "PyArray_CheckStrides", "long_name": "PyArray_CheckStrides( int elsize , int nd , intp numbytes , intp * dims , intp * newstrides)", "filename": "arrayobject.c", "nloc": 13, "complexity": 4, "token_count": 84, "parameters": [ "elsize", "nd", "numbytes", "dims", "newstrides" ], "start_line": 3080, "end_line": 3095, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "_array_fill_strides", "long_name": "_array_fill_strides( intp * strides , intp * dims , int nd , intp itemsize , int inflag , int * objflags)", "filename": "arrayobject.c", "nloc": 24, "complexity": 9, "token_count": 171, "parameters": [ "strides", "dims", "nd", "itemsize", "inflag", "objflags" ], "start_line": 3115, "end_line": 3139, "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 , char * data , int itemsize , int flags , PyObject * obj)", "filename": "arrayobject.c", "nloc": 117, "complexity": 27, "token_count": 713, "parameters": [ "subtype", "nd", "dims", "type_num", "strides", "data", "itemsize", "flags", "obj" ], "start_line": 3143, "end_line": 3293, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 151, "top_nesting_level": 0 }, { "name": "PyArray_Resize", "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape)", "filename": "arrayobject.c", "nloc": 87, "complexity": 15, "token_count": 501, "parameters": [ "self", "newshape" ], "start_line": 3298, "end_line": 3403, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 106, "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": 3408, "end_line": 3425, "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": 47, "complexity": 7, "token_count": 261, "parameters": [ "arr", "obj" ], "start_line": 3428, "end_line": 3480, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "top_nesting_level": 0 }, { "name": "array_new", "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", "filename": "arrayobject.c", "nloc": 100, "complexity": 20, "token_count": 589, "parameters": [ "subtype", "args", "kwds" ], "start_line": 3483, "end_line": 3598, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 116, "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": 3605, "end_line": 3608, "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": 10, "complexity": 3, "token_count": 57, "parameters": [ "self" ], "start_line": 3611, "end_line": 3621, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "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": 3694, "end_line": 3697, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "array_shape_set", "long_name": "array_shape_set( PyArrayObject * self , PyObject * val)", "filename": "arrayobject.c", "nloc": 33, "complexity": 6, "token_count": 206, "parameters": [ "self", "val" ], "start_line": 3701, "end_line": 3735, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "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": 3739, "end_line": 3742, "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": 32, "complexity": 7, "token_count": 209, "parameters": [ "self", "obj" ], "start_line": 3745, "end_line": 3778, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "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": 3782, "end_line": 3789, "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": 3792, "end_line": 3800, "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": 3804, "end_line": 3810, "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": 3813, "end_line": 3827, "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": 3830, "end_line": 3874, "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": 19, "parameters": [ "self" ], "start_line": 3878, "end_line": 3881, "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": 8, "complexity": 3, "token_count": 42, "parameters": [ "self" ], "start_line": 3884, "end_line": 3891, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "array_typechar_get", "long_name": "array_typechar_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 8, "complexity": 2, "token_count": 47, "parameters": [ "self" ], "start_line": 3895, "end_line": 3902, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "array_typestr_get", "long_name": "array_typestr_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 19, "complexity": 7, "token_count": 141, "parameters": [ "self" ], "start_line": 3905, "end_line": 3925, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "array_descr_get", "long_name": "array_descr_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 19, "complexity": 5, "token_count": 128, "parameters": [ "self" ], "start_line": 3928, "end_line": 3950, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "array_type_get", "long_name": "array_type_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 4, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 3954, "end_line": 3957, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "array_type_set", "long_name": "array_type_set( PyArrayObject * self , PyObject * arg)", "filename": "arrayobject.c", "nloc": 41, "complexity": 10, "token_count": 294, "parameters": [ "self", "arg" ], "start_line": 3969, "end_line": 4027, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 59, "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": 4032, "end_line": 4042, "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": 4046, "end_line": 4071, "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": 31, "complexity": 4, "token_count": 177, "parameters": [ "self", "val" ], "start_line": 4075, "end_line": 4107, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "array_imag_get", "long_name": "array_imag_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 34, "complexity": 3, "token_count": 200, "parameters": [ "self" ], "start_line": 4110, "end_line": 4145, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "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": 203, "parameters": [ "self", "val" ], "start_line": 4148, "end_line": 4185, "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": 4188, "end_line": 4191, "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": 51, "complexity": 9, "token_count": 368, "parameters": [ "self", "val" ], "start_line": 4194, "end_line": 4248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 55, "top_nesting_level": 0 }, { "name": "discover_depth", "long_name": "discover_depth( PyObject * s , int max , int stop_at_string)", "filename": "arrayobject.c", "nloc": 23, "complexity": 14, "token_count": 169, "parameters": [ "s", "max", "stop_at_string" ], "start_line": 4423, "end_line": 4448, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "discover_itemsize", "long_name": "discover_itemsize( PyObject * s , int nd , int * itemsize)", "filename": "arrayobject.c", "nloc": 21, "complexity": 9, "token_count": 161, "parameters": [ "s", "nd", "itemsize" ], "start_line": 4451, "end_line": 4473, "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": 4480, "end_line": 4506, "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( int chktype , int mintype , int chksize , int minsize , PyArray_Typecode * outtype)", "filename": "arrayobject.c", "nloc": 19, "complexity": 5, "token_count": 100, "parameters": [ "chktype", "mintype", "chksize", "minsize", "outtype" ], "start_line": 4509, "end_line": 4529, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "_array_find_type", "long_name": "_array_find_type( PyObject * op , PyArray_Typecode * minitype , PyArray_Typecode * outtype , int max)", "filename": "arrayobject.c", "nloc": 126, "complexity": 28, "token_count": 671, "parameters": [ "op", "minitype", "outtype", "max" ], "start_line": 4532, "end_line": 4673, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 142, "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": 4676, "end_line": 4699, "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_Typecode * typecode)", "filename": "arrayobject.c", "nloc": 21, "complexity": 5, "token_count": 132, "parameters": [ "op", "typecode" ], "start_line": 4703, "end_line": 4729, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 0 }, { "name": "Array_FromSequence", "long_name": "Array_FromSequence( PyObject * s , PyArray_Typecode * typecode , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 51, "complexity": 17, "token_count": 313, "parameters": [ "s", "typecode", "min_depth", "max_depth" ], "start_line": 4733, "end_line": 4790, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 58, "top_nesting_level": 0 }, { "name": "PyArray_ValidType", "long_name": "PyArray_ValidType( int type)", "filename": "arrayobject.c", "nloc": 7, "complexity": 2, "token_count": 30, "parameters": [ "type" ], "start_line": 4794, "end_line": 4801, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "_bufferedcast", "long_name": "_bufferedcast( PyArrayObject * out , PyArrayObject * in)", "filename": "arrayobject.c", "nloc": 75, "complexity": 16, "token_count": 477, "parameters": [ "out", "in" ], "start_line": 4807, "end_line": 4897, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 91, "top_nesting_level": 0 }, { "name": "PyArray_Cast", "long_name": "PyArray_Cast( PyArrayObject * mp , int type_num)", "filename": "arrayobject.c", "nloc": 10, "complexity": 1, "token_count": 56, "parameters": [ "mp", "type_num" ], "start_line": 4903, "end_line": 4914, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_CastToType", "long_name": "PyArray_CastToType( PyArrayObject * mp , PyArray_Typecode * at)", "filename": "arrayobject.c", "nloc": 31, "complexity": 13, "token_count": 233, "parameters": [ "mp", "at" ], "start_line": 4917, "end_line": 4952, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "PyArray_CastTo", "long_name": "PyArray_CastTo( PyArrayObject * out , PyArrayObject * mp)", "filename": "arrayobject.c", "nloc": 40, "complexity": 10, "token_count": 214, "parameters": [ "out", "mp" ], "start_line": 4959, "end_line": 5005, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "array_fromarray", "long_name": "array_fromarray( PyArrayObject * arr , PyArray_Typecode * typecode , int flags)", "filename": "arrayobject.c", "nloc": 116, "complexity": 35, "token_count": 721, "parameters": [ "arr", "typecode", "flags" ], "start_line": 5008, "end_line": 5139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 132, "top_nesting_level": 0 }, { "name": "_array_typecode_fromstr", "long_name": "_array_typecode_fromstr( char * str , int * swap , PyArray_Typecode * type)", "filename": "arrayobject.c", "nloc": 94, "complexity": 36, "token_count": 533, "parameters": [ "str", "swap", "type" ], "start_line": 5143, "end_line": 5248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 106, "top_nesting_level": 0 }, { "name": "array_frominterface", "long_name": "array_frominterface( PyObject * input , PyArray_Typecode * intype , int flags)", "filename": "arrayobject.c", "nloc": 113, "complexity": 26, "token_count": 715, "parameters": [ "input", "intype", "flags" ], "start_line": 5251, "end_line": 5374, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 124, "top_nesting_level": 0 }, { "name": "array_fromattr", "long_name": "array_fromattr( PyObject * op , PyArray_Typecode * typecode , int flags)", "filename": "arrayobject.c", "nloc": 30, "complexity": 5, "token_count": 181, "parameters": [ "op", "typecode", "flags" ], "start_line": 5377, "end_line": 5408, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "array_fromobject", "long_name": "array_fromobject( PyObject * op , PyArray_Typecode * typecode , int min_depth , int max_depth , int flags)", "filename": "arrayobject.c", "nloc": 49, "complexity": 14, "token_count": 291, "parameters": [ "op", "typecode", "min_depth", "max_depth", "flags" ], "start_line": 5412, "end_line": 5477, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 66, "top_nesting_level": 0 }, { "name": "PyArray_ArrayType", "long_name": "PyArray_ArrayType( PyObject * op , PyArray_Typecode * intype , PyArray_Typecode * outtype)", "filename": "arrayobject.c", "nloc": 6, "complexity": 1, "token_count": 29, "parameters": [ "op", "intype", "outtype" ], "start_line": 5480, "end_line": 5485, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "PyArray_ObjectType", "long_name": "PyArray_ObjectType( PyObject * op , int minimum_type)", "filename": "arrayobject.c", "nloc": 7, "complexity": 1, "token_count": 40, "parameters": [ "op", "minimum_type" ], "start_line": 5488, "end_line": 5494, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "PyArray_FromAny", "long_name": "PyArray_FromAny( PyObject * op , PyArray_Typecode * typecode , int min_depth , int max_depth , int requires)", "filename": "arrayobject.c", "nloc": 24, "complexity": 9, "token_count": 165, "parameters": [ "op", "typecode", "min_depth", "max_depth", "requires" ], "start_line": 5548, "end_line": 5578, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "PyArray_EnsureArray", "long_name": "PyArray_EnsureArray( PyObject * op)", "filename": "arrayobject.c", "nloc": 14, "complexity": 5, "token_count": 87, "parameters": [ "op" ], "start_line": 5589, "end_line": 5605, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "PyArray_FromObject", "long_name": "PyArray_FromObject( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 7, "complexity": 1, "token_count": 51, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5611, "end_line": 5617, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "PyArray_ContiguousFromObject", "long_name": "PyArray_ContiguousFromObject( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 8, "complexity": 1, "token_count": 51, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5620, "end_line": 5627, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_CopyFromObject", "long_name": "PyArray_CopyFromObject( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 8, "complexity": 1, "token_count": 51, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5630, "end_line": 5637, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_ContiguousFromAny", "long_name": "PyArray_ContiguousFromAny( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 8, "complexity": 1, "token_count": 49, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5642, "end_line": 5649, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_CanCastSafely", "long_name": "PyArray_CanCastSafely( int fromtype , int totype)", "filename": "arrayobject.c", "nloc": 81, "complexity": 39, "token_count": 476, "parameters": [ "fromtype", "totype" ], "start_line": 5652, "end_line": 5735, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 84, "top_nesting_level": 0 }, { "name": "PyArray_CanCastTo", "long_name": "PyArray_CanCastTo( PyArray_Typecode * from , PyArray_Typecode * to)", "filename": "arrayobject.c", "nloc": 24, "complexity": 7, "token_count": 134, "parameters": [ "from", "to" ], "start_line": 5738, "end_line": 5762, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 }, { "name": "PyArray_IterNew", "long_name": "PyArray_IterNew( PyObject * obj)", "filename": "arrayobject.c", "nloc": 34, "complexity": 6, "token_count": 258, "parameters": [ "obj" ], "start_line": 5772, "end_line": 5809, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "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": 5814, "end_line": 5824, "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": 6, "complexity": 1, "token_count": 25, "parameters": [ "it" ], "start_line": 5827, "end_line": 5832, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "arrayiter_traverse", "long_name": "arrayiter_traverse( PyArrayIterObject * it , visitproc visit , * arg)", "filename": "arrayobject.c", "nloc": 6, "complexity": 2, "token_count": 42, "parameters": [ "it", "visit", "arg" ], "start_line": 5835, "end_line": 5840, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "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": 5844, "end_line": 5847, "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": 42, "complexity": 7, "token_count": 272, "parameters": [ "self", "ind" ], "start_line": 5851, "end_line": 5899, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "iter_subscript_int", "long_name": "iter_subscript_int( PyArrayIterObject * self , PyArrayObject * ind)", "filename": "arrayobject.c", "nloc": 51, "complexity": 8, "token_count": 347, "parameters": [ "self", "ind" ], "start_line": 5902, "end_line": 5955, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 0 }, { "name": "iter_subscript", "long_name": "iter_subscript( PyArrayIterObject * self , PyObject * ind)", "filename": "arrayobject.c", "nloc": 97, "complexity": 20, "token_count": 593, "parameters": [ "self", "ind" ], "start_line": 5959, "end_line": 6078, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 120, "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": 176, "parameters": [ "self", "ind", "val", "swap" ], "start_line": 6082, "end_line": 6114, "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": 289, "parameters": [ "self", "ind", "val", "swap" ], "start_line": 6117, "end_line": 6159, "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": 103, "complexity": 24, "token_count": 636, "parameters": [ "self", "ind", "val" ], "start_line": 6163, "end_line": 6285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 123, "top_nesting_level": 0 }, { "name": "iter_array", "long_name": "iter_array( PyArrayIterObject * it , PyObject * op)", "filename": "arrayobject.c", "nloc": 30, "complexity": 5, "token_count": 221, "parameters": [ "it", "op" ], "start_line": 6298, "end_line": 6340, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "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": 6345, "end_line": 6349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "fancy_indexing_check", "long_name": "fancy_indexing_check( PyObject * args)", "filename": "arrayobject.c", "nloc": 55, "complexity": 22, "token_count": 293, "parameters": [ "args" ], "start_line": 6414, "end_line": 6475, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 62, "top_nesting_level": 0 }, { "name": "_convert_obj", "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", "filename": "arrayobject.c", "nloc": 15, "complexity": 5, "token_count": 105, "parameters": [ "obj", "iter" ], "start_line": 6483, "end_line": 6498, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "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": 6504, "end_line": 6573, "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": 261, "parameters": [ "mit" ], "start_line": 6577, "end_line": 6614, "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": 296, "parameters": [ "mit" ], "start_line": 6620, "end_line": 6664, "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": 102, "complexity": 22, "token_count": 690, "parameters": [ "mit", "arr" ], "start_line": 6682, "end_line": 6818, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 137, "top_nesting_level": 0 }, { "name": "_nonzero_indices", "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", "filename": "arrayobject.c", "nloc": 57, "complexity": 15, "token_count": 454, "parameters": [ "myBool", "iters" ], "start_line": 6824, "end_line": 6893, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 70, "top_nesting_level": 0 }, { "name": "PyArray_MapIterNew", "long_name": "PyArray_MapIterNew( PyObject * indexobj)", "filename": "arrayobject.c", "nloc": 111, "complexity": 24, "token_count": 745, "parameters": [ "indexobj" ], "start_line": 6896, "end_line": 7029, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 134, "top_nesting_level": 0 }, { "name": "arraymapiter_new", "long_name": "arraymapiter_new( PyTypeObject * type , PyObject * args , PyObject * kwds)", "filename": "arrayobject.c", "nloc": 26, "complexity": 5, "token_count": 130, "parameters": [ "type", "args", "kwds" ], "start_line": 7035, "end_line": 7065, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "arraymapiter_dealloc", "long_name": "arraymapiter_dealloc( PyArrayMapIterObject * mit)", "filename": "arrayobject.c", "nloc": 10, "complexity": 2, "token_count": 60, "parameters": [ "mit" ], "start_line": 7086, "end_line": 7095, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "arraymapiter_traverse", "long_name": "arraymapiter_traverse( PyArrayMapIterObject * mit , visitproc visit , * arg)", "filename": "arrayobject.c", "nloc": 16, "complexity": 9, "token_count": 146, "parameters": [ "mit", "visit", "arg" ], "start_line": 7098, "end_line": 7116, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "array_item", "long_name": "array_item( PyArrayObject * self , int i)", "filename": "arrayobject.c", "nloc": 22, "complexity": 4, "token_count": 150, "parameters": [ "self", "i" ], "start_line": 1213, "end_line": 1237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "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": 27, "complexity": 8, "token_count": 177, "parameters": [ "self", "i", "v" ], "start_line": 1247, "end_line": 1277, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "PyArray_ToList", "long_name": "PyArray_ToList( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 24, "complexity": 5, "token_count": 151, "parameters": [ "self" ], "start_line": 1082, "end_line": 1110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "array_big_item", "long_name": "array_big_item( PyArrayObject * self , intp i)", "filename": "arrayobject.c", "nloc": 22, "complexity": 4, "token_count": 150, "parameters": [ "self", "i" ], "start_line": 1213, "end_line": 1237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 }, { "name": "array_ass_sub", "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", "filename": "arrayobject.c", "nloc": 44, "complexity": 9, "token_count": 252, "parameters": [ "self", "index", "op" ], "start_line": 1770, "end_line": 1823, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 0 }, { "name": "index2ptr", "long_name": "index2ptr( PyArrayObject * mp , int i)", "filename": "arrayobject.c", "nloc": 10, "complexity": 7, "token_count": 86, "parameters": [ "mp", "i" ], "start_line": 570, "end_line": 580, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "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": 1240, "end_line": 1243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "index2ptr", "long_name": "index2ptr( PyArrayObject * mp , intp i)", "filename": "arrayobject.c", "nloc": 10, "complexity": 7, "token_count": 86, "parameters": [ "mp", "i" ], "start_line": 570, "end_line": 580, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "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": 1283, "end_line": 1286, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "array_subscript", "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", "filename": "arrayobject.c", "nloc": 62, "complexity": 19, "token_count": 420, "parameters": [ "self", "op" ], "start_line": 1681, "end_line": 1757, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 77, "top_nesting_level": 0 } ], "nloc": 5650, "complexity": 1234, "token_count": 33751, "diff_parsed": { "added": [ "index2ptr(PyArrayObject *mp, intp i)", "static PyObject *array_big_item(PyArrayObject *, intp);", " v=(PyArrayObject *)array_big_item(self, i);", "array_big_item(PyArrayObject *self, intp i)", "\tchar *item;", "\tPyArrayObject *r;", "", "", "", "\treturn PyArray_Return((PyArrayObject *)array_big_item(self, (intp) i));", "array_ass_big_item(PyArrayObject *self, intp i, PyObject *v)", " if((tmp = (PyArrayObject *)array_big_item(self, i)) == NULL)", "#if SIZEOF_INT == SIZEOF_INTP", "#define array_ass_item array_ass_big_item", "#else", "static int", "array_ass_item(PyArrayObject *self, int i, PyObject *v)", "{", "\treturn array_ass_big_item(self, (intp) i, v);", "}", "#endif", "", "", " int nd;", "\tintp i;", " return array_big_item(self, value);", " return array_big_item(self, value);", "\ti = PyArray_PyIntAsIntp(op);", "\t\treturn array_big_item(self, i);", " int ret;", "\tintp i;", "\ti = PyArray_PyIntAsIntp(index);", "\t\treturn array_ass_big_item(self, i, op);" ], "deleted": [ "index2ptr(PyArrayObject *mp, int i)", "static PyObject *array_item(PyArrayObject *, int);", " v=(PyArrayObject *)array_item(self, i);", "array_item(PyArrayObject *self, int i)", " char *item;", " PyArrayObject *r;", "", "", "", "\treturn PyArray_Return((PyArrayObject *)array_item(self, i));", "array_ass_item(PyArrayObject *self, int i, PyObject *v)", " if((tmp = (PyArrayObject *)array_item(self, i)) == NULL)", " int nd, i;", " return array_item(self, (int) value);", " return array_item(self, (int) value);", "\ti = PyArray_PyIntAsInt(op);", "\t\treturn array_item(self, i);", " int ret, i;", "\ti = PyArray_PyIntAsInt(index);", "\t\treturn array_ass_item(self, i, op);" ] } } ] }, { "hash": "1523841beea21af826131945038ea89e686815b9", "msg": "Finished impl. of new array_from_pyobj. Updates and clean up. Removed array_has_column_major_storage and transpose_strides functions from f2py extensions.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2005-10-26T13:54:20+00:00", "author_timezone": 0, "committer_date": "2005-10-26T13:54:20+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "83643d12f617983314c277505802789d1542928d" ], "project_name": "repo_copy", "project_path": "/tmp/tmpn4cqam_6/repo_copy", "deletions": 407, "insertions": 345, "lines": 752, "files": 6, "dmm_unit_size": 1.0, "dmm_unit_complexity": 1.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy/f2py2e/rules.py", "new_path": "scipy/f2py2e/rules.py", "filename": "rules.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -157,40 +157,6 @@\n \n \"\"\"+gentitle(\"See f2py2e/rules.py\")+\"\"\"\n \n-static char doc_f2py_has_column_major_storage[] = \\\"\\\\\n-Function has_column_major_storage(obj):\\\\n\\\\\n- Return transpose(obj).iscontiguous().\\\\n\\\";\n-static PyObject *f2py_has_column_major_storage(PyObject *self,PyObject *args) {\n- PyObject * obj = NULL;\n- if (!PyArg_ParseTuple(args, \\\"O\\\",&obj))\n- return NULL;\n- return Py_BuildValue(\\\"i\\\",(PyArray_Check(obj)? array_has_column_major_storage((PyArrayObject*)(obj)):0));\n-}\n-\n-static char doc_f2py_as_column_major_storage[] = \\\"\\\\\n-Function as_column_major_storage(arr):\\\\n\\\\\n- Return array in column major data storage order.\\\\n\\\";\n-static PyObject *f2py_as_column_major_storage(PyObject *self,PyObject *args) {\n- PyObject * obj = NULL;\n- PyArrayObject * arr = NULL;\n- if (!PyArg_ParseTuple(args, \\\"O\\\",&obj))\n- return NULL;\n- if (!PyArray_Check(obj)) {\n- PyErr_SetString(#modulename#_error,\\\"expected array object\\\\n\\\");\n- return NULL;\n- }\n- arr = (PyArrayObject*)obj;\n- arr = array_from_pyobj(arr->descr->type_num, arr->dimensions, arr->nd,\n- F2PY_INTENT_OUT|F2PY_INTENT_IN, obj);\n- if (arr == NULL) {\n- if (!PyErr_Occurred())\n- PyErr_SetString(#modulename#_error,\n- \\\"failed in converting argument to C/Fortran array\\\");\n- return NULL;\n- }\n- return Py_BuildValue(\\\"N\\\",arr);\n-}\n-\n static FortranDataDef f2py_routine_defs[] = {\n #routine_defs#\n \\t{NULL}\n@@ -198,8 +164,6 @@\n \n static PyMethodDef f2py_module_methods[] = {\n #pymethoddef#\n-\\t{\\\"has_column_major_storage\\\",f2py_has_column_major_storage,METH_VARARGS,doc_f2py_has_column_major_storage},\n-\\t{\\\"as_column_major_storage\\\",f2py_as_column_major_storage,METH_VARARGS,doc_f2py_as_column_major_storage},\n \\t{NULL,NULL}\n };\n \n", "added_lines": 0, "deleted_lines": 36, "source_code": "#!/usr/bin/env python\n\"\"\"\n\nRules for building C/API module with f2py2e.\n\nHere is a skeleton of a new wrapper function (13Dec2001):\n\nwrapper_function(args)\n declarations\n get_python_arguments, say, `a' and `b'\n\n get_a_from_python\n if (successful) {\n\n get_b_from_python\n if (successful) {\n\n callfortran\n if (succesful) {\n\n put_a_to_python\n if (succesful) {\n\n put_b_to_python\n if (succesful) {\n\n buildvalue = ...\n\n }\n\n }\n \n }\n\n }\n cleanup_b\n\n }\n cleanup_a\n\n return buildvalue\n\"\"\"\n\"\"\"\nCopyright 1999,2000 Pearu Peterson all rights reserved,\nPearu Peterson \nPermission to use, modify, and distribute this software is given under the\nterms of the LGPL. See http://www.fsf.org\n\nNO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n$Date: 2005/08/30 08:58:42 $\nPearu Peterson\n\"\"\"\n\n__version__ = \"$Revision: 1.129 $\"[10:-1]\n\nimport __version__\nf2py_version = __version__.version\n\nimport pprint\nimport sys,string,time,types,copy\nerrmess=sys.stderr.write\noutmess=sys.stdout.write\nshow=pprint.pprint\n\nfrom auxfuncs import *\nimport capi_maps\nfrom capi_maps import *\nimport cfuncs\nimport common_rules\nimport use_rules\nimport f90mod_rules\nimport func2subr\noptions={}\n\nsepdict={}\n#for k in ['need_cfuncs']: sepdict[k]=','\nfor k in ['decl',\n 'frompyobj',\n 'cleanupfrompyobj',\n 'topyarr','method',\n 'pyobjfrom','closepyobjfrom',\n 'freemem',\n 'userincludes',\n 'includes0','includes','typedefs','typedefs_generated',\n 'cppmacros','cfuncs','callbacks',\n 'latexdoc',\n 'restdoc',\n 'routine_defs','externroutines',\n 'initf2pywraphooks',\n 'commonhooks','initcommonhooks',\n 'f90modhooks','initf90modhooks']:\n sepdict[k]='\\n'\n\n#################### Rules for C/API module #################\n\nmodule_rules={\n 'modulebody':\"\"\"\\\n/* File: #modulename#module.c\n * This file is auto-generated with f2py (version:#f2py_version#).\n * f2py is a Fortran to Python Interface Generator (FPIG), Second Edition,\n * written by Pearu Peterson .\n * See http://cens.ioc.ee/projects/f2py2e/\n * Generation date: \"\"\"+time.asctime(time.localtime(time.time()))+\"\"\"\n * $R\"\"\"+\"\"\"evision:$\n * $D\"\"\"+\"\"\"ate:$\n * Do not edit this file directly unless you know what you are doing!!!\n */\n#ifdef __cplusplus\nextern \\\"C\\\" {\n#endif\n\n\"\"\"+gentitle(\"See f2py2e/cfuncs.py: includes\")+\"\"\"\n#includes#\n#includes0#\n\n\"\"\"+gentitle(\"See f2py2e/rules.py: mod_rules['modulebody']\")+\"\"\"\nstatic PyObject *#modulename#_error;\nstatic PyObject *#modulename#_module;\n\n\"\"\"+gentitle(\"See f2py2e/cfuncs.py: typedefs\")+\"\"\"\n#typedefs#\n\n\"\"\"+gentitle(\"See f2py2e/cfuncs.py: typedefs_generated\")+\"\"\"\n#typedefs_generated#\n\n\"\"\"+gentitle(\"See f2py2e/cfuncs.py: cppmacros\")+\"\"\"\n#cppmacros#\n\n\"\"\"+gentitle(\"See f2py2e/cfuncs.py: cfuncs\")+\"\"\"\n#cfuncs#\n\n\"\"\"+gentitle(\"See f2py2e/cfuncs.py: userincludes\")+\"\"\"\n#userincludes#\n\n\"\"\"+gentitle(\"See f2py2e/capi_rules.py: usercode\")+\"\"\"\n#usercode#\n\n/* See f2py2e/rules.py */\n#externroutines#\n\n\"\"\"+gentitle(\"See f2py2e/capi_rules.py: usercode1\")+\"\"\"\n#usercode1#\n\n\"\"\"+gentitle(\"See f2py2e/cb_rules.py: buildcallback\")+\"\"\"\n#callbacks#\n\n\"\"\"+gentitle(\"See f2py2e/rules.py: buildapi\")+\"\"\"\n#body#\n\n\"\"\"+gentitle(\"See f2py2e/f90mod_rules.py: buildhooks\")+\"\"\"\n#f90modhooks#\n\n\"\"\"+gentitle(\"See f2py2e/rules.py: module_rules['modulebody']\")+\"\"\"\n\n\"\"\"+gentitle(\"See f2py2e/common_rules.py: buildhooks\")+\"\"\"\n#commonhooks#\n\n\"\"\"+gentitle(\"See f2py2e/rules.py\")+\"\"\"\n\nstatic FortranDataDef f2py_routine_defs[] = {\n#routine_defs#\n\\t{NULL}\n};\n\nstatic PyMethodDef f2py_module_methods[] = {\n#pymethoddef#\n\\t{NULL,NULL}\n};\n\nDL_EXPORT(void) init#modulename#(void) {\n\\tint i;\n\\tPyObject *m,*d, *s;\n\\tm = #modulename#_module = Py_InitModule(\\\"#modulename#\\\", f2py_module_methods);\n\\tPyFortran_Type.ob_type = &PyType_Type;\n\\timport_array();\n\\tif (PyErr_Occurred())\n\\t\\tPy_FatalError(\\\"can't initialize module #modulename# (failed to import scipy.base)\\\");\n\\td = PyModule_GetDict(m);\n\\ts = PyString_FromString(\\\"$R\"\"\"+\"\"\"evision: $\\\");\n\\tPyDict_SetItemString(d, \\\"__version__\\\", s);\n\\ts = PyString_FromString(\\\"This module '#modulename#' is auto-generated with f2py (version:#f2py_version#).\\\\nFunctions:\\\\n\\\"\\n#docs#\\\".\\\");\n\\tPyDict_SetItemString(d, \\\"__doc__\\\", s);\n\\t#modulename#_error = PyErr_NewException (\\\"#modulename#.error\\\", NULL, NULL);\n\\tPy_DECREF(s);\n\\tfor(i=0;f2py_routine_defs[i].name!=NULL;i++)\n\\t\\tPyDict_SetItemString(d, f2py_routine_defs[i].name,PyFortranObject_NewAsAttr(&f2py_routine_defs[i]));\n#initf2pywraphooks#\n#initf90modhooks#\n#initcommonhooks#\n#interface_usercode#\n\\tif (PyErr_Occurred())\n\\t\\tPy_FatalError(\\\"can't initialize module #modulename#\\\");\n\n#ifdef F2PY_REPORT_ATEXIT\n\\ton_exit(f2py_report_on_exit,(void*)\\\"#modulename#\\\");\n#endif\n\n}\n#ifdef __cplusplus\n}\n#endif\n\"\"\",\n 'separatorsfor':{'latexdoc':'\\n\\n',\n 'restdoc':'\\n\\n'},\n 'latexdoc':['\\\\section{Module \\\\texttt{#texmodulename#}}\\n',\n '#modnote#\\n',\n '#latexdoc#'],\n 'restdoc':['Module #modulename#\\n'+'='*80,\n '\\n#restdoc#']\n }\n\ndefmod_rules=[\n {'body':'/*eof body*/',\n 'method':'/*eof method*/',\n 'externroutines':'/*eof externroutines*/',\n 'routine_defs':'/*eof routine_defs*/',\n 'initf90modhooks':'/*eof initf90modhooks*/',\n 'initf2pywraphooks':'/*eof initf2pywraphooks*/',\n 'initcommonhooks':'/*eof initcommonhooks*/',\n 'latexdoc':'',\n 'restdoc':'',\n 'modnote':{hasnote:'#note#',l_not(hasnote):''},\n }\n ]\n\nroutine_rules={\n 'separatorsfor':sepdict,\n 'body':\"\"\"\n#begintitle#\nstatic char doc_#apiname#[] = \\\"\\\\\\nFunction signature:\\\\n\\\\\\n\\t#docreturn##name#(#docsignatureshort#)\\\\n\\\\\\n#docstrsigns#\\\";\n/* #declfortranroutine# */\nstatic PyObject *#apiname#(const PyObject *capi_self,\n PyObject *capi_args,\n PyObject *capi_keywds,\n #functype# (*f2py_func)(#callprotoargument#)) {\n\\tPyObject * volatile capi_buildvalue = NULL;\n\\tvolatile int f2py_success = 1;\n#decl#\n\\tstatic char *capi_kwlist[] = {#kwlist##kwlistopt##kwlistxa#NULL};\n#usercode#\n#routdebugenter#\n#ifdef F2PY_REPORT_ATEXIT\nf2py_start_clock();\n#endif\n\\tif (!PyArg_ParseTupleAndKeywords(capi_args,capi_keywds,\\\\\n\\t\\t\\\"#argformat#|#keyformat##xaformat#:#pyname#\\\",\\\\\n\\t\\tcapi_kwlist#args_capi##keys_capi##keys_xa#))\\n\\t\\treturn NULL;\n#frompyobj#\n/*end of frompyobj*/\n#ifdef F2PY_REPORT_ATEXIT\nf2py_start_call_clock();\n#endif\n#callfortranroutine#\nif (PyErr_Occurred())\n f2py_success = 0;\n#ifdef F2PY_REPORT_ATEXIT\nf2py_stop_call_clock();\n#endif\n/*end of callfortranroutine*/\n\\t\\tif (f2py_success) {\n#pyobjfrom#\n/*end of pyobjfrom*/\n\\t\\tCFUNCSMESS(\\\"Building return value.\\\\n\\\");\n\\t\\tcapi_buildvalue = Py_BuildValue(\\\"#returnformat#\\\"#return#);\n/*closepyobjfrom*/\n#closepyobjfrom#\n\\t\\t} /*if (f2py_success) after callfortranroutine*/\n/*cleanupfrompyobj*/\n#cleanupfrompyobj#\n\\tif (capi_buildvalue == NULL) {\n#routdebugfailure#\n\\t} else {\n#routdebugleave#\n\\t}\n\\tCFUNCSMESS(\\\"Freeing memory.\\\\n\\\");\n#freemem#\n#ifdef F2PY_REPORT_ATEXIT\nf2py_stop_clock();\n#endif\n\\treturn capi_buildvalue;\n}\n#endtitle#\n\"\"\",\n 'routine_defs':'#routine_def#',\n 'initf2pywraphooks':'#initf2pywraphook#',\n 'externroutines':'#declfortranroutine#',\n 'doc':'#docreturn##name#(#docsignature#)',\n 'docshort':'#docreturn##name#(#docsignatureshort#)',\n 'docs':'\"\\t#docreturn##name#(#docsignature#)\\\\n\"\\n',\n 'need':['arrayobject.h','CFUNCSMESS','MINMAX'],\n 'cppmacros':{debugcapi:'#define DEBUGCFUNCS'},\n 'latexdoc':['\\\\subsection{Wrapper function \\\\texttt{#texname#}}\\n',\n \"\"\"\n\\\\noindent{{}\\\\verb@#docreturn##name#@{}}\\\\texttt{(#latexdocsignatureshort#)}\n#routnote#\n\n#latexdocstrsigns#\n\"\"\"],\n 'restdoc':['Wrapped function ``#name#``\\n'+'-'*80,\n \n ]\n }\n\n################## Rules for C/API function ##############\n\nrout_rules=[\n { # Init\n 'separatorsfor': {'callfortranroutine':'\\n','routdebugenter':'\\n','decl':'\\n',\n 'routdebugleave':'\\n','routdebugfailure':'\\n',\n 'setjmpbuf':' || ',\n 'docstrreq':'\\n','docstropt':'\\n','docstrout':'\\n',\n 'docstrcbs':'\\n','docstrsigns':'\\\\n\"\\n\"',\n 'latexdocstrsigns':'\\n',\n 'latexdocstrreq':'\\n','latexdocstropt':'\\n',\n 'latexdocstrout':'\\n','latexdocstrcbs':'\\n',\n },\n 'kwlist':'','kwlistopt':'','callfortran':'','callfortranappend':'',\n 'docsign':'','docsignopt':'','decl':'/*decl*/',\n 'freemem':'/*freemem*/',\n 'docsignshort':'','docsignoptshort':'',\n 'docstrsigns':'','latexdocstrsigns':'',\n 'docstrreq':'Required arguments:',\n 'docstropt':'Optional arguments:',\n 'docstrout':'Return objects:',\n 'docstrcbs':'Call-back functions:',\n 'latexdocstrreq':'\\\\noindent Required arguments:',\n 'latexdocstropt':'\\\\noindent Optional arguments:',\n 'latexdocstrout':'\\\\noindent Return objects:',\n 'latexdocstrcbs':'\\\\noindent Call-back functions:',\n 'args_capi':'','keys_capi':'','functype':'',\n 'frompyobj':'/*frompyobj*/',\n 'cleanupfrompyobj':['/*end of cleanupfrompyobj*/'], #this list will be reversed\n 'pyobjfrom':'/*pyobjfrom*/',\n 'closepyobjfrom':['/*end of closepyobjfrom*/'], #this list will be reversed\n 'topyarr':'/*topyarr*/','routdebugleave':'/*routdebugleave*/',\n 'routdebugenter':'/*routdebugenter*/',\n 'routdebugfailure':'/*routdebugfailure*/',\n 'callfortranroutine':'/*callfortranroutine*/',\n 'argformat':'','keyformat':'','need_cfuncs':'',\n 'docreturn':'','return':'','returnformat':'','rformat':'',\n 'kwlistxa':'','keys_xa':'','xaformat':'','docsignxa':'','docsignxashort':'',\n 'initf2pywraphook':'',\n 'routnote':{hasnote:'--- #note#',l_not(hasnote):''},\n },{\n 'apiname':'f2py_rout_#modulename#_#name#',\n 'pyname':'#modulename#.#name#',\n 'decl':'',\n '_check':l_not(ismoduleroutine)\n },{\n 'apiname':'f2py_rout_#modulename#_#f90modulename#_#name#',\n 'pyname':'#modulename#.#f90modulename#.#name#',\n 'decl':'',\n '_check':ismoduleroutine\n },{ # Subroutine\n 'functype':'void',\n 'declfortranroutine':{l_and(l_not(l_or(ismoduleroutine,isintent_c)),l_not(isdummyroutine)):'extern void #F_FUNC#(#fortranname#,#FORTRANNAME#)(#callprotoargument#);',\n l_and(l_not(ismoduleroutine),isintent_c,l_not(isdummyroutine)):'extern void #fortranname#(#callprotoargument#);',\n ismoduleroutine:'',\n isdummyroutine:''\n },\n 'routine_def':{l_not(l_or(ismoduleroutine,isintent_c,isdummyroutine)):'\\t{\\\"#name#\\\",-1,{{-1}},0,(char *)#F_FUNC#(#fortranname#,#FORTRANNAME#),(f2py_init_func)#apiname#,doc_#apiname#},',\n l_and(l_not(ismoduleroutine),isintent_c,l_not(isdummyroutine)):'\\t{\\\"#name#\\\",-1,{{-1}},0,(char *)#fortranname#,(f2py_init_func)#apiname#,doc_#apiname#},',\n l_and(l_not(ismoduleroutine),isdummyroutine):'\\t{\\\"#name#\\\",-1,{{-1}},0,NULL,(f2py_init_func)#apiname#,doc_#apiname#},',\n },\n 'need':{l_and(l_not(l_or(ismoduleroutine,isintent_c)),l_not(isdummyroutine)):'F_FUNC'},\n 'callfortranroutine':[\n {debugcapi:[\"\"\"\\tfprintf(stderr,\\\"debug-capi:Fortran subroutine `#fortranname#(#callfortran#)\\'\\\\n\\\");\"\"\"]},\n {hasexternals:\"\"\"\\\n\\t\\tif (#setjmpbuf#) {\n\\t\\t\\tf2py_success = 0;\n\\t\\t} else {\"\"\"},\n {isthreadsafe:'\\t\\t\\tPy_BEGIN_ALLOW_THREADS'},\n {hascallstatement:'''\\t\\t\\t\\t#callstatement#;\n\\t\\t\\t\\t/*(*f2py_func)(#callfortran#);*/'''},\n {l_not(l_or(hascallstatement,isdummyroutine)):'\\t\\t\\t\\t(*f2py_func)(#callfortran#);'},\n {isthreadsafe:'\\t\\t\\tPy_END_ALLOW_THREADS'},\n {hasexternals:\"\"\"\\t\\t}\"\"\"}\n ],\n '_check':issubroutine,\n },{ # Wrapped function\n 'functype':'void',\n 'declfortranroutine':{l_not(l_or(ismoduleroutine,isdummyroutine)):'extern void #F_WRAPPEDFUNC#(#name_lower#,#NAME#)(#callprotoargument#);',\n isdummyroutine:'',\n },\n\n 'routine_def':{l_not(l_or(ismoduleroutine,isdummyroutine)):'\\t{\\\"#name#\\\",-1,{{-1}},0,(char *)#F_WRAPPEDFUNC#(#name_lower#,#NAME#),(f2py_init_func)#apiname#,doc_#apiname#},',\n isdummyroutine:'\\t{\\\"#name#\\\",-1,{{-1}},0,NULL,(f2py_init_func)#apiname#,doc_#apiname#},',\n },\n 'initf2pywraphook':{l_not(l_or(ismoduleroutine,isdummyroutine)):'''\n {\n extern #ctype# #F_FUNC#(#name_lower#,#NAME#)(void);\n PyObject* o = PyDict_GetItemString(d,\"#name#\");\n PyObject_SetAttrString(o,\"_cpointer\", PyCObject_FromVoidPtr((void*)#F_FUNC#(#name_lower#,#NAME#),NULL));\n }\n '''},\n 'need':{l_not(l_or(ismoduleroutine,isdummyroutine)):['F_WRAPPEDFUNC','F_FUNC']},\n 'callfortranroutine':[\n {debugcapi:[\"\"\"\\tfprintf(stderr,\\\"debug-capi:Fortran subroutine `f2pywrap#name_lower#(#callfortran#)\\'\\\\n\\\");\"\"\"]},\n {hasexternals:\"\"\"\\\n\\tif (#setjmpbuf#) {\n\\t\\tf2py_success = 0;\n\\t} else {\"\"\"},\n {isthreadsafe:'\\tPy_BEGIN_ALLOW_THREADS'},\n {l_not(l_or(hascallstatement,isdummyroutine)):'\\t(*f2py_func)(#callfortran#);'},\n {hascallstatement:'\\t#callstatement#;\\n\\t/*(*f2py_func)(#callfortran#);*/'},\n {isthreadsafe:'\\tPy_END_ALLOW_THREADS'},\n {hasexternals:'\\t}'}\n ],\n '_check':isfunction_wrap,\n },{ # Function\n 'functype':'#ctype#',\n 'docreturn':{l_not(isintent_hide):'#rname#,'},\n 'docstrout':'\\t#pydocsignout#',\n 'latexdocstrout':['\\\\item[]{{}\\\\verb@#pydocsignout#@{}}',\n {hasresultnote:'--- #resultnote#'}],\n 'callfortranroutine':[{l_and(debugcapi,isstringfunction):\"\"\"\\\n#ifdef USESCOMPAQFORTRAN\n\\tfprintf(stderr,\\\"debug-capi:Fortran function #ctype# #fortranname#(#callcompaqfortran#)\\\\n\\\");\n#else\n\\tfprintf(stderr,\\\"debug-capi:Fortran function #ctype# #fortranname#(#callfortran#)\\\\n\\\");\n#endif\n\"\"\"},\n {l_and(debugcapi,l_not(isstringfunction)):\"\"\"\\\n\\tfprintf(stderr,\\\"debug-capi:Fortran function #ctype# #fortranname#(#callfortran#)\\\\n\\\");\n\"\"\"}\n ],\n '_check':l_and(isfunction,l_not(isfunction_wrap))\n },{ # Scalar function\n 'declfortranroutine':{l_and(l_not(l_or(ismoduleroutine,isintent_c)),l_not(isdummyroutine)):'extern #ctype# #F_FUNC#(#fortranname#,#FORTRANNAME#)(#callprotoargument#);',\n l_and(l_not(ismoduleroutine),isintent_c,l_not(isdummyroutine)):'extern #ctype# #fortranname#(#callprotoargument#);',\n isdummyroutine:''\n },\n 'routine_def':{l_and(l_not(l_or(ismoduleroutine,isintent_c)),l_not(isdummyroutine)):'\\t{\\\"#name#\\\",-1,{{-1}},0,(char *)#F_FUNC#(#fortranname#,#FORTRANNAME#),(f2py_init_func)#apiname#,doc_#apiname#},',\n l_and(l_not(ismoduleroutine),isintent_c,l_not(isdummyroutine)):'\\t{\\\"#name#\\\",-1,{{-1}},0,(char *)#fortranname#,(f2py_init_func)#apiname#,doc_#apiname#},',\n isdummyroutine:'\\t{\\\"#name#\\\",-1,{{-1}},0,NULL,(f2py_init_func)#apiname#,doc_#apiname#},',\n },\n 'decl':[{iscomplexfunction_warn:'\\t#ctype# #name#_return_value={0,0};',\n l_not(iscomplexfunction):'\\t#ctype# #name#_return_value=0;'},\n {iscomplexfunction:'\\tPyObject *#name#_return_value_capi = Py_None;'}\n ],\n 'callfortranroutine':[\n {hasexternals:\"\"\"\\\n\\tif (#setjmpbuf#) {\n\\t\\tf2py_success = 0;\n\\t} else {\"\"\"},\n {isthreadsafe:'\\tPy_BEGIN_ALLOW_THREADS'},\n {hascallstatement:'''\\t#callstatement#;\n/*\\t#name#_return_value = (*f2py_func)(#callfortran#);*/\n'''},\n {l_not(l_or(hascallstatement,isdummyroutine)):'\\t#name#_return_value = (*f2py_func)(#callfortran#);'},\n {isthreadsafe:'\\tPy_END_ALLOW_THREADS'},\n {hasexternals:'\\t}'},\n {l_and(debugcapi,iscomplexfunction):'\\tfprintf(stderr,\"#routdebugshowvalue#\\\\n\",#name#_return_value.r,#name#_return_value.i);'},\n {l_and(debugcapi,l_not(iscomplexfunction)):'\\tfprintf(stderr,\"#routdebugshowvalue#\\\\n\",#name#_return_value);'}],\n 'pyobjfrom':{iscomplexfunction:'\\t#name#_return_value_capi = pyobj_from_#ctype#1(#name#_return_value);'},\n 'need':[{l_not(isdummyroutine):'F_FUNC'},\n {iscomplexfunction:'pyobj_from_#ctype#1'},\n {islong_longfunction:'long_long'},\n {islong_doublefunction:'long_double'}],\n 'returnformat':{l_not(isintent_hide):'#rformat#'},\n 'return':{iscomplexfunction:',#name#_return_value_capi',\n l_not(l_or(iscomplexfunction,isintent_hide)):',#name#_return_value'},\n '_check':l_and(isfunction,l_not(isstringfunction),l_not(isfunction_wrap))\n },{ # String function # in use for --no-wrap\n 'declfortranroutine':'extern void #F_FUNC#(#fortranname#,#FORTRANNAME#)(#callprotoargument#);',\n 'routine_def':{l_not(l_or(ismoduleroutine,isintent_c)):\n# '\\t{\\\"#name#\\\",-1,{{-1}},0,(char *)F_FUNC(#fortranname#,#FORTRANNAME#),(void *)#apiname#,doc_#apiname#},',\n '\\t{\\\"#name#\\\",-1,{{-1}},0,(char *)#F_FUNC#(#fortranname#,#FORTRANNAME#),(f2py_init_func)#apiname#,doc_#apiname#},',\n l_and(l_not(ismoduleroutine),isintent_c):\n# '\\t{\\\"#name#\\\",-1,{{-1}},0,(char *)#fortranname#,(void *)#apiname#,doc_#apiname#},'\n '\\t{\\\"#name#\\\",-1,{{-1}},0,(char *)#fortranname#,(f2py_init_func)#apiname#,doc_#apiname#},'\n },\n 'decl':['\\t#ctype# #name#_return_value = NULL;',\n '\\tint #name#_return_value_len = 0;'],\n 'callfortran':'#name#_return_value,#name#_return_value_len,',\n 'callfortranroutine':['\\t#name#_return_value_len = #rlength#;',\n '\\tif ((#name#_return_value = (string)malloc(sizeof(char)*(#name#_return_value_len+1))) == NULL) {',\n '\\t\\tPyErr_SetString(PyExc_MemoryError, \\\"out of memory\\\");',\n '\\t\\tf2py_success = 0;',\n '\\t} else {',\n \"\\t\\t(#name#_return_value)[#name#_return_value_len] = '\\\\0';\",\n '\\t}',\n '\\tif (f2py_success) {',\n {hasexternals:\"\"\"\\\n\\t\\tif (#setjmpbuf#) {\n\\t\\t\\tf2py_success = 0;\n\\t\\t} else {\"\"\"},\n {isthreadsafe:'\\t\\tPy_BEGIN_ALLOW_THREADS'},\n \"\"\"\\\n#ifdef USESCOMPAQFORTRAN\n\\t\\t(*f2py_func)(#callcompaqfortran#);\n#else\n\\t\\t(*f2py_func)(#callfortran#);\n#endif\n\"\"\",\n {isthreadsafe:'\\t\\tPy_END_ALLOW_THREADS'},\n {hasexternals:'\\t\\t}'},\n {debugcapi:'\\t\\tfprintf(stderr,\"#routdebugshowvalue#\\\\n\",#name#_return_value_len,#name#_return_value);'},\n '\\t} /* if (f2py_success) after (string)malloc */',\n ],\n 'returnformat':'#rformat#',\n 'return':',#name#_return_value',\n 'freemem':'\\tSTRINGFREE(#name#_return_value);',\n 'need':['F_FUNC','#ctype#','STRINGFREE'],\n '_check':l_and(isstringfunction,l_not(isfunction_wrap)) # ???obsolete\n },\n { # Debugging\n 'routdebugenter':'\\tfprintf(stderr,\"debug-capi:Python C/API function #modulename#.#name#(#docsignature#)\\\\n\");',\n 'routdebugleave':'\\tfprintf(stderr,\"debug-capi:Python C/API function #modulename#.#name#: successful.\\\\n\");',\n 'routdebugfailure':'\\tfprintf(stderr,\"debug-capi:Python C/API function #modulename#.#name#: failure.\\\\n\");',\n '_check':debugcapi\n }\n ]\n\n################ Rules for arguments ##################\n\ntypedef_need_dict = {islong_long:'long_long',\n islong_double:'long_double',\n islong_complex:'complex_long_double',\n isunsigned_char:'unsigned_char',\n isunsigned_short:'unsigned_short',\n isunsigned:'unsigned',\n isunsigned_long_long:'unsigned_long_long'}\n\naux_rules=[\n {\n 'separatorsfor':sepdict\n },\n { # Common\n 'frompyobj':['\\t/* Processing auxiliary variable #varname# */',\n {debugcapi:'\\tfprintf(stderr,\"#vardebuginfo#\\\\n\");'},],\n 'cleanupfrompyobj':'\\t/* End of cleaning variable #varname# */',\n 'need':typedef_need_dict,\n },\n# Scalars (not complex)\n { # Common\n 'decl':'\\t#ctype# #varname# = 0;',\n 'need':{hasinitvalue:'math.h'},\n 'frompyobj':{hasinitvalue:'\\t#varname# = #init#;'},\n '_check':l_and(isscalar,l_not(iscomplex)),\n },\n {\n 'return':',#varname#',\n 'docstrout':'\\t#pydocsignout#',\n 'docreturn':'#outvarname#,',\n 'returnformat':'#varrformat#',\n '_check':l_and(isscalar,l_not(iscomplex),isintent_out),\n },\n# Complex scalars\n { # Common\n 'decl':'\\t#ctype# #varname#;',\n 'frompyobj': {hasinitvalue:'\\t#varname#.r = #init.r#, #varname#.i = #init.i#;'},\n '_check':iscomplex\n },\n# String\n { # Common\n 'decl':['\\t#ctype# #varname# = NULL;',\n '\\tint slen(#varname#);',\n ],\n 'need':['len..'],\n '_check':isstring\n },\n# Array\n { # Common\n 'decl':['\\t#ctype# *#varname# = NULL;',\n '\\tintp #varname#_Dims[#rank#] = {#rank*[-1]#};',\n '\\tconst int #varname#_Rank = #rank#;',\n ],\n 'need':['len..',{hasinitvalue:'forcomb'},{hasinitvalue:'CFUNCSMESS'}],\n '_check':isarray\n },\n# Scalararray\n { # Common\n '_check':l_and(isarray,l_not(iscomplexarray))\n },{ # Not hidden\n '_check':l_and(isarray,l_not(iscomplexarray),isintent_nothide)\n },\n# Integer*1 array\n {'need':'#ctype#',\n '_check':isint1array,\n '_depend':''\n },\n# Integer*-1 array\n {'need':'#ctype#',\n '_check':isunsigned_chararray,\n '_depend':''\n },\n# Integer*-2 array\n {'need':'#ctype#',\n '_check':isunsigned_shortarray,\n '_depend':''\n },\n# Integer*-8 array\n {'need':'#ctype#',\n '_check':isunsigned_long_longarray,\n '_depend':''\n },\n# Complexarray\n {'need':'#ctype#',\n '_check':iscomplexarray,\n '_depend':''\n },\n# Stringarray\n {\n 'callfortranappend':{isarrayofstrings:'flen(#varname#),'},\n 'need':'string',\n '_check':isstringarray\n }\n ]\n\narg_rules=[\n {\n 'separatorsfor':sepdict\n },\n { # Common\n 'frompyobj':['\\t/* Processing variable #varname# */',\n {debugcapi:'\\tfprintf(stderr,\"#vardebuginfo#\\\\n\");'},],\n 'cleanupfrompyobj':'\\t/* End of cleaning variable #varname# */',\n '_depend':'',\n 'need':typedef_need_dict,\n },\n# Doc signatures\n {\n 'docstropt':{l_and(isoptional,isintent_nothide):'\\t#pydocsign#'},\n 'docstrreq':{l_and(isrequired,isintent_nothide):'\\t#pydocsign#'},\n 'docstrout':{isintent_out:'\\t#pydocsignout#'},\n 'latexdocstropt':{l_and(isoptional,isintent_nothide):['\\\\item[]{{}\\\\verb@#pydocsign#@{}}',\n {hasnote:'--- #note#'}]},\n 'latexdocstrreq':{l_and(isrequired,isintent_nothide):['\\\\item[]{{}\\\\verb@#pydocsign#@{}}',\n {hasnote:'--- #note#'}]},\n 'latexdocstrout':{isintent_out:['\\\\item[]{{}\\\\verb@#pydocsignout#@{}}',\n {l_and(hasnote,isintent_hide):'--- #note#',\n l_and(hasnote,isintent_nothide):'--- See above.'}]},\n 'depend':''\n },\n# Required/Optional arguments\n {\n 'kwlist':'\"#varname#\",',\n 'docsign':'#varname#,',\n '_check':l_and(isintent_nothide,l_not(isoptional))\n },\n {\n 'kwlistopt':'\"#varname#\",',\n 'docsignopt':'#varname#=#showinit#,',\n 'docsignoptshort':'#varname#,',\n '_check':l_and(isintent_nothide,isoptional)\n },\n# Docstring/BuildValue\n {\n 'docreturn':'#outvarname#,',\n 'returnformat':'#varrformat#',\n '_check':isintent_out\n },\n# Externals (call-back functions)\n { # Common\n 'docsignxa':{isintent_nothide:'#varname#_extra_args=(),'},\n 'docsignxashort':{isintent_nothide:'#varname#_extra_args,'},\n 'docstropt':{isintent_nothide:'\\t#varname#_extra_args := () input tuple'},\n 'docstrcbs':'#cbdocstr#',\n 'latexdocstrcbs':'\\\\item[] #cblatexdocstr#',\n 'latexdocstropt':{isintent_nothide:'\\\\item[]{{}\\\\verb@#varname#_extra_args := () input tuple@{}} --- Extra arguments for call-back function {{}\\\\verb@#varname#@{}}.'},\n 'decl':['\\tPyObject *#varname#_capi = Py_None;',\n '\\tPyTupleObject *#varname#_xa_capi = NULL;',\n '\\tPyTupleObject *#varname#_args_capi = NULL;',\n '\\tint #varname#_nofargs_capi = 0;',\n {l_not(isintent_callback):'\\t#cbname#_typedef #varname#_cptr;'}\n ],\n 'kwlistxa':{isintent_nothide:'\"#varname#_extra_args\",'},\n 'argformat':{isrequired:'O'},\n 'keyformat':{isoptional:'O'},\n 'xaformat':{isintent_nothide:'O!'},\n 'args_capi':{isrequired:',&#varname#_capi'},\n 'keys_capi':{isoptional:',&#varname#_capi'},\n 'keys_xa':',&PyTuple_Type,&#varname#_xa_capi',\n 'setjmpbuf':'(setjmp(#cbname#_jmpbuf))',\n 'callfortran':{l_not(isintent_callback):'#varname#_cptr,'},\n 'need':['#cbname#','setjmp.h'],\n '_check':isexternal\n },\n {\n 'frompyobj':[{l_not(isintent_callback):\"\"\"\\\nif(PyCObject_Check(#varname#_capi)) {\n #varname#_cptr = PyCObject_AsVoidPtr(#varname#_capi);\n} else {\n #varname#_cptr = #cbname#;\n}\n\"\"\"},{isintent_callback:\"\"\"\\\nif (#varname#_capi==Py_None) {\n #varname#_capi = PyObject_GetAttrString(#modulename#_module,\\\"#varname#\\\");\n if (#varname#_capi) {\n if (#varname#_xa_capi==NULL) {\n if (PyObject_HasAttrString(#modulename#_module,\\\"#varname#_extra_args\\\")) {\n PyObject* capi_tmp = PyObject_GetAttrString(#modulename#_module,\\\"#varname#_extra_args\\\");\n if (capi_tmp)\n #varname#_xa_capi = (PyTupleObject *)PySequence_Tuple(capi_tmp);\n else\n #varname#_xa_capi = (PyTupleObject *)Py_BuildValue(\\\"()\\\");\n if (#varname#_xa_capi==NULL) {\n PyErr_SetString(#modulename#_error,\\\"Failed to convert #modulename#.#varname#_extra_args to tuple.\\\\n\\\");\n return NULL;\n }\n }\n }\n }\n if (#varname#_capi==NULL) {\n PyErr_SetString(#modulename#_error,\\\"Callback #varname# not defined (as an argument or module #modulename# attribute).\\\\n\\\");\n return NULL;\n }\n}\n\"\"\"},\n## {l_not(isintent_callback):\"\"\"\\\n## if (#varname#_capi==Py_None) {\n## printf(\\\"hoi\\\\n\\\");\n## }\n## \"\"\"},\n\"\"\"\\\n\\t#varname#_nofargs_capi = #cbname#_nofargs;\n\\tif (create_cb_arglist(#varname#_capi,#varname#_xa_capi,#maxnofargs#,#nofoptargs#,&#cbname#_nofargs,&#varname#_args_capi,\\\"failed in processing argument list for call-back #varname#.\\\")) {\n\\t\\tjmp_buf #varname#_jmpbuf;\"\"\",\n{debugcapi:[\"\"\"\\\n\\t\\tfprintf(stderr,\\\"debug-capi:Assuming %d arguments; at most #maxnofargs#(-#nofoptargs#) is expected.\\\\n\\\",#cbname#_nofargs);\n\\t\\tCFUNCSMESSPY(\\\"for #varname#=\\\",#cbname#_capi);\"\"\",\n{l_not(isintent_callback):\"\"\"\\t\\tfprintf(stderr,\\\"#vardebugshowvalue# (call-back in C).\\\\n\\\",#cbname#);\"\"\"}]},\n \"\"\"\\\n\\t\\tCFUNCSMESS(\\\"Saving jmpbuf for `#varname#`.\\\\n\\\");\n\\t\\tSWAP(#varname#_capi,#cbname#_capi,PyObject);\n\\t\\tSWAP(#varname#_args_capi,#cbname#_args_capi,PyTupleObject);\n\\t\\tmemcpy(&#varname#_jmpbuf,&#cbname#_jmpbuf,sizeof(jmp_buf));\"\"\",\n ],\n'cleanupfrompyobj':\n\"\"\"\\\n\\t\\tCFUNCSMESS(\\\"Restoring jmpbuf for `#varname#`.\\\\n\\\");\n\\t\\t#cbname#_capi = #varname#_capi;\n\\t\\tPy_DECREF(#cbname#_args_capi);\n\\t\\t#cbname#_args_capi = #varname#_args_capi;\n\\t\\t#cbname#_nofargs = #varname#_nofargs_capi;\n\\t\\tmemcpy(&#cbname#_jmpbuf,&#varname#_jmpbuf,sizeof(jmp_buf));\n\\t}\"\"\",\n 'need':['SWAP','create_cb_arglist'],\n '_check':isexternal,\n '_depend':''\n },\n# Scalars (not complex)\n { # Common\n 'decl':'\\t#ctype# #varname# = 0;',\n 'pyobjfrom':{debugcapi:'\\tfprintf(stderr,\"#vardebugshowvalue#\\\\n\",#varname#);'},\n 'callfortran':{isintent_c:'#varname#,',l_not(isintent_c):'&#varname#,'},\n 'return':{isintent_out:',#varname#'},\n '_check':l_and(isscalar,l_not(iscomplex))\n },{\n 'need':{hasinitvalue:'math.h'},\n '_check':l_and(isscalar,l_not(iscomplex)),\n #'_depend':''\n },{ # Not hidden\n 'decl':'\\tPyObject *#varname#_capi = Py_None;',\n 'argformat':{isrequired:'O'},\n 'keyformat':{isoptional:'O'},\n 'args_capi':{isrequired:',&#varname#_capi'},\n 'keys_capi':{isoptional:',&#varname#_capi'},\n 'pyobjfrom':{isintent_inout:\"\"\"\\\n\\tf2py_success = try_pyarr_from_#ctype#(#varname#_capi,&#varname#);\n\\tif (f2py_success) {\"\"\"},\n 'closepyobjfrom':{isintent_inout:\"\\t} /*if (f2py_success) of #varname# pyobjfrom*/\"},\n 'need':{isintent_inout:'try_pyarr_from_#ctype#'},\n '_check':l_and(isscalar,l_not(iscomplex),isintent_nothide)\n },{\n 'frompyobj':[\n# hasinitvalue...\n# if pyobj is None:\n# varname = init\n# else\n# from_pyobj(varname)\n# \n# isoptional and noinitvalue...\n# if pyobj is not None:\n# from_pyobj(varname)\n# else:\n# varname is uninitialized\n#\n# ...\n# from_pyobj(varname)\n#\n {hasinitvalue:'\\tif (#varname#_capi == Py_None) #varname# = #init#; else',\n '_depend':''},\n {l_and(isoptional,l_not(hasinitvalue)):'\\tif (#varname#_capi != Py_None)',\n '_depend':''}, \n {l_not(islogical):'''\\\n\\t\\tf2py_success = #ctype#_from_pyobj(&#varname#,#varname#_capi,\"#pyname#() #nth# (#varname#) can\\'t be converted to #ctype#\");\n\\tif (f2py_success) {'''},\n {islogical:'''\\\n\\t\\t#varname# = (#ctype#)PyObject_IsTrue(#varname#_capi);\n\\t\\tf2py_success = 1;\n\\tif (f2py_success) {'''},\n ],\n 'cleanupfrompyobj':'\\t} /*if (f2py_success) of #varname#*/',\n 'need':{l_not(islogical):'#ctype#_from_pyobj'},\n '_check':l_and(isscalar,l_not(iscomplex),isintent_nothide),\n '_depend':''\n# },{ # Hidden\n# '_check':l_and(isscalar,l_not(iscomplex),isintent_hide)\n },{ # Hidden\n 'frompyobj':{hasinitvalue:'\\t#varname# = #init#;'},\n 'need':typedef_need_dict,\n '_check':l_and(isscalar,l_not(iscomplex),isintent_hide),\n '_depend':''\n },{ # Common\n 'frompyobj':{debugcapi:'\\tfprintf(stderr,\"#vardebugshowvalue#\\\\n\",#varname#);'},\n '_check':l_and(isscalar,l_not(iscomplex)),\n '_depend':''\n },\n# Complex scalars\n { # Common\n 'decl':'\\t#ctype# #varname#;',\n 'callfortran':{isintent_c:'#varname#,',l_not(isintent_c):'&#varname#,'},\n 'pyobjfrom':{debugcapi:'\\tfprintf(stderr,\"#vardebugshowvalue#\\\\n\",#varname#.r,#varname#.i);'},\n 'return':{isintent_out:',#varname#_capi'},\n '_check':iscomplex\n },{ # Not hidden\n 'decl':'\\tPyObject *#varname#_capi = Py_None;',\n 'argformat':{isrequired:'O'},\n 'keyformat':{isoptional:'O'},\n 'args_capi':{isrequired:',&#varname#_capi'},\n 'keys_capi':{isoptional:',&#varname#_capi'},\n 'need':{isintent_inout:'try_pyarr_from_#ctype#'},\n 'pyobjfrom':{isintent_inout:\"\"\"\\\n\\t\\tf2py_success = try_pyarr_from_#ctype#(#varname#_capi,&#varname#);\n\\t\\tif (f2py_success) {\"\"\"},\n 'closepyobjfrom':{isintent_inout:\"\\t\\t} /*if (f2py_success) of #varname# pyobjfrom*/\"},\n '_check':l_and(iscomplex,isintent_nothide)\n },{\n 'frompyobj':[{hasinitvalue:'\\tif (#varname#_capi==Py_None) {#varname#.r = #init.r#, #varname#.i = #init.i#;} else'},\n {l_and(isoptional,l_not(hasinitvalue)):'\\tif (#varname#_capi != Py_None)'},\n# '\\t\\tf2py_success = #ctype#_from_pyobj(&#varname#,#varname#_capi,\"#ctype#_from_pyobj failed in converting #nth# `#varname#\\' of #pyname# to C #ctype#\\\\n\");'\n '\\t\\tf2py_success = #ctype#_from_pyobj(&#varname#,#varname#_capi,\"#pyname#() #nth# (#varname#) can\\'t be converted to #ctype#\");'\n '\\n\\tif (f2py_success) {'],\n 'cleanupfrompyobj':'\\t} /*if (f2py_success) of #varname# frompyobj*/',\n 'need':['#ctype#_from_pyobj'],\n '_check':l_and(iscomplex,isintent_nothide),\n '_depend':''\n },{ # Hidden\n 'decl':{isintent_out:'\\tPyObject *#varname#_capi = Py_None;'},\n '_check':l_and(iscomplex,isintent_hide)\n },{\n 'frompyobj': {hasinitvalue:'\\t#varname#.r = #init.r#, #varname#.i = #init.i#;'},\n '_check':l_and(iscomplex,isintent_hide),\n '_depend':''\n },{ # Common\n 'pyobjfrom':{isintent_out:'\\t#varname#_capi = pyobj_from_#ctype#1(#varname#);'},\n 'need':['pyobj_from_#ctype#1'],\n '_check':iscomplex\n },{\n 'frompyobj':{debugcapi:'\\tfprintf(stderr,\"#vardebugshowvalue#\\\\n\",#varname#.r,#varname#.i);'},\n '_check':iscomplex,\n '_depend':''\n },\n# String\n { # Common\n 'decl':['\\t#ctype# #varname# = NULL;',\n '\\tint slen(#varname#);',\n '\\tPyObject *#varname#_capi = Py_None;'],\n 'callfortran':'#varname#,',\n 'callfortranappend':'slen(#varname#),',\n 'pyobjfrom':{debugcapi:'\\tfprintf(stderr,\"#vardebugshowvalue#\\\\n\",slen(#varname#),#varname#);'},\n# 'freemem':'\\tSTRINGFREE(#varname#);',\n 'return':{isintent_out:',#varname#'},\n 'need':['len..'],#'STRINGFREE'],\n '_check':isstring\n },{ # Common\n 'frompyobj':\"\"\"\\\n\\tslen(#varname#) = #length#;\n\\tf2py_success = #ctype#_from_pyobj(&#varname#,&slen(#varname#),#init#,#varname#_capi,\\\"#ctype#_from_pyobj failed in converting #nth# `#varname#\\' of #pyname# to C #ctype#\\\");\n\\tif (f2py_success) {\"\"\",\n 'cleanupfrompyobj':\"\"\"\\\n\\t\\tSTRINGFREE(#varname#);\n\\t} /*if (f2py_success) of #varname#*/\"\"\",\n 'need':['#ctype#_from_pyobj','len..','STRINGFREE'],\n '_check':isstring,\n '_depend':''\n },{ # Not hidden\n 'argformat':{isrequired:'O'},\n 'keyformat':{isoptional:'O'},\n 'args_capi':{isrequired:',&#varname#_capi'},\n 'keys_capi':{isoptional:',&#varname#_capi'},\n 'pyobjfrom':{isintent_inout:'''\\\n\\tf2py_success = try_pyarr_from_#ctype#(#varname#_capi,#varname#);\n\\tif (f2py_success) {'''},\n 'closepyobjfrom':{isintent_inout:'\\t} /*if (f2py_success) of #varname# pyobjfrom*/'},\n 'need':{isintent_inout:'try_pyarr_from_#ctype#'},\n '_check':l_and(isstring,isintent_nothide)\n },{ # Hidden\n '_check':l_and(isstring,isintent_hide)\n },{\n 'frompyobj':{debugcapi:'\\tfprintf(stderr,\"#vardebugshowvalue#\\\\n\",slen(#varname#),#varname#);'},\n '_check':isstring,\n '_depend':''\n },\n# Array\n { # Common\n 'decl':['\\t#ctype# *#varname# = NULL;',\n '\\tintp #varname#_Dims[#rank#] = {#rank*[-1]#};',\n '\\tconst int #varname#_Rank = #rank#;',\n '\\tPyArrayObject *capi_#varname#_tmp = NULL;',\n '\\tint capi_#varname#_intent = 0;',\n ],\n 'callfortran':'#varname#,',\n 'return':{isintent_out:',capi_#varname#_tmp'},\n 'need':'len..',\n '_check':isarray\n },{ # intent(overwrite) array\n 'decl':'\\tint capi_overwrite_#varname# = 1;',\n 'kwlistxa':'\"overwrite_#varname#\",',\n 'xaformat':'i',\n 'keys_xa':',&capi_overwrite_#varname#',\n 'docsignxa':'overwrite_#varname#=1,',\n 'docsignxashort':'overwrite_#varname#,',\n 'docstropt':'\\toverwrite_#varname# := 1 input int',\n '_check':l_and(isarray,isintent_overwrite),\n },{\n 'frompyobj':'\\tcapi_#varname#_intent |= (capi_overwrite_#varname#?0:F2PY_INTENT_COPY);',\n '_check':l_and(isarray,isintent_overwrite),\n '_depend':'',\n },\n { # intent(copy) array\n 'decl':'\\tint capi_overwrite_#varname# = 0;',\n 'kwlistxa':'\"overwrite_#varname#\",',\n 'xaformat':'i',\n 'keys_xa':',&capi_overwrite_#varname#',\n 'docsignxa':'overwrite_#varname#=0,',\n 'docsignxashort':'overwrite_#varname#,',\n 'docstropt':'\\toverwrite_#varname# := 0 input int',\n '_check':l_and(isarray,isintent_copy),\n },{\n 'frompyobj':'\\tcapi_#varname#_intent |= (capi_overwrite_#varname#?0:F2PY_INTENT_COPY);',\n '_check':l_and(isarray,isintent_copy),\n '_depend':'',\n },{ \n 'need':[{hasinitvalue:'forcomb'},{hasinitvalue:'CFUNCSMESS'}],\n '_check':isarray,\n '_depend':''\n },{ # Not hidden\n 'decl':'\\tPyObject *#varname#_capi = Py_None;',\n 'argformat':{isrequired:'O'},\n 'keyformat':{isoptional:'O'},\n 'args_capi':{isrequired:',&#varname#_capi'},\n 'keys_capi':{isoptional:',&#varname#_capi'},\n# 'pyobjfrom':{isintent_inout:\"\"\"\\\n# /* Partly because of the following hack, intent(inout) is depreciated,\n# Use intent(in,out) instead.\n \n# \\tif ((#varname#_capi != Py_None) && PyArray_Check(#varname#_capi) \\\\\n# \\t\\t&& (#varname#_capi != (PyObject *)capi_#varname#_tmp)) {\n# \\t\\tif (((PyArrayObject *)#varname#_capi)->nd != capi_#varname#_tmp->nd) {\n# \\t\\t\\tif (#varname#_capi != capi_#varname#_tmp->base)\n# \\t\\t\\t\\tcopy_ND_array((PyArrayObject *)capi_#varname#_tmp->base,(PyArrayObject *)#varname#_capi);\n# \\t\\t} else\n# \\t\\t\\tcopy_ND_array(capi_#varname#_tmp,(PyArrayObject *)#varname#_capi);\n# \\t}\n# */\n# \"\"\"},\n# 'need':{isintent_inout:'copy_ND_array'},\n '_check':l_and(isarray,isintent_nothide)\n },{\n 'frompyobj':['\\t#setdims#;',\n '\\tcapi_#varname#_intent |= #intent#;',\n {isintent_hide:'\\tcapi_#varname#_tmp = array_from_pyobj(#atype#,#varname#_Dims,#varname#_Rank,capi_#varname#_intent,Py_None);'},\n {isintent_nothide:'\\tcapi_#varname#_tmp = array_from_pyobj(#atype#,#varname#_Dims,#varname#_Rank,capi_#varname#_intent,#varname#_capi);'},\n \"\"\"\\\n\\tif (capi_#varname#_tmp == NULL) {\n\\t\\tif (!PyErr_Occurred())\n\\t\\t\\tPyErr_SetString(#modulename#_error,\\\"failed in converting #nth# `#varname#\\' of #pyname# to C/Fortran array\\\" );\n\\t} else {\n\\t\\t#varname# = (#ctype# *)(capi_#varname#_tmp->data);\n\"\"\",\n{hasinitvalue:[\n {isintent_nothide:'\\tif (#varname#_capi == Py_None) {'},\n {isintent_hide:'\\t{'},\n {iscomplexarray:'\\t\\t#ctype# capi_c;'},\n \"\"\"\\\n\\t\\tint *_i,capi_i=0;\n\\t\\tCFUNCSMESS(\\\"#name#: Initializing #varname#=#init#\\\\n\\\");\n\\t\\tif (initforcomb(capi_#varname#_tmp->dimensions,capi_#varname#_tmp->nd,1)) {\n\\t\\t\\twhile ((_i = nextforcomb()))\n\\t\\t\\t\\t#varname#[capi_i++] = #init#; /* fortran way */\n\\t\\t} else {\n\\t\\t\\tif (!PyErr_Occurred())\n\\t\\t\\t\\tPyErr_SetString(#modulename#_error,\\\"Initialization of #nth# #varname# failed (initforcomb).\\\");\n\\t\\t\\tf2py_success = 0;\n\\t\\t}\n\\t}\n\\tif (f2py_success) {\"\"\"]},\n ],\n 'cleanupfrompyobj':[ # note that this list will be reversed\n '\\t} /*if (capi_#varname#_tmp == NULL) ... else of #varname#*/',\n {l_not(l_or(isintent_out,isintent_hide)):\"\"\"\\\n\\tif((PyObject *)capi_#varname#_tmp!=#varname#_capi) {\n\\t\\tPy_XDECREF(capi_#varname#_tmp); }\"\"\"},\n {l_and(isintent_hide,l_not(isintent_out)):\"\"\"\\t\\tPy_XDECREF(capi_#varname#_tmp);\"\"\"},\n {hasinitvalue:'\\t} /*if (f2py_success) of #varname# init*/'},\n ],\n '_check':isarray,\n '_depend':''\n },\n# { # Hidden\n# 'freemem':{l_not(isintent_out):'\\tPy_XDECREF(capi_#varname#_tmp);'},\n# '_check':l_and(isarray,isintent_hide)\n# },\n# Scalararray\n { # Common\n '_check':l_and(isarray,l_not(iscomplexarray))\n },{ # Not hidden\n '_check':l_and(isarray,l_not(iscomplexarray),isintent_nothide)\n },\n# Integer*1 array\n {'need':'#ctype#',\n '_check':isint1array,\n '_depend':''\n },\n# Integer*-1 array\n {'need':'#ctype#',\n '_check':isunsigned_chararray,\n '_depend':''\n },\n# Integer*-2 array\n {'need':'#ctype#',\n '_check':isunsigned_shortarray,\n '_depend':''\n },\n# Integer*-8 array\n {'need':'#ctype#',\n '_check':isunsigned_long_longarray,\n '_depend':''\n },\n# Complexarray\n {'need':'#ctype#',\n '_check':iscomplexarray,\n '_depend':''\n },\n# Stringarray\n {\n 'callfortranappend':{isarrayofstrings:'flen(#varname#),'},\n 'need':'string',\n '_check':isstringarray\n }\n ]\n\n################# Rules for checking ###############\n\ncheck_rules=[\n {\n 'frompyobj':{debugcapi:'\\tfprintf(stderr,\\\"debug-capi:Checking `#check#\\'\\\\n\\\");'},\n 'need':'len..'\n },{\n 'frompyobj':'\\tCHECKSCALAR(#check#,\\\"#check#\\\",\\\"#nth# #varname#\\\",\\\"#varshowvalue#\\\",#varname#) {',\n 'cleanupfrompyobj':'\\t} /*CHECKSCALAR(#check#)*/',\n 'need':'CHECKSCALAR',\n '_check':l_and(isscalar,l_not(iscomplex)),\n '_break':''\n },{\n 'frompyobj':'\\tCHECKSTRING(#check#,\\\"#check#\\\",\\\"#nth# #varname#\\\",\\\"#varshowvalue#\\\",#varname#) {',\n 'cleanupfrompyobj':'\\t} /*CHECKSTRING(#check#)*/',\n 'need':'CHECKSTRING',\n '_check':isstring,\n '_break':''\n },{\n 'need':'CHECKARRAY',\n 'frompyobj':'\\tCHECKARRAY(#check#,\\\"#check#\\\",\\\"#nth# #varname#\\\") {',\n 'cleanupfrompyobj':'\\t} /*CHECKARRAY(#check#)*/',\n '_check':isarray,\n '_break':''\n },{\n 'need':'CHECKGENERIC',\n 'frompyobj':'\\tCHECKGENERIC(#check#,\\\"#check#\\\",\\\"#nth# #varname#\\\") {',\n 'cleanupfrompyobj':'\\t} /*CHECKGENERIC(#check#)*/',\n }\n]\n\n########## Applying the rules. No need to modify what follows #############\n\n#################### Build C/API module #######################\n\ndef buildmodule(m,um):\n \"\"\"\n Return \n \"\"\"\n global f2py_version,options\n outmess('\\tBuilding module \"%s\"...\\n'%(m['name']))\n ret = {}\n mod_rules=defmod_rules[:]\n vrd=modsign2map(m)\n rd=dictappend({'f2py_version':f2py_version},vrd)\n funcwrappers = []\n funcwrappers2 = [] # F90 codes\n for n in m['interfaced']:\n nb=None\n for bi in m['body']:\n if not bi['block']=='interface':\n errmess('buildmodule: Expected interface block. Skipping.\\n')\n continue\n for b in bi['body']:\n if b['name']==n: nb=b;break\n \n if not nb:\n errmess('buildmodule: Could not found the body of interfaced routine \"%s\". Skipping.\\n'%(n))\n continue\n nb_list = [nb]\n if nb.has_key('entry'):\n for k,a in nb['entry'].items():\n nb1 = copy.deepcopy(nb)\n del nb1['entry']\n nb1['name'] = k\n nb1['args'] = a\n nb_list.append(nb1)\n for nb in nb_list:\n api,wrap=buildapi(nb)\n if wrap:\n if ismoduleroutine(nb):\n funcwrappers2.append(wrap)\n else:\n funcwrappers.append(wrap)\n ar=applyrules(api,vrd)\n rd=dictappend(rd,ar)\n\n # Construct COMMON block support\n cr,wrap = common_rules.buildhooks(m)\n if wrap:\n funcwrappers.append(wrap)\n ar=applyrules(cr,vrd)\n rd=dictappend(rd,ar)\n\n # Construct F90 module support\n mr,wrap = f90mod_rules.buildhooks(m)\n if wrap:\n funcwrappers2.append(wrap)\n ar=applyrules(mr,vrd)\n rd=dictappend(rd,ar)\n\n for u in um:\n ar=use_rules.buildusevars(u,m['use'][u['name']])\n rd=dictappend(rd,ar)\n\n needs=cfuncs.get_needs()\n code={}\n for n in needs.keys():\n code[n]=[]\n for k in needs[n]:\n c=''\n if cfuncs.includes0.has_key(k): c=cfuncs.includes0[k]\n elif cfuncs.includes.has_key(k): c=cfuncs.includes[k]\n elif cfuncs.userincludes.has_key(k): c=cfuncs.userincludes[k]\n elif cfuncs.typedefs.has_key(k): c=cfuncs.typedefs[k]\n elif cfuncs.typedefs_generated.has_key(k):\n c=cfuncs.typedefs_generated[k]\n elif cfuncs.cppmacros.has_key(k): c=cfuncs.cppmacros[k]\n elif cfuncs.cfuncs.has_key(k): c=cfuncs.cfuncs[k]\n elif cfuncs.callbacks.has_key(k): c=cfuncs.callbacks[k]\n elif cfuncs.f90modhooks.has_key(k): c=cfuncs.f90modhooks[k]\n elif cfuncs.commonhooks.has_key(k): c=cfuncs.commonhooks[k]\n else: errmess('buildmodule: unknown need %s.\\n'%(`k`));continue\n code[n].append(c)\n mod_rules.append(code)\n for r in mod_rules:\n if (r.has_key('_check') and r['_check'](m)) or (not r.has_key('_check')):\n ar=applyrules(r,vrd,m)\n rd=dictappend(rd,ar)\n ar=applyrules(module_rules,rd)\n\n fn = os.path.join(options['buildpath'],vrd['modulename']+'module.c')\n ret['csrc'] = fn\n f=open(fn,'w')\n f.write(string.replace(ar['modulebody'],'\\t',2*' '))\n f.close()\n outmess('\\tWrote C/API module \"%s\" to file \"%s/%smodule.c\"\\n'%(m['name'],options['buildpath'],vrd['modulename']))\n\n if options['dorestdoc']:\n fn = os.path.join(options['buildpath'],vrd['modulename']+'module.rest')\n f=open(fn,'w')\n f.write('.. -*- rest -*-\\n')\n f.write(string.join(ar['restdoc'],'\\n'))\n f.close()\n outmess('\\tReST Documentation is saved to file \"%s/%smodule.rest\"\\n'%(options['buildpath'],vrd['modulename']))\n if options['dolatexdoc']:\n fn = os.path.join(options['buildpath'],vrd['modulename']+'module.tex')\n ret['ltx'] = fn\n f=open(fn,'w')\n f.write('%% This file is auto-generated with f2py (version:%s)\\n'%(f2py_version))\n if not options.has_key('shortlatex'):\n f.write('\\\\documentclass{article}\\n\\\\usepackage{a4wide}\\n\\\\begin{document}\\n\\\\tableofcontents\\n\\n')\n f.write(string.join(ar['latexdoc'],'\\n'))\n if not options.has_key('shortlatex'):\n f.write('\\\\end{document}')\n f.close()\n outmess('\\tDocumentation is saved to file \"%s/%smodule.tex\"\\n'%(options['buildpath'],vrd['modulename']))\n if funcwrappers:\n wn = os.path.join(options['buildpath'],'%s-f2pywrappers.f'%(vrd['modulename']))\n ret['fsrc'] = wn\n f=open(wn,'w')\n f.write('C -*- fortran -*-\\n')\n f.write('C This file is autogenerated with f2py (version:%s)\\n'%(f2py_version))\n f.write('C It contains Fortran 77 wrappers to fortran functions.\\n')\n lines = []\n for l in string.split(string.join(funcwrappers,'\\n\\n')+'\\n','\\n'):\n if l and l[0]==' ':\n while len(l)>=66:\n lines.append(l[:66]+'\\n &')\n l = l[66:]\n lines.append(l+'\\n')\n else: lines.append(l+'\\n')\n lines = string.join(lines,'').replace('\\n &\\n','\\n')\n f.write(lines)\n f.close()\n outmess('\\tFortran 77 wrappers are saved to \"%s\"\\n'%(wn))\n if funcwrappers2:\n wn = os.path.join(options['buildpath'],'%s-f2pywrappers2.f90'%(vrd['modulename']))\n ret['fsrc'] = wn\n f=open(wn,'w')\n f.write('! -*- f90 -*-\\n')\n f.write('! This file is autogenerated with f2py (version:%s)\\n'%(f2py_version))\n f.write('! It contains Fortran 90 wrappers to fortran functions.\\n')\n lines = []\n for l in string.split(string.join(funcwrappers2,'\\n\\n')+'\\n','\\n'):\n if len(l)>72 and l[0]==' ':\n lines.append(l[:72]+'&\\n &')\n l = l[72:]\n while len(l)>66:\n lines.append(l[:66]+'&\\n &')\n l = l[66:]\n lines.append(l+'\\n')\n else: lines.append(l+'\\n')\n lines = string.join(lines,'').replace('\\n &\\n','\\n')\n f.write(lines)\n f.close()\n outmess('\\tFortran 90 wrappers are saved to \"%s\"\\n'%(wn))\n return ret\n\n################## Build C/API function #############\n\nstnd={1:'st',2:'nd',3:'rd',4:'th',5:'th',6:'th',7:'th',8:'th',9:'th',0:'th'}\ndef buildapi(rout):\n rout,wrap = func2subr.assubr(rout)\n args,depargs=getargs2(rout)\n capi_maps.depargs=depargs\n var=rout['vars']\n auxvars = [a for a in var.keys() if isintent_aux(var[a])]\n \n if ismoduleroutine(rout):\n outmess('\\t\\t\\tConstructing wrapper function \"%s.%s\"...\\n'%(rout['modulename'],rout['name']))\n else:\n outmess('\\t\\tConstructing wrapper function \"%s\"...\\n'%(rout['name']))\n # Routine\n vrd=routsign2map(rout)\n rd=dictappend({},vrd)\n for r in rout_rules:\n if (r.has_key('_check') and r['_check'](rout)) or (not r.has_key('_check')):\n ar=applyrules(r,vrd,rout)\n rd=dictappend(rd,ar)\n\n # Args\n nth,nthk=0,0\n savevrd={}\n for a in args:\n vrd=sign2map(a,var[a])\n if isintent_aux(var[a]):\n _rules = aux_rules\n else:\n _rules = arg_rules\n if not isintent_hide(var[a]):\n if not isoptional(var[a]):\n nth=nth+1\n vrd['nth']=`nth`+stnd[nth%10]+' argument'\n else:\n nthk=nthk+1\n vrd['nth']=`nthk`+stnd[nthk%10]+' keyword'\n else: vrd['nth']='hidden' \n savevrd[a]=vrd\n for r in _rules:\n if r.has_key('_depend'): continue\n if (r.has_key('_check') and r['_check'](var[a])) or (not r.has_key('_check')):\n ar=applyrules(r,vrd,var[a])\n rd=dictappend(rd,ar)\n if r.has_key('_break'): break\n for a in depargs:\n if isintent_aux(var[a]):\n _rules = aux_rules\n else:\n _rules = arg_rules\n vrd=savevrd[a]\n for r in _rules:\n if not r.has_key('_depend'): continue\n if (r.has_key('_check') and r['_check'](var[a])) or (not r.has_key('_check')):\n ar=applyrules(r,vrd,var[a])\n rd=dictappend(rd,ar)\n if r.has_key('_break'): break\n if var[a].has_key('check'):\n for c in var[a]['check']:\n vrd['check']=c\n ar=applyrules(check_rules,vrd,var[a])\n rd=dictappend(rd,ar)\n if type(rd['cleanupfrompyobj']) is types.ListType:\n rd['cleanupfrompyobj'].reverse()\n if type(rd['closepyobjfrom']) is types.ListType:\n rd['closepyobjfrom'].reverse()\n rd['docsignature']=stripcomma(replace('#docsign##docsignopt##docsignxa#',\n {'docsign':rd['docsign'],\n 'docsignopt':rd['docsignopt'],\n 'docsignxa':rd['docsignxa']}))\n optargs=stripcomma(replace('#docsignopt##docsignxa#',\n {'docsignxa':rd['docsignxashort'],\n 'docsignopt':rd['docsignoptshort']}\n ))\n if optargs=='':\n rd['docsignatureshort']=stripcomma(replace('#docsign#',{'docsign':rd['docsign']}))\n else:\n rd['docsignatureshort']=replace('#docsign#[#docsignopt#]',\n {'docsign':rd['docsign'],\n 'docsignopt':optargs,\n })\n rd['latexdocsignatureshort']=string.replace(rd['docsignatureshort'],'_','\\\\_')\n rd['latexdocsignatureshort']=string.replace(rd['latexdocsignatureshort'],',',', ')\n cfs=stripcomma(replace('#callfortran##callfortranappend#',{'callfortran':rd['callfortran'],'callfortranappend':rd['callfortranappend']}))\n if len(rd['callfortranappend'])>1:\n rd['callcompaqfortran']=stripcomma(replace('#callfortran# 0,#callfortranappend#',{'callfortran':rd['callfortran'],'callfortranappend':rd['callfortranappend']}))\n else:\n rd['callcompaqfortran']=cfs\n rd['callfortran']=cfs\n if type(rd['docreturn'])==types.ListType:\n rd['docreturn']=stripcomma(replace('#docreturn#',{'docreturn':rd['docreturn']}))+' = '\n rd['docstrsigns']=[]\n rd['latexdocstrsigns']=[]\n for k in ['docstrreq','docstropt','docstrout','docstrcbs']:\n if rd.has_key(k) and type(rd[k])==types.ListType:\n rd['docstrsigns']=rd['docstrsigns']+rd[k]\n k='latex'+k\n if rd.has_key(k) and type(rd[k])==types.ListType:\n rd['latexdocstrsigns']=rd['latexdocstrsigns']+rd[k][0:1]+\\\n ['\\\\begin{description}']+rd[k][1:]+\\\n ['\\\\end{description}']\n ar=applyrules(routine_rules,rd)\n if ismoduleroutine(rout):\n outmess('\\t\\t\\t %s\\n'%(ar['docshort']))\n else:\n outmess('\\t\\t %s\\n'%(ar['docshort']))\n return ar,wrap\n\n\n#################### EOF rules.py #######################\n", "source_code_before": "#!/usr/bin/env python\n\"\"\"\n\nRules for building C/API module with f2py2e.\n\nHere is a skeleton of a new wrapper function (13Dec2001):\n\nwrapper_function(args)\n declarations\n get_python_arguments, say, `a' and `b'\n\n get_a_from_python\n if (successful) {\n\n get_b_from_python\n if (successful) {\n\n callfortran\n if (succesful) {\n\n put_a_to_python\n if (succesful) {\n\n put_b_to_python\n if (succesful) {\n\n buildvalue = ...\n\n }\n\n }\n \n }\n\n }\n cleanup_b\n\n }\n cleanup_a\n\n return buildvalue\n\"\"\"\n\"\"\"\nCopyright 1999,2000 Pearu Peterson all rights reserved,\nPearu Peterson \nPermission to use, modify, and distribute this software is given under the\nterms of the LGPL. See http://www.fsf.org\n\nNO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n$Date: 2005/08/30 08:58:42 $\nPearu Peterson\n\"\"\"\n\n__version__ = \"$Revision: 1.129 $\"[10:-1]\n\nimport __version__\nf2py_version = __version__.version\n\nimport pprint\nimport sys,string,time,types,copy\nerrmess=sys.stderr.write\noutmess=sys.stdout.write\nshow=pprint.pprint\n\nfrom auxfuncs import *\nimport capi_maps\nfrom capi_maps import *\nimport cfuncs\nimport common_rules\nimport use_rules\nimport f90mod_rules\nimport func2subr\noptions={}\n\nsepdict={}\n#for k in ['need_cfuncs']: sepdict[k]=','\nfor k in ['decl',\n 'frompyobj',\n 'cleanupfrompyobj',\n 'topyarr','method',\n 'pyobjfrom','closepyobjfrom',\n 'freemem',\n 'userincludes',\n 'includes0','includes','typedefs','typedefs_generated',\n 'cppmacros','cfuncs','callbacks',\n 'latexdoc',\n 'restdoc',\n 'routine_defs','externroutines',\n 'initf2pywraphooks',\n 'commonhooks','initcommonhooks',\n 'f90modhooks','initf90modhooks']:\n sepdict[k]='\\n'\n\n#################### Rules for C/API module #################\n\nmodule_rules={\n 'modulebody':\"\"\"\\\n/* File: #modulename#module.c\n * This file is auto-generated with f2py (version:#f2py_version#).\n * f2py is a Fortran to Python Interface Generator (FPIG), Second Edition,\n * written by Pearu Peterson .\n * See http://cens.ioc.ee/projects/f2py2e/\n * Generation date: \"\"\"+time.asctime(time.localtime(time.time()))+\"\"\"\n * $R\"\"\"+\"\"\"evision:$\n * $D\"\"\"+\"\"\"ate:$\n * Do not edit this file directly unless you know what you are doing!!!\n */\n#ifdef __cplusplus\nextern \\\"C\\\" {\n#endif\n\n\"\"\"+gentitle(\"See f2py2e/cfuncs.py: includes\")+\"\"\"\n#includes#\n#includes0#\n\n\"\"\"+gentitle(\"See f2py2e/rules.py: mod_rules['modulebody']\")+\"\"\"\nstatic PyObject *#modulename#_error;\nstatic PyObject *#modulename#_module;\n\n\"\"\"+gentitle(\"See f2py2e/cfuncs.py: typedefs\")+\"\"\"\n#typedefs#\n\n\"\"\"+gentitle(\"See f2py2e/cfuncs.py: typedefs_generated\")+\"\"\"\n#typedefs_generated#\n\n\"\"\"+gentitle(\"See f2py2e/cfuncs.py: cppmacros\")+\"\"\"\n#cppmacros#\n\n\"\"\"+gentitle(\"See f2py2e/cfuncs.py: cfuncs\")+\"\"\"\n#cfuncs#\n\n\"\"\"+gentitle(\"See f2py2e/cfuncs.py: userincludes\")+\"\"\"\n#userincludes#\n\n\"\"\"+gentitle(\"See f2py2e/capi_rules.py: usercode\")+\"\"\"\n#usercode#\n\n/* See f2py2e/rules.py */\n#externroutines#\n\n\"\"\"+gentitle(\"See f2py2e/capi_rules.py: usercode1\")+\"\"\"\n#usercode1#\n\n\"\"\"+gentitle(\"See f2py2e/cb_rules.py: buildcallback\")+\"\"\"\n#callbacks#\n\n\"\"\"+gentitle(\"See f2py2e/rules.py: buildapi\")+\"\"\"\n#body#\n\n\"\"\"+gentitle(\"See f2py2e/f90mod_rules.py: buildhooks\")+\"\"\"\n#f90modhooks#\n\n\"\"\"+gentitle(\"See f2py2e/rules.py: module_rules['modulebody']\")+\"\"\"\n\n\"\"\"+gentitle(\"See f2py2e/common_rules.py: buildhooks\")+\"\"\"\n#commonhooks#\n\n\"\"\"+gentitle(\"See f2py2e/rules.py\")+\"\"\"\n\nstatic char doc_f2py_has_column_major_storage[] = \\\"\\\\\nFunction has_column_major_storage(obj):\\\\n\\\\\n Return transpose(obj).iscontiguous().\\\\n\\\";\nstatic PyObject *f2py_has_column_major_storage(PyObject *self,PyObject *args) {\n PyObject * obj = NULL;\n if (!PyArg_ParseTuple(args, \\\"O\\\",&obj))\n return NULL;\n return Py_BuildValue(\\\"i\\\",(PyArray_Check(obj)? array_has_column_major_storage((PyArrayObject*)(obj)):0));\n}\n\nstatic char doc_f2py_as_column_major_storage[] = \\\"\\\\\nFunction as_column_major_storage(arr):\\\\n\\\\\n Return array in column major data storage order.\\\\n\\\";\nstatic PyObject *f2py_as_column_major_storage(PyObject *self,PyObject *args) {\n PyObject * obj = NULL;\n PyArrayObject * arr = NULL;\n if (!PyArg_ParseTuple(args, \\\"O\\\",&obj))\n return NULL;\n if (!PyArray_Check(obj)) {\n PyErr_SetString(#modulename#_error,\\\"expected array object\\\\n\\\");\n return NULL;\n }\n arr = (PyArrayObject*)obj;\n arr = array_from_pyobj(arr->descr->type_num, arr->dimensions, arr->nd,\n F2PY_INTENT_OUT|F2PY_INTENT_IN, obj);\n if (arr == NULL) {\n if (!PyErr_Occurred())\n PyErr_SetString(#modulename#_error,\n \\\"failed in converting argument to C/Fortran array\\\");\n return NULL;\n }\n return Py_BuildValue(\\\"N\\\",arr);\n}\n\nstatic FortranDataDef f2py_routine_defs[] = {\n#routine_defs#\n\\t{NULL}\n};\n\nstatic PyMethodDef f2py_module_methods[] = {\n#pymethoddef#\n\\t{\\\"has_column_major_storage\\\",f2py_has_column_major_storage,METH_VARARGS,doc_f2py_has_column_major_storage},\n\\t{\\\"as_column_major_storage\\\",f2py_as_column_major_storage,METH_VARARGS,doc_f2py_as_column_major_storage},\n\\t{NULL,NULL}\n};\n\nDL_EXPORT(void) init#modulename#(void) {\n\\tint i;\n\\tPyObject *m,*d, *s;\n\\tm = #modulename#_module = Py_InitModule(\\\"#modulename#\\\", f2py_module_methods);\n\\tPyFortran_Type.ob_type = &PyType_Type;\n\\timport_array();\n\\tif (PyErr_Occurred())\n\\t\\tPy_FatalError(\\\"can't initialize module #modulename# (failed to import scipy.base)\\\");\n\\td = PyModule_GetDict(m);\n\\ts = PyString_FromString(\\\"$R\"\"\"+\"\"\"evision: $\\\");\n\\tPyDict_SetItemString(d, \\\"__version__\\\", s);\n\\ts = PyString_FromString(\\\"This module '#modulename#' is auto-generated with f2py (version:#f2py_version#).\\\\nFunctions:\\\\n\\\"\\n#docs#\\\".\\\");\n\\tPyDict_SetItemString(d, \\\"__doc__\\\", s);\n\\t#modulename#_error = PyErr_NewException (\\\"#modulename#.error\\\", NULL, NULL);\n\\tPy_DECREF(s);\n\\tfor(i=0;f2py_routine_defs[i].name!=NULL;i++)\n\\t\\tPyDict_SetItemString(d, f2py_routine_defs[i].name,PyFortranObject_NewAsAttr(&f2py_routine_defs[i]));\n#initf2pywraphooks#\n#initf90modhooks#\n#initcommonhooks#\n#interface_usercode#\n\\tif (PyErr_Occurred())\n\\t\\tPy_FatalError(\\\"can't initialize module #modulename#\\\");\n\n#ifdef F2PY_REPORT_ATEXIT\n\\ton_exit(f2py_report_on_exit,(void*)\\\"#modulename#\\\");\n#endif\n\n}\n#ifdef __cplusplus\n}\n#endif\n\"\"\",\n 'separatorsfor':{'latexdoc':'\\n\\n',\n 'restdoc':'\\n\\n'},\n 'latexdoc':['\\\\section{Module \\\\texttt{#texmodulename#}}\\n',\n '#modnote#\\n',\n '#latexdoc#'],\n 'restdoc':['Module #modulename#\\n'+'='*80,\n '\\n#restdoc#']\n }\n\ndefmod_rules=[\n {'body':'/*eof body*/',\n 'method':'/*eof method*/',\n 'externroutines':'/*eof externroutines*/',\n 'routine_defs':'/*eof routine_defs*/',\n 'initf90modhooks':'/*eof initf90modhooks*/',\n 'initf2pywraphooks':'/*eof initf2pywraphooks*/',\n 'initcommonhooks':'/*eof initcommonhooks*/',\n 'latexdoc':'',\n 'restdoc':'',\n 'modnote':{hasnote:'#note#',l_not(hasnote):''},\n }\n ]\n\nroutine_rules={\n 'separatorsfor':sepdict,\n 'body':\"\"\"\n#begintitle#\nstatic char doc_#apiname#[] = \\\"\\\\\\nFunction signature:\\\\n\\\\\\n\\t#docreturn##name#(#docsignatureshort#)\\\\n\\\\\\n#docstrsigns#\\\";\n/* #declfortranroutine# */\nstatic PyObject *#apiname#(const PyObject *capi_self,\n PyObject *capi_args,\n PyObject *capi_keywds,\n #functype# (*f2py_func)(#callprotoargument#)) {\n\\tPyObject * volatile capi_buildvalue = NULL;\n\\tvolatile int f2py_success = 1;\n#decl#\n\\tstatic char *capi_kwlist[] = {#kwlist##kwlistopt##kwlistxa#NULL};\n#usercode#\n#routdebugenter#\n#ifdef F2PY_REPORT_ATEXIT\nf2py_start_clock();\n#endif\n\\tif (!PyArg_ParseTupleAndKeywords(capi_args,capi_keywds,\\\\\n\\t\\t\\\"#argformat#|#keyformat##xaformat#:#pyname#\\\",\\\\\n\\t\\tcapi_kwlist#args_capi##keys_capi##keys_xa#))\\n\\t\\treturn NULL;\n#frompyobj#\n/*end of frompyobj*/\n#ifdef F2PY_REPORT_ATEXIT\nf2py_start_call_clock();\n#endif\n#callfortranroutine#\nif (PyErr_Occurred())\n f2py_success = 0;\n#ifdef F2PY_REPORT_ATEXIT\nf2py_stop_call_clock();\n#endif\n/*end of callfortranroutine*/\n\\t\\tif (f2py_success) {\n#pyobjfrom#\n/*end of pyobjfrom*/\n\\t\\tCFUNCSMESS(\\\"Building return value.\\\\n\\\");\n\\t\\tcapi_buildvalue = Py_BuildValue(\\\"#returnformat#\\\"#return#);\n/*closepyobjfrom*/\n#closepyobjfrom#\n\\t\\t} /*if (f2py_success) after callfortranroutine*/\n/*cleanupfrompyobj*/\n#cleanupfrompyobj#\n\\tif (capi_buildvalue == NULL) {\n#routdebugfailure#\n\\t} else {\n#routdebugleave#\n\\t}\n\\tCFUNCSMESS(\\\"Freeing memory.\\\\n\\\");\n#freemem#\n#ifdef F2PY_REPORT_ATEXIT\nf2py_stop_clock();\n#endif\n\\treturn capi_buildvalue;\n}\n#endtitle#\n\"\"\",\n 'routine_defs':'#routine_def#',\n 'initf2pywraphooks':'#initf2pywraphook#',\n 'externroutines':'#declfortranroutine#',\n 'doc':'#docreturn##name#(#docsignature#)',\n 'docshort':'#docreturn##name#(#docsignatureshort#)',\n 'docs':'\"\\t#docreturn##name#(#docsignature#)\\\\n\"\\n',\n 'need':['arrayobject.h','CFUNCSMESS','MINMAX'],\n 'cppmacros':{debugcapi:'#define DEBUGCFUNCS'},\n 'latexdoc':['\\\\subsection{Wrapper function \\\\texttt{#texname#}}\\n',\n \"\"\"\n\\\\noindent{{}\\\\verb@#docreturn##name#@{}}\\\\texttt{(#latexdocsignatureshort#)}\n#routnote#\n\n#latexdocstrsigns#\n\"\"\"],\n 'restdoc':['Wrapped function ``#name#``\\n'+'-'*80,\n \n ]\n }\n\n################## Rules for C/API function ##############\n\nrout_rules=[\n { # Init\n 'separatorsfor': {'callfortranroutine':'\\n','routdebugenter':'\\n','decl':'\\n',\n 'routdebugleave':'\\n','routdebugfailure':'\\n',\n 'setjmpbuf':' || ',\n 'docstrreq':'\\n','docstropt':'\\n','docstrout':'\\n',\n 'docstrcbs':'\\n','docstrsigns':'\\\\n\"\\n\"',\n 'latexdocstrsigns':'\\n',\n 'latexdocstrreq':'\\n','latexdocstropt':'\\n',\n 'latexdocstrout':'\\n','latexdocstrcbs':'\\n',\n },\n 'kwlist':'','kwlistopt':'','callfortran':'','callfortranappend':'',\n 'docsign':'','docsignopt':'','decl':'/*decl*/',\n 'freemem':'/*freemem*/',\n 'docsignshort':'','docsignoptshort':'',\n 'docstrsigns':'','latexdocstrsigns':'',\n 'docstrreq':'Required arguments:',\n 'docstropt':'Optional arguments:',\n 'docstrout':'Return objects:',\n 'docstrcbs':'Call-back functions:',\n 'latexdocstrreq':'\\\\noindent Required arguments:',\n 'latexdocstropt':'\\\\noindent Optional arguments:',\n 'latexdocstrout':'\\\\noindent Return objects:',\n 'latexdocstrcbs':'\\\\noindent Call-back functions:',\n 'args_capi':'','keys_capi':'','functype':'',\n 'frompyobj':'/*frompyobj*/',\n 'cleanupfrompyobj':['/*end of cleanupfrompyobj*/'], #this list will be reversed\n 'pyobjfrom':'/*pyobjfrom*/',\n 'closepyobjfrom':['/*end of closepyobjfrom*/'], #this list will be reversed\n 'topyarr':'/*topyarr*/','routdebugleave':'/*routdebugleave*/',\n 'routdebugenter':'/*routdebugenter*/',\n 'routdebugfailure':'/*routdebugfailure*/',\n 'callfortranroutine':'/*callfortranroutine*/',\n 'argformat':'','keyformat':'','need_cfuncs':'',\n 'docreturn':'','return':'','returnformat':'','rformat':'',\n 'kwlistxa':'','keys_xa':'','xaformat':'','docsignxa':'','docsignxashort':'',\n 'initf2pywraphook':'',\n 'routnote':{hasnote:'--- #note#',l_not(hasnote):''},\n },{\n 'apiname':'f2py_rout_#modulename#_#name#',\n 'pyname':'#modulename#.#name#',\n 'decl':'',\n '_check':l_not(ismoduleroutine)\n },{\n 'apiname':'f2py_rout_#modulename#_#f90modulename#_#name#',\n 'pyname':'#modulename#.#f90modulename#.#name#',\n 'decl':'',\n '_check':ismoduleroutine\n },{ # Subroutine\n 'functype':'void',\n 'declfortranroutine':{l_and(l_not(l_or(ismoduleroutine,isintent_c)),l_not(isdummyroutine)):'extern void #F_FUNC#(#fortranname#,#FORTRANNAME#)(#callprotoargument#);',\n l_and(l_not(ismoduleroutine),isintent_c,l_not(isdummyroutine)):'extern void #fortranname#(#callprotoargument#);',\n ismoduleroutine:'',\n isdummyroutine:''\n },\n 'routine_def':{l_not(l_or(ismoduleroutine,isintent_c,isdummyroutine)):'\\t{\\\"#name#\\\",-1,{{-1}},0,(char *)#F_FUNC#(#fortranname#,#FORTRANNAME#),(f2py_init_func)#apiname#,doc_#apiname#},',\n l_and(l_not(ismoduleroutine),isintent_c,l_not(isdummyroutine)):'\\t{\\\"#name#\\\",-1,{{-1}},0,(char *)#fortranname#,(f2py_init_func)#apiname#,doc_#apiname#},',\n l_and(l_not(ismoduleroutine),isdummyroutine):'\\t{\\\"#name#\\\",-1,{{-1}},0,NULL,(f2py_init_func)#apiname#,doc_#apiname#},',\n },\n 'need':{l_and(l_not(l_or(ismoduleroutine,isintent_c)),l_not(isdummyroutine)):'F_FUNC'},\n 'callfortranroutine':[\n {debugcapi:[\"\"\"\\tfprintf(stderr,\\\"debug-capi:Fortran subroutine `#fortranname#(#callfortran#)\\'\\\\n\\\");\"\"\"]},\n {hasexternals:\"\"\"\\\n\\t\\tif (#setjmpbuf#) {\n\\t\\t\\tf2py_success = 0;\n\\t\\t} else {\"\"\"},\n {isthreadsafe:'\\t\\t\\tPy_BEGIN_ALLOW_THREADS'},\n {hascallstatement:'''\\t\\t\\t\\t#callstatement#;\n\\t\\t\\t\\t/*(*f2py_func)(#callfortran#);*/'''},\n {l_not(l_or(hascallstatement,isdummyroutine)):'\\t\\t\\t\\t(*f2py_func)(#callfortran#);'},\n {isthreadsafe:'\\t\\t\\tPy_END_ALLOW_THREADS'},\n {hasexternals:\"\"\"\\t\\t}\"\"\"}\n ],\n '_check':issubroutine,\n },{ # Wrapped function\n 'functype':'void',\n 'declfortranroutine':{l_not(l_or(ismoduleroutine,isdummyroutine)):'extern void #F_WRAPPEDFUNC#(#name_lower#,#NAME#)(#callprotoargument#);',\n isdummyroutine:'',\n },\n\n 'routine_def':{l_not(l_or(ismoduleroutine,isdummyroutine)):'\\t{\\\"#name#\\\",-1,{{-1}},0,(char *)#F_WRAPPEDFUNC#(#name_lower#,#NAME#),(f2py_init_func)#apiname#,doc_#apiname#},',\n isdummyroutine:'\\t{\\\"#name#\\\",-1,{{-1}},0,NULL,(f2py_init_func)#apiname#,doc_#apiname#},',\n },\n 'initf2pywraphook':{l_not(l_or(ismoduleroutine,isdummyroutine)):'''\n {\n extern #ctype# #F_FUNC#(#name_lower#,#NAME#)(void);\n PyObject* o = PyDict_GetItemString(d,\"#name#\");\n PyObject_SetAttrString(o,\"_cpointer\", PyCObject_FromVoidPtr((void*)#F_FUNC#(#name_lower#,#NAME#),NULL));\n }\n '''},\n 'need':{l_not(l_or(ismoduleroutine,isdummyroutine)):['F_WRAPPEDFUNC','F_FUNC']},\n 'callfortranroutine':[\n {debugcapi:[\"\"\"\\tfprintf(stderr,\\\"debug-capi:Fortran subroutine `f2pywrap#name_lower#(#callfortran#)\\'\\\\n\\\");\"\"\"]},\n {hasexternals:\"\"\"\\\n\\tif (#setjmpbuf#) {\n\\t\\tf2py_success = 0;\n\\t} else {\"\"\"},\n {isthreadsafe:'\\tPy_BEGIN_ALLOW_THREADS'},\n {l_not(l_or(hascallstatement,isdummyroutine)):'\\t(*f2py_func)(#callfortran#);'},\n {hascallstatement:'\\t#callstatement#;\\n\\t/*(*f2py_func)(#callfortran#);*/'},\n {isthreadsafe:'\\tPy_END_ALLOW_THREADS'},\n {hasexternals:'\\t}'}\n ],\n '_check':isfunction_wrap,\n },{ # Function\n 'functype':'#ctype#',\n 'docreturn':{l_not(isintent_hide):'#rname#,'},\n 'docstrout':'\\t#pydocsignout#',\n 'latexdocstrout':['\\\\item[]{{}\\\\verb@#pydocsignout#@{}}',\n {hasresultnote:'--- #resultnote#'}],\n 'callfortranroutine':[{l_and(debugcapi,isstringfunction):\"\"\"\\\n#ifdef USESCOMPAQFORTRAN\n\\tfprintf(stderr,\\\"debug-capi:Fortran function #ctype# #fortranname#(#callcompaqfortran#)\\\\n\\\");\n#else\n\\tfprintf(stderr,\\\"debug-capi:Fortran function #ctype# #fortranname#(#callfortran#)\\\\n\\\");\n#endif\n\"\"\"},\n {l_and(debugcapi,l_not(isstringfunction)):\"\"\"\\\n\\tfprintf(stderr,\\\"debug-capi:Fortran function #ctype# #fortranname#(#callfortran#)\\\\n\\\");\n\"\"\"}\n ],\n '_check':l_and(isfunction,l_not(isfunction_wrap))\n },{ # Scalar function\n 'declfortranroutine':{l_and(l_not(l_or(ismoduleroutine,isintent_c)),l_not(isdummyroutine)):'extern #ctype# #F_FUNC#(#fortranname#,#FORTRANNAME#)(#callprotoargument#);',\n l_and(l_not(ismoduleroutine),isintent_c,l_not(isdummyroutine)):'extern #ctype# #fortranname#(#callprotoargument#);',\n isdummyroutine:''\n },\n 'routine_def':{l_and(l_not(l_or(ismoduleroutine,isintent_c)),l_not(isdummyroutine)):'\\t{\\\"#name#\\\",-1,{{-1}},0,(char *)#F_FUNC#(#fortranname#,#FORTRANNAME#),(f2py_init_func)#apiname#,doc_#apiname#},',\n l_and(l_not(ismoduleroutine),isintent_c,l_not(isdummyroutine)):'\\t{\\\"#name#\\\",-1,{{-1}},0,(char *)#fortranname#,(f2py_init_func)#apiname#,doc_#apiname#},',\n isdummyroutine:'\\t{\\\"#name#\\\",-1,{{-1}},0,NULL,(f2py_init_func)#apiname#,doc_#apiname#},',\n },\n 'decl':[{iscomplexfunction_warn:'\\t#ctype# #name#_return_value={0,0};',\n l_not(iscomplexfunction):'\\t#ctype# #name#_return_value=0;'},\n {iscomplexfunction:'\\tPyObject *#name#_return_value_capi = Py_None;'}\n ],\n 'callfortranroutine':[\n {hasexternals:\"\"\"\\\n\\tif (#setjmpbuf#) {\n\\t\\tf2py_success = 0;\n\\t} else {\"\"\"},\n {isthreadsafe:'\\tPy_BEGIN_ALLOW_THREADS'},\n {hascallstatement:'''\\t#callstatement#;\n/*\\t#name#_return_value = (*f2py_func)(#callfortran#);*/\n'''},\n {l_not(l_or(hascallstatement,isdummyroutine)):'\\t#name#_return_value = (*f2py_func)(#callfortran#);'},\n {isthreadsafe:'\\tPy_END_ALLOW_THREADS'},\n {hasexternals:'\\t}'},\n {l_and(debugcapi,iscomplexfunction):'\\tfprintf(stderr,\"#routdebugshowvalue#\\\\n\",#name#_return_value.r,#name#_return_value.i);'},\n {l_and(debugcapi,l_not(iscomplexfunction)):'\\tfprintf(stderr,\"#routdebugshowvalue#\\\\n\",#name#_return_value);'}],\n 'pyobjfrom':{iscomplexfunction:'\\t#name#_return_value_capi = pyobj_from_#ctype#1(#name#_return_value);'},\n 'need':[{l_not(isdummyroutine):'F_FUNC'},\n {iscomplexfunction:'pyobj_from_#ctype#1'},\n {islong_longfunction:'long_long'},\n {islong_doublefunction:'long_double'}],\n 'returnformat':{l_not(isintent_hide):'#rformat#'},\n 'return':{iscomplexfunction:',#name#_return_value_capi',\n l_not(l_or(iscomplexfunction,isintent_hide)):',#name#_return_value'},\n '_check':l_and(isfunction,l_not(isstringfunction),l_not(isfunction_wrap))\n },{ # String function # in use for --no-wrap\n 'declfortranroutine':'extern void #F_FUNC#(#fortranname#,#FORTRANNAME#)(#callprotoargument#);',\n 'routine_def':{l_not(l_or(ismoduleroutine,isintent_c)):\n# '\\t{\\\"#name#\\\",-1,{{-1}},0,(char *)F_FUNC(#fortranname#,#FORTRANNAME#),(void *)#apiname#,doc_#apiname#},',\n '\\t{\\\"#name#\\\",-1,{{-1}},0,(char *)#F_FUNC#(#fortranname#,#FORTRANNAME#),(f2py_init_func)#apiname#,doc_#apiname#},',\n l_and(l_not(ismoduleroutine),isintent_c):\n# '\\t{\\\"#name#\\\",-1,{{-1}},0,(char *)#fortranname#,(void *)#apiname#,doc_#apiname#},'\n '\\t{\\\"#name#\\\",-1,{{-1}},0,(char *)#fortranname#,(f2py_init_func)#apiname#,doc_#apiname#},'\n },\n 'decl':['\\t#ctype# #name#_return_value = NULL;',\n '\\tint #name#_return_value_len = 0;'],\n 'callfortran':'#name#_return_value,#name#_return_value_len,',\n 'callfortranroutine':['\\t#name#_return_value_len = #rlength#;',\n '\\tif ((#name#_return_value = (string)malloc(sizeof(char)*(#name#_return_value_len+1))) == NULL) {',\n '\\t\\tPyErr_SetString(PyExc_MemoryError, \\\"out of memory\\\");',\n '\\t\\tf2py_success = 0;',\n '\\t} else {',\n \"\\t\\t(#name#_return_value)[#name#_return_value_len] = '\\\\0';\",\n '\\t}',\n '\\tif (f2py_success) {',\n {hasexternals:\"\"\"\\\n\\t\\tif (#setjmpbuf#) {\n\\t\\t\\tf2py_success = 0;\n\\t\\t} else {\"\"\"},\n {isthreadsafe:'\\t\\tPy_BEGIN_ALLOW_THREADS'},\n \"\"\"\\\n#ifdef USESCOMPAQFORTRAN\n\\t\\t(*f2py_func)(#callcompaqfortran#);\n#else\n\\t\\t(*f2py_func)(#callfortran#);\n#endif\n\"\"\",\n {isthreadsafe:'\\t\\tPy_END_ALLOW_THREADS'},\n {hasexternals:'\\t\\t}'},\n {debugcapi:'\\t\\tfprintf(stderr,\"#routdebugshowvalue#\\\\n\",#name#_return_value_len,#name#_return_value);'},\n '\\t} /* if (f2py_success) after (string)malloc */',\n ],\n 'returnformat':'#rformat#',\n 'return':',#name#_return_value',\n 'freemem':'\\tSTRINGFREE(#name#_return_value);',\n 'need':['F_FUNC','#ctype#','STRINGFREE'],\n '_check':l_and(isstringfunction,l_not(isfunction_wrap)) # ???obsolete\n },\n { # Debugging\n 'routdebugenter':'\\tfprintf(stderr,\"debug-capi:Python C/API function #modulename#.#name#(#docsignature#)\\\\n\");',\n 'routdebugleave':'\\tfprintf(stderr,\"debug-capi:Python C/API function #modulename#.#name#: successful.\\\\n\");',\n 'routdebugfailure':'\\tfprintf(stderr,\"debug-capi:Python C/API function #modulename#.#name#: failure.\\\\n\");',\n '_check':debugcapi\n }\n ]\n\n################ Rules for arguments ##################\n\ntypedef_need_dict = {islong_long:'long_long',\n islong_double:'long_double',\n islong_complex:'complex_long_double',\n isunsigned_char:'unsigned_char',\n isunsigned_short:'unsigned_short',\n isunsigned:'unsigned',\n isunsigned_long_long:'unsigned_long_long'}\n\naux_rules=[\n {\n 'separatorsfor':sepdict\n },\n { # Common\n 'frompyobj':['\\t/* Processing auxiliary variable #varname# */',\n {debugcapi:'\\tfprintf(stderr,\"#vardebuginfo#\\\\n\");'},],\n 'cleanupfrompyobj':'\\t/* End of cleaning variable #varname# */',\n 'need':typedef_need_dict,\n },\n# Scalars (not complex)\n { # Common\n 'decl':'\\t#ctype# #varname# = 0;',\n 'need':{hasinitvalue:'math.h'},\n 'frompyobj':{hasinitvalue:'\\t#varname# = #init#;'},\n '_check':l_and(isscalar,l_not(iscomplex)),\n },\n {\n 'return':',#varname#',\n 'docstrout':'\\t#pydocsignout#',\n 'docreturn':'#outvarname#,',\n 'returnformat':'#varrformat#',\n '_check':l_and(isscalar,l_not(iscomplex),isintent_out),\n },\n# Complex scalars\n { # Common\n 'decl':'\\t#ctype# #varname#;',\n 'frompyobj': {hasinitvalue:'\\t#varname#.r = #init.r#, #varname#.i = #init.i#;'},\n '_check':iscomplex\n },\n# String\n { # Common\n 'decl':['\\t#ctype# #varname# = NULL;',\n '\\tint slen(#varname#);',\n ],\n 'need':['len..'],\n '_check':isstring\n },\n# Array\n { # Common\n 'decl':['\\t#ctype# *#varname# = NULL;',\n '\\tintp #varname#_Dims[#rank#] = {#rank*[-1]#};',\n '\\tconst int #varname#_Rank = #rank#;',\n ],\n 'need':['len..',{hasinitvalue:'forcomb'},{hasinitvalue:'CFUNCSMESS'}],\n '_check':isarray\n },\n# Scalararray\n { # Common\n '_check':l_and(isarray,l_not(iscomplexarray))\n },{ # Not hidden\n '_check':l_and(isarray,l_not(iscomplexarray),isintent_nothide)\n },\n# Integer*1 array\n {'need':'#ctype#',\n '_check':isint1array,\n '_depend':''\n },\n# Integer*-1 array\n {'need':'#ctype#',\n '_check':isunsigned_chararray,\n '_depend':''\n },\n# Integer*-2 array\n {'need':'#ctype#',\n '_check':isunsigned_shortarray,\n '_depend':''\n },\n# Integer*-8 array\n {'need':'#ctype#',\n '_check':isunsigned_long_longarray,\n '_depend':''\n },\n# Complexarray\n {'need':'#ctype#',\n '_check':iscomplexarray,\n '_depend':''\n },\n# Stringarray\n {\n 'callfortranappend':{isarrayofstrings:'flen(#varname#),'},\n 'need':'string',\n '_check':isstringarray\n }\n ]\n\narg_rules=[\n {\n 'separatorsfor':sepdict\n },\n { # Common\n 'frompyobj':['\\t/* Processing variable #varname# */',\n {debugcapi:'\\tfprintf(stderr,\"#vardebuginfo#\\\\n\");'},],\n 'cleanupfrompyobj':'\\t/* End of cleaning variable #varname# */',\n '_depend':'',\n 'need':typedef_need_dict,\n },\n# Doc signatures\n {\n 'docstropt':{l_and(isoptional,isintent_nothide):'\\t#pydocsign#'},\n 'docstrreq':{l_and(isrequired,isintent_nothide):'\\t#pydocsign#'},\n 'docstrout':{isintent_out:'\\t#pydocsignout#'},\n 'latexdocstropt':{l_and(isoptional,isintent_nothide):['\\\\item[]{{}\\\\verb@#pydocsign#@{}}',\n {hasnote:'--- #note#'}]},\n 'latexdocstrreq':{l_and(isrequired,isintent_nothide):['\\\\item[]{{}\\\\verb@#pydocsign#@{}}',\n {hasnote:'--- #note#'}]},\n 'latexdocstrout':{isintent_out:['\\\\item[]{{}\\\\verb@#pydocsignout#@{}}',\n {l_and(hasnote,isintent_hide):'--- #note#',\n l_and(hasnote,isintent_nothide):'--- See above.'}]},\n 'depend':''\n },\n# Required/Optional arguments\n {\n 'kwlist':'\"#varname#\",',\n 'docsign':'#varname#,',\n '_check':l_and(isintent_nothide,l_not(isoptional))\n },\n {\n 'kwlistopt':'\"#varname#\",',\n 'docsignopt':'#varname#=#showinit#,',\n 'docsignoptshort':'#varname#,',\n '_check':l_and(isintent_nothide,isoptional)\n },\n# Docstring/BuildValue\n {\n 'docreturn':'#outvarname#,',\n 'returnformat':'#varrformat#',\n '_check':isintent_out\n },\n# Externals (call-back functions)\n { # Common\n 'docsignxa':{isintent_nothide:'#varname#_extra_args=(),'},\n 'docsignxashort':{isintent_nothide:'#varname#_extra_args,'},\n 'docstropt':{isintent_nothide:'\\t#varname#_extra_args := () input tuple'},\n 'docstrcbs':'#cbdocstr#',\n 'latexdocstrcbs':'\\\\item[] #cblatexdocstr#',\n 'latexdocstropt':{isintent_nothide:'\\\\item[]{{}\\\\verb@#varname#_extra_args := () input tuple@{}} --- Extra arguments for call-back function {{}\\\\verb@#varname#@{}}.'},\n 'decl':['\\tPyObject *#varname#_capi = Py_None;',\n '\\tPyTupleObject *#varname#_xa_capi = NULL;',\n '\\tPyTupleObject *#varname#_args_capi = NULL;',\n '\\tint #varname#_nofargs_capi = 0;',\n {l_not(isintent_callback):'\\t#cbname#_typedef #varname#_cptr;'}\n ],\n 'kwlistxa':{isintent_nothide:'\"#varname#_extra_args\",'},\n 'argformat':{isrequired:'O'},\n 'keyformat':{isoptional:'O'},\n 'xaformat':{isintent_nothide:'O!'},\n 'args_capi':{isrequired:',&#varname#_capi'},\n 'keys_capi':{isoptional:',&#varname#_capi'},\n 'keys_xa':',&PyTuple_Type,&#varname#_xa_capi',\n 'setjmpbuf':'(setjmp(#cbname#_jmpbuf))',\n 'callfortran':{l_not(isintent_callback):'#varname#_cptr,'},\n 'need':['#cbname#','setjmp.h'],\n '_check':isexternal\n },\n {\n 'frompyobj':[{l_not(isintent_callback):\"\"\"\\\nif(PyCObject_Check(#varname#_capi)) {\n #varname#_cptr = PyCObject_AsVoidPtr(#varname#_capi);\n} else {\n #varname#_cptr = #cbname#;\n}\n\"\"\"},{isintent_callback:\"\"\"\\\nif (#varname#_capi==Py_None) {\n #varname#_capi = PyObject_GetAttrString(#modulename#_module,\\\"#varname#\\\");\n if (#varname#_capi) {\n if (#varname#_xa_capi==NULL) {\n if (PyObject_HasAttrString(#modulename#_module,\\\"#varname#_extra_args\\\")) {\n PyObject* capi_tmp = PyObject_GetAttrString(#modulename#_module,\\\"#varname#_extra_args\\\");\n if (capi_tmp)\n #varname#_xa_capi = (PyTupleObject *)PySequence_Tuple(capi_tmp);\n else\n #varname#_xa_capi = (PyTupleObject *)Py_BuildValue(\\\"()\\\");\n if (#varname#_xa_capi==NULL) {\n PyErr_SetString(#modulename#_error,\\\"Failed to convert #modulename#.#varname#_extra_args to tuple.\\\\n\\\");\n return NULL;\n }\n }\n }\n }\n if (#varname#_capi==NULL) {\n PyErr_SetString(#modulename#_error,\\\"Callback #varname# not defined (as an argument or module #modulename# attribute).\\\\n\\\");\n return NULL;\n }\n}\n\"\"\"},\n## {l_not(isintent_callback):\"\"\"\\\n## if (#varname#_capi==Py_None) {\n## printf(\\\"hoi\\\\n\\\");\n## }\n## \"\"\"},\n\"\"\"\\\n\\t#varname#_nofargs_capi = #cbname#_nofargs;\n\\tif (create_cb_arglist(#varname#_capi,#varname#_xa_capi,#maxnofargs#,#nofoptargs#,&#cbname#_nofargs,&#varname#_args_capi,\\\"failed in processing argument list for call-back #varname#.\\\")) {\n\\t\\tjmp_buf #varname#_jmpbuf;\"\"\",\n{debugcapi:[\"\"\"\\\n\\t\\tfprintf(stderr,\\\"debug-capi:Assuming %d arguments; at most #maxnofargs#(-#nofoptargs#) is expected.\\\\n\\\",#cbname#_nofargs);\n\\t\\tCFUNCSMESSPY(\\\"for #varname#=\\\",#cbname#_capi);\"\"\",\n{l_not(isintent_callback):\"\"\"\\t\\tfprintf(stderr,\\\"#vardebugshowvalue# (call-back in C).\\\\n\\\",#cbname#);\"\"\"}]},\n \"\"\"\\\n\\t\\tCFUNCSMESS(\\\"Saving jmpbuf for `#varname#`.\\\\n\\\");\n\\t\\tSWAP(#varname#_capi,#cbname#_capi,PyObject);\n\\t\\tSWAP(#varname#_args_capi,#cbname#_args_capi,PyTupleObject);\n\\t\\tmemcpy(&#varname#_jmpbuf,&#cbname#_jmpbuf,sizeof(jmp_buf));\"\"\",\n ],\n'cleanupfrompyobj':\n\"\"\"\\\n\\t\\tCFUNCSMESS(\\\"Restoring jmpbuf for `#varname#`.\\\\n\\\");\n\\t\\t#cbname#_capi = #varname#_capi;\n\\t\\tPy_DECREF(#cbname#_args_capi);\n\\t\\t#cbname#_args_capi = #varname#_args_capi;\n\\t\\t#cbname#_nofargs = #varname#_nofargs_capi;\n\\t\\tmemcpy(&#cbname#_jmpbuf,&#varname#_jmpbuf,sizeof(jmp_buf));\n\\t}\"\"\",\n 'need':['SWAP','create_cb_arglist'],\n '_check':isexternal,\n '_depend':''\n },\n# Scalars (not complex)\n { # Common\n 'decl':'\\t#ctype# #varname# = 0;',\n 'pyobjfrom':{debugcapi:'\\tfprintf(stderr,\"#vardebugshowvalue#\\\\n\",#varname#);'},\n 'callfortran':{isintent_c:'#varname#,',l_not(isintent_c):'&#varname#,'},\n 'return':{isintent_out:',#varname#'},\n '_check':l_and(isscalar,l_not(iscomplex))\n },{\n 'need':{hasinitvalue:'math.h'},\n '_check':l_and(isscalar,l_not(iscomplex)),\n #'_depend':''\n },{ # Not hidden\n 'decl':'\\tPyObject *#varname#_capi = Py_None;',\n 'argformat':{isrequired:'O'},\n 'keyformat':{isoptional:'O'},\n 'args_capi':{isrequired:',&#varname#_capi'},\n 'keys_capi':{isoptional:',&#varname#_capi'},\n 'pyobjfrom':{isintent_inout:\"\"\"\\\n\\tf2py_success = try_pyarr_from_#ctype#(#varname#_capi,&#varname#);\n\\tif (f2py_success) {\"\"\"},\n 'closepyobjfrom':{isintent_inout:\"\\t} /*if (f2py_success) of #varname# pyobjfrom*/\"},\n 'need':{isintent_inout:'try_pyarr_from_#ctype#'},\n '_check':l_and(isscalar,l_not(iscomplex),isintent_nothide)\n },{\n 'frompyobj':[\n# hasinitvalue...\n# if pyobj is None:\n# varname = init\n# else\n# from_pyobj(varname)\n# \n# isoptional and noinitvalue...\n# if pyobj is not None:\n# from_pyobj(varname)\n# else:\n# varname is uninitialized\n#\n# ...\n# from_pyobj(varname)\n#\n {hasinitvalue:'\\tif (#varname#_capi == Py_None) #varname# = #init#; else',\n '_depend':''},\n {l_and(isoptional,l_not(hasinitvalue)):'\\tif (#varname#_capi != Py_None)',\n '_depend':''}, \n {l_not(islogical):'''\\\n\\t\\tf2py_success = #ctype#_from_pyobj(&#varname#,#varname#_capi,\"#pyname#() #nth# (#varname#) can\\'t be converted to #ctype#\");\n\\tif (f2py_success) {'''},\n {islogical:'''\\\n\\t\\t#varname# = (#ctype#)PyObject_IsTrue(#varname#_capi);\n\\t\\tf2py_success = 1;\n\\tif (f2py_success) {'''},\n ],\n 'cleanupfrompyobj':'\\t} /*if (f2py_success) of #varname#*/',\n 'need':{l_not(islogical):'#ctype#_from_pyobj'},\n '_check':l_and(isscalar,l_not(iscomplex),isintent_nothide),\n '_depend':''\n# },{ # Hidden\n# '_check':l_and(isscalar,l_not(iscomplex),isintent_hide)\n },{ # Hidden\n 'frompyobj':{hasinitvalue:'\\t#varname# = #init#;'},\n 'need':typedef_need_dict,\n '_check':l_and(isscalar,l_not(iscomplex),isintent_hide),\n '_depend':''\n },{ # Common\n 'frompyobj':{debugcapi:'\\tfprintf(stderr,\"#vardebugshowvalue#\\\\n\",#varname#);'},\n '_check':l_and(isscalar,l_not(iscomplex)),\n '_depend':''\n },\n# Complex scalars\n { # Common\n 'decl':'\\t#ctype# #varname#;',\n 'callfortran':{isintent_c:'#varname#,',l_not(isintent_c):'&#varname#,'},\n 'pyobjfrom':{debugcapi:'\\tfprintf(stderr,\"#vardebugshowvalue#\\\\n\",#varname#.r,#varname#.i);'},\n 'return':{isintent_out:',#varname#_capi'},\n '_check':iscomplex\n },{ # Not hidden\n 'decl':'\\tPyObject *#varname#_capi = Py_None;',\n 'argformat':{isrequired:'O'},\n 'keyformat':{isoptional:'O'},\n 'args_capi':{isrequired:',&#varname#_capi'},\n 'keys_capi':{isoptional:',&#varname#_capi'},\n 'need':{isintent_inout:'try_pyarr_from_#ctype#'},\n 'pyobjfrom':{isintent_inout:\"\"\"\\\n\\t\\tf2py_success = try_pyarr_from_#ctype#(#varname#_capi,&#varname#);\n\\t\\tif (f2py_success) {\"\"\"},\n 'closepyobjfrom':{isintent_inout:\"\\t\\t} /*if (f2py_success) of #varname# pyobjfrom*/\"},\n '_check':l_and(iscomplex,isintent_nothide)\n },{\n 'frompyobj':[{hasinitvalue:'\\tif (#varname#_capi==Py_None) {#varname#.r = #init.r#, #varname#.i = #init.i#;} else'},\n {l_and(isoptional,l_not(hasinitvalue)):'\\tif (#varname#_capi != Py_None)'},\n# '\\t\\tf2py_success = #ctype#_from_pyobj(&#varname#,#varname#_capi,\"#ctype#_from_pyobj failed in converting #nth# `#varname#\\' of #pyname# to C #ctype#\\\\n\");'\n '\\t\\tf2py_success = #ctype#_from_pyobj(&#varname#,#varname#_capi,\"#pyname#() #nth# (#varname#) can\\'t be converted to #ctype#\");'\n '\\n\\tif (f2py_success) {'],\n 'cleanupfrompyobj':'\\t} /*if (f2py_success) of #varname# frompyobj*/',\n 'need':['#ctype#_from_pyobj'],\n '_check':l_and(iscomplex,isintent_nothide),\n '_depend':''\n },{ # Hidden\n 'decl':{isintent_out:'\\tPyObject *#varname#_capi = Py_None;'},\n '_check':l_and(iscomplex,isintent_hide)\n },{\n 'frompyobj': {hasinitvalue:'\\t#varname#.r = #init.r#, #varname#.i = #init.i#;'},\n '_check':l_and(iscomplex,isintent_hide),\n '_depend':''\n },{ # Common\n 'pyobjfrom':{isintent_out:'\\t#varname#_capi = pyobj_from_#ctype#1(#varname#);'},\n 'need':['pyobj_from_#ctype#1'],\n '_check':iscomplex\n },{\n 'frompyobj':{debugcapi:'\\tfprintf(stderr,\"#vardebugshowvalue#\\\\n\",#varname#.r,#varname#.i);'},\n '_check':iscomplex,\n '_depend':''\n },\n# String\n { # Common\n 'decl':['\\t#ctype# #varname# = NULL;',\n '\\tint slen(#varname#);',\n '\\tPyObject *#varname#_capi = Py_None;'],\n 'callfortran':'#varname#,',\n 'callfortranappend':'slen(#varname#),',\n 'pyobjfrom':{debugcapi:'\\tfprintf(stderr,\"#vardebugshowvalue#\\\\n\",slen(#varname#),#varname#);'},\n# 'freemem':'\\tSTRINGFREE(#varname#);',\n 'return':{isintent_out:',#varname#'},\n 'need':['len..'],#'STRINGFREE'],\n '_check':isstring\n },{ # Common\n 'frompyobj':\"\"\"\\\n\\tslen(#varname#) = #length#;\n\\tf2py_success = #ctype#_from_pyobj(&#varname#,&slen(#varname#),#init#,#varname#_capi,\\\"#ctype#_from_pyobj failed in converting #nth# `#varname#\\' of #pyname# to C #ctype#\\\");\n\\tif (f2py_success) {\"\"\",\n 'cleanupfrompyobj':\"\"\"\\\n\\t\\tSTRINGFREE(#varname#);\n\\t} /*if (f2py_success) of #varname#*/\"\"\",\n 'need':['#ctype#_from_pyobj','len..','STRINGFREE'],\n '_check':isstring,\n '_depend':''\n },{ # Not hidden\n 'argformat':{isrequired:'O'},\n 'keyformat':{isoptional:'O'},\n 'args_capi':{isrequired:',&#varname#_capi'},\n 'keys_capi':{isoptional:',&#varname#_capi'},\n 'pyobjfrom':{isintent_inout:'''\\\n\\tf2py_success = try_pyarr_from_#ctype#(#varname#_capi,#varname#);\n\\tif (f2py_success) {'''},\n 'closepyobjfrom':{isintent_inout:'\\t} /*if (f2py_success) of #varname# pyobjfrom*/'},\n 'need':{isintent_inout:'try_pyarr_from_#ctype#'},\n '_check':l_and(isstring,isintent_nothide)\n },{ # Hidden\n '_check':l_and(isstring,isintent_hide)\n },{\n 'frompyobj':{debugcapi:'\\tfprintf(stderr,\"#vardebugshowvalue#\\\\n\",slen(#varname#),#varname#);'},\n '_check':isstring,\n '_depend':''\n },\n# Array\n { # Common\n 'decl':['\\t#ctype# *#varname# = NULL;',\n '\\tintp #varname#_Dims[#rank#] = {#rank*[-1]#};',\n '\\tconst int #varname#_Rank = #rank#;',\n '\\tPyArrayObject *capi_#varname#_tmp = NULL;',\n '\\tint capi_#varname#_intent = 0;',\n ],\n 'callfortran':'#varname#,',\n 'return':{isintent_out:',capi_#varname#_tmp'},\n 'need':'len..',\n '_check':isarray\n },{ # intent(overwrite) array\n 'decl':'\\tint capi_overwrite_#varname# = 1;',\n 'kwlistxa':'\"overwrite_#varname#\",',\n 'xaformat':'i',\n 'keys_xa':',&capi_overwrite_#varname#',\n 'docsignxa':'overwrite_#varname#=1,',\n 'docsignxashort':'overwrite_#varname#,',\n 'docstropt':'\\toverwrite_#varname# := 1 input int',\n '_check':l_and(isarray,isintent_overwrite),\n },{\n 'frompyobj':'\\tcapi_#varname#_intent |= (capi_overwrite_#varname#?0:F2PY_INTENT_COPY);',\n '_check':l_and(isarray,isintent_overwrite),\n '_depend':'',\n },\n { # intent(copy) array\n 'decl':'\\tint capi_overwrite_#varname# = 0;',\n 'kwlistxa':'\"overwrite_#varname#\",',\n 'xaformat':'i',\n 'keys_xa':',&capi_overwrite_#varname#',\n 'docsignxa':'overwrite_#varname#=0,',\n 'docsignxashort':'overwrite_#varname#,',\n 'docstropt':'\\toverwrite_#varname# := 0 input int',\n '_check':l_and(isarray,isintent_copy),\n },{\n 'frompyobj':'\\tcapi_#varname#_intent |= (capi_overwrite_#varname#?0:F2PY_INTENT_COPY);',\n '_check':l_and(isarray,isintent_copy),\n '_depend':'',\n },{ \n 'need':[{hasinitvalue:'forcomb'},{hasinitvalue:'CFUNCSMESS'}],\n '_check':isarray,\n '_depend':''\n },{ # Not hidden\n 'decl':'\\tPyObject *#varname#_capi = Py_None;',\n 'argformat':{isrequired:'O'},\n 'keyformat':{isoptional:'O'},\n 'args_capi':{isrequired:',&#varname#_capi'},\n 'keys_capi':{isoptional:',&#varname#_capi'},\n# 'pyobjfrom':{isintent_inout:\"\"\"\\\n# /* Partly because of the following hack, intent(inout) is depreciated,\n# Use intent(in,out) instead.\n \n# \\tif ((#varname#_capi != Py_None) && PyArray_Check(#varname#_capi) \\\\\n# \\t\\t&& (#varname#_capi != (PyObject *)capi_#varname#_tmp)) {\n# \\t\\tif (((PyArrayObject *)#varname#_capi)->nd != capi_#varname#_tmp->nd) {\n# \\t\\t\\tif (#varname#_capi != capi_#varname#_tmp->base)\n# \\t\\t\\t\\tcopy_ND_array((PyArrayObject *)capi_#varname#_tmp->base,(PyArrayObject *)#varname#_capi);\n# \\t\\t} else\n# \\t\\t\\tcopy_ND_array(capi_#varname#_tmp,(PyArrayObject *)#varname#_capi);\n# \\t}\n# */\n# \"\"\"},\n# 'need':{isintent_inout:'copy_ND_array'},\n '_check':l_and(isarray,isintent_nothide)\n },{\n 'frompyobj':['\\t#setdims#;',\n '\\tcapi_#varname#_intent |= #intent#;',\n {isintent_hide:'\\tcapi_#varname#_tmp = array_from_pyobj(#atype#,#varname#_Dims,#varname#_Rank,capi_#varname#_intent,Py_None);'},\n {isintent_nothide:'\\tcapi_#varname#_tmp = array_from_pyobj(#atype#,#varname#_Dims,#varname#_Rank,capi_#varname#_intent,#varname#_capi);'},\n \"\"\"\\\n\\tif (capi_#varname#_tmp == NULL) {\n\\t\\tif (!PyErr_Occurred())\n\\t\\t\\tPyErr_SetString(#modulename#_error,\\\"failed in converting #nth# `#varname#\\' of #pyname# to C/Fortran array\\\" );\n\\t} else {\n\\t\\t#varname# = (#ctype# *)(capi_#varname#_tmp->data);\n\"\"\",\n{hasinitvalue:[\n {isintent_nothide:'\\tif (#varname#_capi == Py_None) {'},\n {isintent_hide:'\\t{'},\n {iscomplexarray:'\\t\\t#ctype# capi_c;'},\n \"\"\"\\\n\\t\\tint *_i,capi_i=0;\n\\t\\tCFUNCSMESS(\\\"#name#: Initializing #varname#=#init#\\\\n\\\");\n\\t\\tif (initforcomb(capi_#varname#_tmp->dimensions,capi_#varname#_tmp->nd,1)) {\n\\t\\t\\twhile ((_i = nextforcomb()))\n\\t\\t\\t\\t#varname#[capi_i++] = #init#; /* fortran way */\n\\t\\t} else {\n\\t\\t\\tif (!PyErr_Occurred())\n\\t\\t\\t\\tPyErr_SetString(#modulename#_error,\\\"Initialization of #nth# #varname# failed (initforcomb).\\\");\n\\t\\t\\tf2py_success = 0;\n\\t\\t}\n\\t}\n\\tif (f2py_success) {\"\"\"]},\n ],\n 'cleanupfrompyobj':[ # note that this list will be reversed\n '\\t} /*if (capi_#varname#_tmp == NULL) ... else of #varname#*/',\n {l_not(l_or(isintent_out,isintent_hide)):\"\"\"\\\n\\tif((PyObject *)capi_#varname#_tmp!=#varname#_capi) {\n\\t\\tPy_XDECREF(capi_#varname#_tmp); }\"\"\"},\n {l_and(isintent_hide,l_not(isintent_out)):\"\"\"\\t\\tPy_XDECREF(capi_#varname#_tmp);\"\"\"},\n {hasinitvalue:'\\t} /*if (f2py_success) of #varname# init*/'},\n ],\n '_check':isarray,\n '_depend':''\n },\n# { # Hidden\n# 'freemem':{l_not(isintent_out):'\\tPy_XDECREF(capi_#varname#_tmp);'},\n# '_check':l_and(isarray,isintent_hide)\n# },\n# Scalararray\n { # Common\n '_check':l_and(isarray,l_not(iscomplexarray))\n },{ # Not hidden\n '_check':l_and(isarray,l_not(iscomplexarray),isintent_nothide)\n },\n# Integer*1 array\n {'need':'#ctype#',\n '_check':isint1array,\n '_depend':''\n },\n# Integer*-1 array\n {'need':'#ctype#',\n '_check':isunsigned_chararray,\n '_depend':''\n },\n# Integer*-2 array\n {'need':'#ctype#',\n '_check':isunsigned_shortarray,\n '_depend':''\n },\n# Integer*-8 array\n {'need':'#ctype#',\n '_check':isunsigned_long_longarray,\n '_depend':''\n },\n# Complexarray\n {'need':'#ctype#',\n '_check':iscomplexarray,\n '_depend':''\n },\n# Stringarray\n {\n 'callfortranappend':{isarrayofstrings:'flen(#varname#),'},\n 'need':'string',\n '_check':isstringarray\n }\n ]\n\n################# Rules for checking ###############\n\ncheck_rules=[\n {\n 'frompyobj':{debugcapi:'\\tfprintf(stderr,\\\"debug-capi:Checking `#check#\\'\\\\n\\\");'},\n 'need':'len..'\n },{\n 'frompyobj':'\\tCHECKSCALAR(#check#,\\\"#check#\\\",\\\"#nth# #varname#\\\",\\\"#varshowvalue#\\\",#varname#) {',\n 'cleanupfrompyobj':'\\t} /*CHECKSCALAR(#check#)*/',\n 'need':'CHECKSCALAR',\n '_check':l_and(isscalar,l_not(iscomplex)),\n '_break':''\n },{\n 'frompyobj':'\\tCHECKSTRING(#check#,\\\"#check#\\\",\\\"#nth# #varname#\\\",\\\"#varshowvalue#\\\",#varname#) {',\n 'cleanupfrompyobj':'\\t} /*CHECKSTRING(#check#)*/',\n 'need':'CHECKSTRING',\n '_check':isstring,\n '_break':''\n },{\n 'need':'CHECKARRAY',\n 'frompyobj':'\\tCHECKARRAY(#check#,\\\"#check#\\\",\\\"#nth# #varname#\\\") {',\n 'cleanupfrompyobj':'\\t} /*CHECKARRAY(#check#)*/',\n '_check':isarray,\n '_break':''\n },{\n 'need':'CHECKGENERIC',\n 'frompyobj':'\\tCHECKGENERIC(#check#,\\\"#check#\\\",\\\"#nth# #varname#\\\") {',\n 'cleanupfrompyobj':'\\t} /*CHECKGENERIC(#check#)*/',\n }\n]\n\n########## Applying the rules. No need to modify what follows #############\n\n#################### Build C/API module #######################\n\ndef buildmodule(m,um):\n \"\"\"\n Return \n \"\"\"\n global f2py_version,options\n outmess('\\tBuilding module \"%s\"...\\n'%(m['name']))\n ret = {}\n mod_rules=defmod_rules[:]\n vrd=modsign2map(m)\n rd=dictappend({'f2py_version':f2py_version},vrd)\n funcwrappers = []\n funcwrappers2 = [] # F90 codes\n for n in m['interfaced']:\n nb=None\n for bi in m['body']:\n if not bi['block']=='interface':\n errmess('buildmodule: Expected interface block. Skipping.\\n')\n continue\n for b in bi['body']:\n if b['name']==n: nb=b;break\n \n if not nb:\n errmess('buildmodule: Could not found the body of interfaced routine \"%s\". Skipping.\\n'%(n))\n continue\n nb_list = [nb]\n if nb.has_key('entry'):\n for k,a in nb['entry'].items():\n nb1 = copy.deepcopy(nb)\n del nb1['entry']\n nb1['name'] = k\n nb1['args'] = a\n nb_list.append(nb1)\n for nb in nb_list:\n api,wrap=buildapi(nb)\n if wrap:\n if ismoduleroutine(nb):\n funcwrappers2.append(wrap)\n else:\n funcwrappers.append(wrap)\n ar=applyrules(api,vrd)\n rd=dictappend(rd,ar)\n\n # Construct COMMON block support\n cr,wrap = common_rules.buildhooks(m)\n if wrap:\n funcwrappers.append(wrap)\n ar=applyrules(cr,vrd)\n rd=dictappend(rd,ar)\n\n # Construct F90 module support\n mr,wrap = f90mod_rules.buildhooks(m)\n if wrap:\n funcwrappers2.append(wrap)\n ar=applyrules(mr,vrd)\n rd=dictappend(rd,ar)\n\n for u in um:\n ar=use_rules.buildusevars(u,m['use'][u['name']])\n rd=dictappend(rd,ar)\n\n needs=cfuncs.get_needs()\n code={}\n for n in needs.keys():\n code[n]=[]\n for k in needs[n]:\n c=''\n if cfuncs.includes0.has_key(k): c=cfuncs.includes0[k]\n elif cfuncs.includes.has_key(k): c=cfuncs.includes[k]\n elif cfuncs.userincludes.has_key(k): c=cfuncs.userincludes[k]\n elif cfuncs.typedefs.has_key(k): c=cfuncs.typedefs[k]\n elif cfuncs.typedefs_generated.has_key(k):\n c=cfuncs.typedefs_generated[k]\n elif cfuncs.cppmacros.has_key(k): c=cfuncs.cppmacros[k]\n elif cfuncs.cfuncs.has_key(k): c=cfuncs.cfuncs[k]\n elif cfuncs.callbacks.has_key(k): c=cfuncs.callbacks[k]\n elif cfuncs.f90modhooks.has_key(k): c=cfuncs.f90modhooks[k]\n elif cfuncs.commonhooks.has_key(k): c=cfuncs.commonhooks[k]\n else: errmess('buildmodule: unknown need %s.\\n'%(`k`));continue\n code[n].append(c)\n mod_rules.append(code)\n for r in mod_rules:\n if (r.has_key('_check') and r['_check'](m)) or (not r.has_key('_check')):\n ar=applyrules(r,vrd,m)\n rd=dictappend(rd,ar)\n ar=applyrules(module_rules,rd)\n\n fn = os.path.join(options['buildpath'],vrd['modulename']+'module.c')\n ret['csrc'] = fn\n f=open(fn,'w')\n f.write(string.replace(ar['modulebody'],'\\t',2*' '))\n f.close()\n outmess('\\tWrote C/API module \"%s\" to file \"%s/%smodule.c\"\\n'%(m['name'],options['buildpath'],vrd['modulename']))\n\n if options['dorestdoc']:\n fn = os.path.join(options['buildpath'],vrd['modulename']+'module.rest')\n f=open(fn,'w')\n f.write('.. -*- rest -*-\\n')\n f.write(string.join(ar['restdoc'],'\\n'))\n f.close()\n outmess('\\tReST Documentation is saved to file \"%s/%smodule.rest\"\\n'%(options['buildpath'],vrd['modulename']))\n if options['dolatexdoc']:\n fn = os.path.join(options['buildpath'],vrd['modulename']+'module.tex')\n ret['ltx'] = fn\n f=open(fn,'w')\n f.write('%% This file is auto-generated with f2py (version:%s)\\n'%(f2py_version))\n if not options.has_key('shortlatex'):\n f.write('\\\\documentclass{article}\\n\\\\usepackage{a4wide}\\n\\\\begin{document}\\n\\\\tableofcontents\\n\\n')\n f.write(string.join(ar['latexdoc'],'\\n'))\n if not options.has_key('shortlatex'):\n f.write('\\\\end{document}')\n f.close()\n outmess('\\tDocumentation is saved to file \"%s/%smodule.tex\"\\n'%(options['buildpath'],vrd['modulename']))\n if funcwrappers:\n wn = os.path.join(options['buildpath'],'%s-f2pywrappers.f'%(vrd['modulename']))\n ret['fsrc'] = wn\n f=open(wn,'w')\n f.write('C -*- fortran -*-\\n')\n f.write('C This file is autogenerated with f2py (version:%s)\\n'%(f2py_version))\n f.write('C It contains Fortran 77 wrappers to fortran functions.\\n')\n lines = []\n for l in string.split(string.join(funcwrappers,'\\n\\n')+'\\n','\\n'):\n if l and l[0]==' ':\n while len(l)>=66:\n lines.append(l[:66]+'\\n &')\n l = l[66:]\n lines.append(l+'\\n')\n else: lines.append(l+'\\n')\n lines = string.join(lines,'').replace('\\n &\\n','\\n')\n f.write(lines)\n f.close()\n outmess('\\tFortran 77 wrappers are saved to \"%s\"\\n'%(wn))\n if funcwrappers2:\n wn = os.path.join(options['buildpath'],'%s-f2pywrappers2.f90'%(vrd['modulename']))\n ret['fsrc'] = wn\n f=open(wn,'w')\n f.write('! -*- f90 -*-\\n')\n f.write('! This file is autogenerated with f2py (version:%s)\\n'%(f2py_version))\n f.write('! It contains Fortran 90 wrappers to fortran functions.\\n')\n lines = []\n for l in string.split(string.join(funcwrappers2,'\\n\\n')+'\\n','\\n'):\n if len(l)>72 and l[0]==' ':\n lines.append(l[:72]+'&\\n &')\n l = l[72:]\n while len(l)>66:\n lines.append(l[:66]+'&\\n &')\n l = l[66:]\n lines.append(l+'\\n')\n else: lines.append(l+'\\n')\n lines = string.join(lines,'').replace('\\n &\\n','\\n')\n f.write(lines)\n f.close()\n outmess('\\tFortran 90 wrappers are saved to \"%s\"\\n'%(wn))\n return ret\n\n################## Build C/API function #############\n\nstnd={1:'st',2:'nd',3:'rd',4:'th',5:'th',6:'th',7:'th',8:'th',9:'th',0:'th'}\ndef buildapi(rout):\n rout,wrap = func2subr.assubr(rout)\n args,depargs=getargs2(rout)\n capi_maps.depargs=depargs\n var=rout['vars']\n auxvars = [a for a in var.keys() if isintent_aux(var[a])]\n \n if ismoduleroutine(rout):\n outmess('\\t\\t\\tConstructing wrapper function \"%s.%s\"...\\n'%(rout['modulename'],rout['name']))\n else:\n outmess('\\t\\tConstructing wrapper function \"%s\"...\\n'%(rout['name']))\n # Routine\n vrd=routsign2map(rout)\n rd=dictappend({},vrd)\n for r in rout_rules:\n if (r.has_key('_check') and r['_check'](rout)) or (not r.has_key('_check')):\n ar=applyrules(r,vrd,rout)\n rd=dictappend(rd,ar)\n\n # Args\n nth,nthk=0,0\n savevrd={}\n for a in args:\n vrd=sign2map(a,var[a])\n if isintent_aux(var[a]):\n _rules = aux_rules\n else:\n _rules = arg_rules\n if not isintent_hide(var[a]):\n if not isoptional(var[a]):\n nth=nth+1\n vrd['nth']=`nth`+stnd[nth%10]+' argument'\n else:\n nthk=nthk+1\n vrd['nth']=`nthk`+stnd[nthk%10]+' keyword'\n else: vrd['nth']='hidden' \n savevrd[a]=vrd\n for r in _rules:\n if r.has_key('_depend'): continue\n if (r.has_key('_check') and r['_check'](var[a])) or (not r.has_key('_check')):\n ar=applyrules(r,vrd,var[a])\n rd=dictappend(rd,ar)\n if r.has_key('_break'): break\n for a in depargs:\n if isintent_aux(var[a]):\n _rules = aux_rules\n else:\n _rules = arg_rules\n vrd=savevrd[a]\n for r in _rules:\n if not r.has_key('_depend'): continue\n if (r.has_key('_check') and r['_check'](var[a])) or (not r.has_key('_check')):\n ar=applyrules(r,vrd,var[a])\n rd=dictappend(rd,ar)\n if r.has_key('_break'): break\n if var[a].has_key('check'):\n for c in var[a]['check']:\n vrd['check']=c\n ar=applyrules(check_rules,vrd,var[a])\n rd=dictappend(rd,ar)\n if type(rd['cleanupfrompyobj']) is types.ListType:\n rd['cleanupfrompyobj'].reverse()\n if type(rd['closepyobjfrom']) is types.ListType:\n rd['closepyobjfrom'].reverse()\n rd['docsignature']=stripcomma(replace('#docsign##docsignopt##docsignxa#',\n {'docsign':rd['docsign'],\n 'docsignopt':rd['docsignopt'],\n 'docsignxa':rd['docsignxa']}))\n optargs=stripcomma(replace('#docsignopt##docsignxa#',\n {'docsignxa':rd['docsignxashort'],\n 'docsignopt':rd['docsignoptshort']}\n ))\n if optargs=='':\n rd['docsignatureshort']=stripcomma(replace('#docsign#',{'docsign':rd['docsign']}))\n else:\n rd['docsignatureshort']=replace('#docsign#[#docsignopt#]',\n {'docsign':rd['docsign'],\n 'docsignopt':optargs,\n })\n rd['latexdocsignatureshort']=string.replace(rd['docsignatureshort'],'_','\\\\_')\n rd['latexdocsignatureshort']=string.replace(rd['latexdocsignatureshort'],',',', ')\n cfs=stripcomma(replace('#callfortran##callfortranappend#',{'callfortran':rd['callfortran'],'callfortranappend':rd['callfortranappend']}))\n if len(rd['callfortranappend'])>1:\n rd['callcompaqfortran']=stripcomma(replace('#callfortran# 0,#callfortranappend#',{'callfortran':rd['callfortran'],'callfortranappend':rd['callfortranappend']}))\n else:\n rd['callcompaqfortran']=cfs\n rd['callfortran']=cfs\n if type(rd['docreturn'])==types.ListType:\n rd['docreturn']=stripcomma(replace('#docreturn#',{'docreturn':rd['docreturn']}))+' = '\n rd['docstrsigns']=[]\n rd['latexdocstrsigns']=[]\n for k in ['docstrreq','docstropt','docstrout','docstrcbs']:\n if rd.has_key(k) and type(rd[k])==types.ListType:\n rd['docstrsigns']=rd['docstrsigns']+rd[k]\n k='latex'+k\n if rd.has_key(k) and type(rd[k])==types.ListType:\n rd['latexdocstrsigns']=rd['latexdocstrsigns']+rd[k][0:1]+\\\n ['\\\\begin{description}']+rd[k][1:]+\\\n ['\\\\end{description}']\n ar=applyrules(routine_rules,rd)\n if ismoduleroutine(rout):\n outmess('\\t\\t\\t %s\\n'%(ar['docshort']))\n else:\n outmess('\\t\\t %s\\n'%(ar['docshort']))\n return ar,wrap\n\n\n#################### EOF rules.py #######################\n", "methods": [ { "name": "buildmodule", "long_name": "buildmodule( m , um )", "filename": "rules.py", "nloc": 141, "complexity": 45, "token_count": 1298, "parameters": [ "m", "um" ], "start_line": 1081, "end_line": 1233, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 153, "top_nesting_level": 0 }, { "name": "buildapi", "long_name": "buildapi( rout )", "filename": "rules.py", "nloc": 101, "complexity": 39, "token_count": 977, "parameters": [ "rout" ], "start_line": 1238, "end_line": 1342, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 105, "top_nesting_level": 0 } ], "methods_before": [ { "name": "buildmodule", "long_name": "buildmodule( m , um )", "filename": "rules.py", "nloc": 141, "complexity": 45, "token_count": 1298, "parameters": [ "m", "um" ], "start_line": 1117, "end_line": 1269, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 153, "top_nesting_level": 0 }, { "name": "buildapi", "long_name": "buildapi( rout )", "filename": "rules.py", "nloc": 101, "complexity": 39, "token_count": 977, "parameters": [ "rout" ], "start_line": 1274, "end_line": 1378, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 105, "top_nesting_level": 0 } ], "changed_methods": [], "nloc": 1221, "complexity": 84, "token_count": 5900, "diff_parsed": { "added": [], "deleted": [ "static char doc_f2py_has_column_major_storage[] = \\\"\\\\", "Function has_column_major_storage(obj):\\\\n\\\\", " Return transpose(obj).iscontiguous().\\\\n\\\";", "static PyObject *f2py_has_column_major_storage(PyObject *self,PyObject *args) {", " PyObject * obj = NULL;", " if (!PyArg_ParseTuple(args, \\\"O\\\",&obj))", " return NULL;", " return Py_BuildValue(\\\"i\\\",(PyArray_Check(obj)? array_has_column_major_storage((PyArrayObject*)(obj)):0));", "}", "", "static char doc_f2py_as_column_major_storage[] = \\\"\\\\", "Function as_column_major_storage(arr):\\\\n\\\\", " Return array in column major data storage order.\\\\n\\\";", "static PyObject *f2py_as_column_major_storage(PyObject *self,PyObject *args) {", " PyObject * obj = NULL;", " PyArrayObject * arr = NULL;", " if (!PyArg_ParseTuple(args, \\\"O\\\",&obj))", " return NULL;", " if (!PyArray_Check(obj)) {", " PyErr_SetString(#modulename#_error,\\\"expected array object\\\\n\\\");", " return NULL;", " }", " arr = (PyArrayObject*)obj;", " arr = array_from_pyobj(arr->descr->type_num, arr->dimensions, arr->nd,", " F2PY_INTENT_OUT|F2PY_INTENT_IN, obj);", " if (arr == NULL) {", " if (!PyErr_Occurred())", " PyErr_SetString(#modulename#_error,", " \\\"failed in converting argument to C/Fortran array\\\");", " return NULL;", " }", " return Py_BuildValue(\\\"N\\\",arr);", "}", "", "\\t{\\\"has_column_major_storage\\\",f2py_has_column_major_storage,METH_VARARGS,doc_f2py_has_column_major_storage},", "\\t{\\\"as_column_major_storage\\\",f2py_as_column_major_storage,METH_VARARGS,doc_f2py_as_column_major_storage}," ] } }, { "old_path": "scipy/f2py2e/src/fortranobject.c", "new_path": "scipy/f2py2e/src/fortranobject.c", "filename": "fortranobject.c", "extension": "c", "change_type": "MODIFY", "diff": "@@ -5,9 +5,7 @@\n extern \"C\" {\n #endif\n /*\n- This file implements: FortranObject, array_from_pyobj, copy_ND_array,\n- lazy_transpose, transpose_strides,\n-\t\t and array_has_column_major_storage.\n+ This file implements: FortranObject, array_from_pyobj, copy_ND_array\n \n Author: Pearu Peterson \n $Revision: 1.52 $\n@@ -386,52 +384,24 @@ void f2py_report_on_exit(int exit_flag,void *name) {\n /********************** report on array copy ****************************/\n \n #ifdef F2PY_REPORT_ON_ARRAY_COPY\n-static void f2py_report_on_array_copy(PyArrayObject* arr, char* func_name) {\n+static void f2py_report_on_array_copy(PyArrayObject* arr) {\n const long arr_size = PyArray_Size((PyObject *)arr);\n if (arr_size>F2PY_REPORT_ON_ARRAY_COPY) {\n- fprintf(stderr,\"copied an array using %s: size=%ld, elsize=%d\\n\", \n-\t func_name, arr_size, PyArray_ITEMSIZE(arr));\n+ fprintf(stderr,\"copied an array: size=%ld, elsize=%d\\n\", \n+\t arr_size, PyArray_ITEMSIZE(arr));\n }\n }\n-#endif\n-\n-/************************* lazy_transpose *******************************/\n-\n-extern\n-void lazy_transpose(PyArrayObject* arr) {\n- /*\n- Changes the order of array strides and dimensions. This\n- corresponds to the lazy transpose of a Numeric array in-situ.\n- Note that this function is assumed to be used even times for a\n- given array. Otherwise, the caller should set flags &= ~CONTIGUOUS.\n- */\n- int rank, i;\n- intp s,j; \n- rank = arr->nd; \n- if (rank < 2) return;\n-\n- for(i=0,j=rank-1;istrides[i];\n- arr->strides[i] = arr->strides[j];\n- arr->strides[j] = s;\n- s = arr->dimensions[i];\n- arr->dimensions[i] = arr->dimensions[j];\n- arr->dimensions[j] = s;\n- }\n+static void f2py_report_on_array_copy_fromany(void) {\n+ fprintf(stderr,\"created an array from object\\n\");\n }\n \n-extern\n-void transpose_strides(PyArrayObject* arr) {\n- int rank, i;\n- intp j;\n- rank = arr->nd; \n- if (rank < 2) return;\n- j = arr->strides[rank-1];\n- for(i=0;istrides[i] = j;\n- j *= arr->dimensions[i];\n- }\n-}\n+#define F2PY_REPORT_ON_ARRAY_COPY_FROMARR f2py_report_on_array_copy((PyArrayObject *)arr)\n+#define F2PY_REPORT_ON_ARRAY_COPY_FROMANY f2py_report_on_array_copy_fromany()\n+#else\n+#define F2PY_REPORT_ON_ARRAY_COPY_FROMARR\n+#define F2PY_REPORT_ON_ARRAY_COPY_FROMANY\n+#endif\n+\n \n /************************* array_from_obj *******************************/\n \n@@ -454,25 +424,6 @@ void transpose_strides(PyArrayObject* arr) {\n * $Id: fortranobject.c,v 1.52 2005/07/11 07:44:20 pearu Exp $\n */\n \n-\n-#define ARR_IS_NULL(arr_is_NULL,mess) \\\n-if (arr_is_NULL) { \\\n- fprintf(stderr,\"array_from_pyobj:\" mess); \\\n- return NULL; \\\n-}\n-\n-#define CHECK_DIMS_DEFINED(rank,dims,mess) \\\n-if (count_nonpos(rank,dims)) { int i;\\\n- fprintf(stderr,\"array_from_pyobj:\" mess); \\\n- fprintf(stderr,\"rank=%d dimensions=[ \",rank); \\\n- for(i=0;ielsize) == PyArray_ITEMSIZE(arr))\n-\n static int \n count_nonpos(const int rank,\n \t const intp *dims) {\n@@ -522,21 +473,6 @@ static int swap_arrays(PyArrayObject* arr1, PyArrayObject* arr2) {\n return 0;\n }\n \n-\t/* useful after a lazy-transpose to update the flags\n-\t quickly \n-\t*/\n-\n-#define _lazy_transpose_update_flags(obj) {\t\t \\\n-\t\tif (PyArray_ISCONTIGUOUS(obj)) {\t \\\n-\t\t\tPyArray_FLAGS(obj) &= ~CONTIGUOUS; \\\n-\t\t\tPyArray_FLAGS(obj) |= FORTRAN; \\\n-\t\t}\t\t\t\t\t \\\n-\t\telse if PyArray_CHKFLAGS(obj, FORTRAN) { \\\n-\t\t\tPyArray_FLAGS(obj) &= ~FORTRAN; \\\n-\t\t\tPyArray_FLAGS(obj) |= CONTIGUOUS; \\\n-\t\t}\t\t\t\t\t \\\n-\t}\n-\n extern\n PyArrayObject* array_from_pyobj(const int type_num,\n \t\t\t\tintp *dims,\n@@ -548,85 +484,122 @@ PyArrayObject* array_from_pyobj(const int type_num,\n If the caller returns the array to Python, it must be done with\n Py_BuildValue(\"N\",arr).\n Otherwise, if obj!=arr then the caller must call Py_DECREF(arr).\n- */\n \n- if (intent & F2PY_INTENT_CACHE) {\n- /* Don't expect correct storage order or anything reasonable when\n- returning intent(cache) array. */ \n- if ((intent & F2PY_INTENT_HIDE)\n-\t|| (obj==Py_None)) {\n- PyArrayObject *arr = NULL;\n- CHECK_DIMS_DEFINED(rank,dims,\"optional,intent(cache) must\"\n-\t\t\t \" have defined dimensions.\\n\");\n- arr = (PyArrayObject *)PyArray_SimpleNew(rank,dims,type_num);\n- ARR_IS_NULL(arr==NULL,\"PyArray_SimpleNew failed: optional,intent(cache)\\n\");\n- return arr;\n- }\n- if (PyArray_Check(obj) \n-\t&& PyArray_ISONESEGMENT(obj)\n-\t&& HAS_PROPER_ELSIZE((PyArrayObject *)obj,type_num)\n-\t) {\n- if (check_and_fix_dimensions((PyArrayObject *)obj,rank,dims))\n-\treturn NULL; /*XXX: set exception */\n- {\n-\tif (intent & F2PY_INTENT_OUT)\n-\t Py_INCREF(obj);\n-\treturn (PyArrayObject *)obj;\n- }\n- }\n- ARR_IS_NULL(1,\"intent(cache) must be contiguous array with a proper elsize.\\n\");\n- }\n+ Note on intent(cache,out,..)\n+ ---------------------\n+ Don't expect correct data when returning intent(cache) array.\n \n- if (intent & F2PY_INTENT_HIDE) {\n- PyArrayObject *arr = NULL;\n- CHECK_DIMS_DEFINED(rank,dims,\"intent(hide) must have defined dimensions.\\n\");\n+ */\n+ char mess[200];\n+ PyArrayObject *arr = NULL;\n+ PyArray_Descr *descr = PyArray_DescrFromType(type_num);\n+\n+ if ((intent & F2PY_INTENT_HIDE)\n+ || ((intent & F2PY_INTENT_CACHE) && (obj==Py_None))\n+ || ((intent & F2PY_OPTIONAL) && (obj==Py_None))\n+ ) {\n+ /* intent(cache), optional, intent(hide) */\n+ if (count_nonpos(rank,dims)) {\n+ int i;\n+ sprintf(mess,\"failed to create intent(cache|hide)|optional array\"\n+\t \"-- must have defined dimensions but got (\");\n+ for(i=0;i=descr->elsize) {\n+\tif (check_and_fix_dimensions((PyArrayObject *)obj,rank,dims))\n+\t return NULL; /*XXX: set exception */\n+\tif (intent & F2PY_INTENT_OUT)\n+\t Py_INCREF(obj);\n+\treturn (PyArrayObject *)obj;\n+ }\n+ sprintf(mess,\"failed to initialize intent(cache) array\");\n+ if (!PyArray_ISONESEGMENT(obj))\n+\tsprintf(mess+strlen(mess),\" -- input must be in one segment\");\n+ if (PyArray_ITEMSIZE(arr)elsize)\n+\tsprintf(mess+strlen(mess),\" -- expected at least elsize=%d but got %d\",\n+\t\tdescr->elsize,PyArray_ITEMSIZE(arr)\n+\t\t);\n+ PyErr_SetString(PyExc_ValueError,mess);\n+ return NULL;\n+ }\n+\n+ /* here we have always intent(in) or intent(inout) or intent(inplace) */\n \n if (check_and_fix_dimensions(arr,rank,dims))\n return NULL; /*XXX: set exception */\n \n if ((! (intent & F2PY_INTENT_COPY))\n-\t&& HAS_PROPER_ELSIZE(arr,type_num)\n+\t&& PyArray_ITEMSIZE(arr)==descr->elsize\n \t&& PyArray_CanCastSafely(arr->descr->type_num,type_num)\n \t) {\n if ((intent & F2PY_INTENT_C)?PyArray_ISCARRAY(arr):PyArray_ISFARRAY(arr)) {\n \tif ((intent & F2PY_INTENT_OUT)) {\n \t Py_INCREF(arr);\n \t}\n+\t/* Returning input array */\n \treturn arr;\n }\n }\n \n+ if (intent & F2PY_INTENT_INOUT) {\n+ sprintf(mess,\"failed to initialize intent(inout) array\");\n+ if ((intent & F2PY_INTENT_C) && !PyArray_ISCARRAY(arr))\n+\tsprintf(mess+strlen(mess),\" -- input not contiguous\");\n+ if (!(intent & F2PY_INTENT_C) && !PyArray_ISFARRAY(arr))\n+\tsprintf(mess+strlen(mess),\" -- input not fortran contiguous\");\n+ if (PyArray_ITEMSIZE(arr)!=descr->elsize)\n+\tsprintf(mess+strlen(mess),\" -- expected elsize=%d but got %d\",\n+\t\tdescr->elsize,\n+\t\tPyArray_ITEMSIZE(arr)\n+\t\t);\n+ if (!(PyArray_CanCastSafely(arr->descr->type_num,type_num)))\n+\tsprintf(mess+strlen(mess),\" -- cannot cast safely from '%c' to '%c'\",\n+\t\tarr->descr->type,descr->type);\n+ PyErr_SetString(PyExc_ValueError,mess);\n+ return NULL;\n+ }\n+\n+ /* here we have always intent(in) or intent(inplace) */\n+\n {\n PyArrayObject *retarr = (PyArrayObject *) \\\n \tPyArray_New(&PyArray_Type, rank, dims, type_num,\n \t\t NULL,NULL,0,\n \t\t !(intent&F2PY_INTENT_C),\n \t\t NULL);\n-\n- ARR_IS_NULL(retarr==NULL,\"PyArray_New failed: intent(in,copy)\\n\");\n+ if (retarr==NULL)\n+\treturn NULL;\n+ F2PY_REPORT_ON_ARRAY_COPY_FROMARR;\n if (PyArray_CopyInto(retarr, arr)) {\n \tPy_DECREF(retarr);\n \treturn NULL;\n }\n if (intent & F2PY_INTENT_INPLACE) {\n \tif (swap_arrays(arr,retarr))\n-\t return NULL;\n+\t return NULL; /* XXX: set exception */\n \tPy_XDECREF(retarr);\n \tif (intent & F2PY_INTENT_OUT)\n-\t Py_INCREF(arr);\t\n+\t Py_INCREF(arr);\n } else {\n \tarr = retarr;\n }\n@@ -634,211 +607,27 @@ PyArrayObject* array_from_pyobj(const int type_num,\n return arr;\n }\n \n- if ((obj==Py_None) && (intent & F2PY_OPTIONAL)) {\n- PyArrayObject *arr = NULL;\n- CHECK_DIMS_DEFINED(rank,dims,\"optional must have defined dimensions.\\n\");\n- arr = (PyArrayObject *)\n- PyArray_New(&PyArray_Type, rank, dims, type_num,\n-\t\t NULL,NULL,0,\n-\t\t !(intent&F2PY_INTENT_C),\n-\t\t NULL);\n- ARR_IS_NULL(arr==NULL,\"PyArray_New failed: optional\\n\");\n- PyArray_FILLWBYTE(arr, 0);\n- return arr;\n- }\n-\n- if ((intent & F2PY_INTENT_INOUT) || (intent & F2PY_INTENT_INPLACE)) {\n- ARR_IS_NULL(1,\"intent(inout)|intent(inplace) argument must be an array.\\n\");\n+ if ((intent & F2PY_INTENT_INOUT) \n+ || (intent & F2PY_INTENT_INPLACE)\n+ || (intent & F2PY_INTENT_CACHE)) {\n+ sprintf(mess,\"failed to initialize intent(inout|inplace|cache) array\"\n+\t \" -- input must be array but got %s\",\n+\t PyString_AsString(PyObject_Str(PyObject_Type(obj)))\n+\t );\n+ PyErr_SetString(PyExc_TypeError,mess);\n+ return NULL;\n }\n \n {\n PyArray_Typecode typecode = {type_num, 0, 0};\n- PyArrayObject *arr = (PyArrayObject *) \\\n+ F2PY_REPORT_ON_ARRAY_COPY_FROMANY;\n+ arr = (PyArrayObject *) \\\n PyArray_FromAny(obj,&typecode, 0,0,\n \t\t ((intent & F2PY_INTENT_C)?CARRAY_FLAGS:FARRAY_FLAGS));\n- ARR_IS_NULL(arr==NULL,\"PyArray_FromAny failed: not a sequence.\\n\");\n- if (check_and_fix_dimensions(arr,rank,dims))\n- return NULL; /*XXX: set exception */\n- return arr;\n- }\n-\n-}\n-\n-extern\n-PyArrayObject* old_array_from_pyobj(const int type_num,\n-\t\t\t\tintp *dims,\n-\t\t\t\tconst int rank,\n-\t\t\t\tconst int intent,\n-\t\t\t\tPyObject *obj) {\n- /* Note about reference counting\n- -----------------------------\n- If the caller returns the array to Python, it must be done with\n- Py_BuildValue(\"N\",arr).\n- Otherwise, if obj!=arr then the caller must call Py_DECREF(arr).\n- */\n- if (intent & F2PY_INTENT_CACHE) {\n- /* Don't expect correct storage order or anything reasonable when\n- returning intent(cache) array. */ \n- if ((intent & F2PY_INTENT_HIDE)\n-\t|| (obj==Py_None)) {\n- PyArrayObject *arr = NULL;\n- CHECK_DIMS_DEFINED(rank,dims,\"optional,intent(cache) must\"\n-\t\t\t \" have defined dimensions.\\n\");\n- arr = (PyArrayObject *)PyArray_SimpleNew(rank,dims,type_num);\n- ARR_IS_NULL(arr==NULL,\"FromDims failed: optional,intent(cache)\\n\");\n- memset(arr->data, 0, PyArray_NBYTES(arr));\n-/* if (intent & F2PY_INTENT_OUT) */\n-/* \tPy_INCREF(arr); */\n- return arr;\n- }\n-\n- if (PyArray_Check(obj) \n-\t&& PyArray_ISONESEGMENT(obj)\n-\t&& HAS_PROPER_ELSIZE((PyArrayObject *)obj,type_num)\n-\t) {\n- if (check_and_fix_dimensions((PyArrayObject *)obj,rank,dims))\n-\treturn NULL; /*XXX: set exception */\n- {\n-\tPyArrayObject *obj2;\n-\tif (intent & F2PY_INTENT_OUT)\n-\t Py_INCREF(obj);\n-\tobj2 = (PyArrayObject *) obj;\n-\treturn obj2;\n- }\n- }\n- ARR_IS_NULL(1,\"intent(cache) must be contiguous array with a proper elsize.\\n\");\n- }\n-\n- if (intent & F2PY_INTENT_HIDE) {\n- PyArrayObject *arr = NULL;\n- CHECK_DIMS_DEFINED(rank,dims,\"intent(hide) must have defined dimensions.\\n\");\n- arr = (PyArrayObject *)PyArray_SimpleNew(rank, dims, type_num);\n- ARR_IS_NULL(arr==NULL,\"FromDims failed: intent(hide)\\n\");\n- memset(arr->data, 0, PyArray_NBYTES(arr));\n- if (intent & F2PY_INTENT_OUT) {\n- if ((!(intent & F2PY_INTENT_C)) && (rank>1)) {\n-\ttranspose_strides(arr);\n-\tarr->flags &= ~CONTIGUOUS;\n-\tarr->flags |= FORTRAN;\n- }\n-/* Py_INCREF(arr); */\n- }\n- return arr;\n- }\n-\n- if (PyArray_Check(obj)) { /* here we have always intent(in) or\n-\t\t\t intent(inout) or intent(inplace) */\n- PyArrayObject *arr;\n- int is_cont;\n-\n- arr = (PyArrayObject *)obj;\n- is_cont = (intent & F2PY_INTENT_C) ? \n- (ISCONTIGUOUS(arr)) : (2*array_has_column_major_storage(arr));\n- if (check_and_fix_dimensions(arr,rank,dims))\n- return NULL; /*XXX: set exception */\n- if ((intent & F2PY_INTENT_COPY)\n-\t|| (! (is_cont\n-\t && HAS_PROPER_ELSIZE(arr,type_num)\n-\t && PyArray_CanCastSafely(arr->descr->type_num,type_num)\n-\t /* Make PyArray_CanCastSafely safer for 64-bit machines: */\n-\t /* && (arr->descr->type_num==PyArray_LONG?type_num!=PyArray_DOUBLE:1)*/\n-\t ))) {\n- PyArrayObject *tmp_arr = NULL;\n- if (intent & F2PY_INTENT_INOUT) {\n-\tARR_IS_NULL(1,\"intent(inout) array must be contiguous and\"\n-\t\t \" with a proper type and size.\\n\")\n-\t }\n- if ((rank>1) && (! (intent & F2PY_INTENT_C))) {\n-\tlazy_transpose(arr);\n-\t_lazy_transpose_update_flags(arr);\n- }\n-/* if (PyArray_CanCastSafely(arr->descr->type_num,type_num)) { */\n-/* \ttmp_arr = (PyArrayObject *)PyArray_CopyFromObject(obj,type_num,0,0); */\n-/* \tARR_IS_NULL(arr==NULL,\"CopyFromObject failed: array.\\n\"); */\n-/* } else */\n- {\n-\ttmp_arr = (PyArrayObject *)PyArray_SimpleNew(arr->nd,\n-\t\t\t\t\t\t arr->dimensions,\n-\t\t\t\t\t\t type_num);\n-\tARR_IS_NULL(tmp_arr==NULL,\"FromDims failed: array with unsafe cast.\\n\");\n-\tif (copy_ND_array(arr,tmp_arr))\n-\t ARR_IS_NULL(1,\"copy_ND_array failed: array with unsafe cast.\\n\");\n- }\n- if ((rank>1) && (! (intent & F2PY_INTENT_C))) {\n-\tlazy_transpose(arr);\n-\t_lazy_transpose_update_flags(arr);\n-\tlazy_transpose(tmp_arr);\n-\ttmp_arr->flags &= ~CONTIGUOUS;\n-\ttmp_arr->flags |= FORTRAN;\n- }\n- if (intent & F2PY_INTENT_INPLACE) {\n-\tif (swap_arrays(arr,tmp_arr))\n-\t return NULL;\n-\tPy_XDECREF(tmp_arr);\n-\tif (intent & F2PY_INTENT_OUT)\n-\t Py_INCREF(arr);\n- } else {\n-\tarr = tmp_arr;\n- }\n- } else {\n- if ((intent & F2PY_INTENT_OUT)) {\n-\tPy_INCREF(arr);\n- }\n- }\n- return arr;\n- }\n-\n- if ((obj==Py_None) && (intent & F2PY_OPTIONAL)) {\n- PyArrayObject *arr = NULL;\n- CHECK_DIMS_DEFINED(rank,dims,\"optional must have defined dimensions.\\n\"); \n- arr = (PyArrayObject *)PyArray_SimpleNew(rank,dims,type_num);\n- ARR_IS_NULL(arr==NULL,\"FromDims failed: optional.\\n\");\n- memset(arr->data, 0, PyArray_NBYTES(arr));\n- if (intent & F2PY_INTENT_OUT) {\n- if ((!(intent & F2PY_INTENT_C)) && (rank>1)) {\n-\ttranspose_strides(arr);\n-\tarr->flags &= ~CONTIGUOUS;\n-\tarr->flags |= FORTRAN;\n- }\n-/* Py_INCREF(arr); */\n- }\n- return arr;\n- }\n-\n- if ((intent & F2PY_INTENT_INOUT) || (intent & F2PY_INTENT_INPLACE)) {\n- ARR_IS_NULL(1,\"intent(inout)|intent(inplace) argument must be an array.\\n\");\n- }\n-\n- {\n- PyArrayObject *arr = (PyArrayObject *) \\\n- PyArray_ContiguousFromObject(obj,type_num,0,0);\n- ARR_IS_NULL(arr==NULL,\"ContiguousFromObject failed: not a sequence.\\n\");\n+ if (arr==NULL)\n+ return NULL;\n if (check_and_fix_dimensions(arr,rank,dims))\n return NULL; /*XXX: set exception */\n-\n- if ((rank>1) && (! (intent & F2PY_INTENT_C))) {\n- PyArrayObject *tmp_arr = NULL;\n- if (rank == 2) {\n-\t tmp_arr = (PyArrayObject *) PyArray_CopyAndTranspose((PyObject *)arr);\n-\t PyArray_UpdateFlags(tmp_arr, CONTIGUOUS | FORTRAN);\n- }\n- else {\n-\t lazy_transpose(arr);\n-\t arr->flags &= ~CONTIGUOUS;\n-\t arr->flags |= FORTRAN;\n-\t tmp_arr = (PyArrayObject *) PyArray_Copy(arr);\n- }\n-#ifdef F2PY_REPORT_ON_ARRAY_COPY\n- f2py_report_on_array_copy(tmp_arr,\"PyArray_Copy\");\n-#endif\n- Py_DECREF(arr);\n- arr = tmp_arr;\n- ARR_IS_NULL(arr==NULL,\"Copy(Array) failed: intent(fortran)\\n\");\n- lazy_transpose(arr);\n- _lazy_transpose_update_flags(arr);\n- }\n-/* if (intent & F2PY_INTENT_OUT) */\n-/* Py_INCREF(arr); */\n return arr;\n }\n \n@@ -848,27 +637,6 @@ PyArrayObject* old_array_from_pyobj(const int type_num,\n /* Helper functions for array_from_pyobj */\n /*****************************************/\n \n-extern\n-int array_has_column_major_storage(const PyArrayObject *ap) {\n- /* array_has_column_major_storage(a) is equivalent to\n- transpose(a).iscontiguous() but more efficient.\n-\n- This function can be used in order to decide whether to use a\n- Fortran or C version of a wrapped function. This is relevant, for\n- example, in choosing a clapack or flapack function depending on\n- the storage order of array arguments.\n- */\n- int sd;\n- int i;\n- sd = PyArray_ITEMSIZE(ap);\n- for (i=0;ind;++i) {\n- if (ap->dimensions[i] == 0) return 1;\n- if (ap->strides[i] != sd) return 0;\n- sd *= ap->dimensions[i];\n- }\n- return 1;\n-}\n-\n static\n int check_and_fix_dimensions(const PyArrayObject* arr,const int rank,intp *dims) {\n /*\n@@ -971,12 +739,10 @@ int check_and_fix_dimensions(const PyArrayObject* arr,const int rank,intp *dims)\n /************************* copy_ND_array *******************************/\n \n extern\n-int copy_ND_array(const PyArrayObject *in, PyArrayObject *out)\n+int copy_ND_array(const PyArrayObject *arr, PyArrayObject *out)\n {\n-#ifdef F2PY_REPORT_ON_ARRAY_COPY\n- f2py_report_on_array_copy(out, \"CopyInto\");\n-#endif\n- return PyArray_CopyInto(out, (PyArrayObject *)in);\n+ F2PY_REPORT_ON_ARRAY_COPY_FROMARR;\n+ return PyArray_CopyInto(out, (PyArrayObject *)arr);\n }\n \n #ifdef __cplusplus\n", "added_lines": 106, "deleted_lines": 340, "source_code": "#define FORTRANOBJECT_C\n#include \"fortranobject.h\"\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n/*\n This file implements: FortranObject, array_from_pyobj, copy_ND_array\n\n Author: Pearu Peterson \n $Revision: 1.52 $\n $Date: 2005/07/11 07:44:20 $\n*/\n\n/************************* FortranObject *******************************/\n\ntypedef PyObject *(*fortranfunc)(PyObject *,PyObject *,PyObject *,void *);\n\nPyObject *\nPyFortranObject_New(FortranDataDef* defs, f2py_void_func init) {\n int i;\n PyFortranObject *fp = NULL;\n PyObject *v = NULL;\n if (init!=NULL) /* Initialize F90 module objects */\n (*(init))();\n if ((fp = PyObject_New(PyFortranObject, &PyFortran_Type))==NULL) return NULL;\n if ((fp->dict = PyDict_New())==NULL) return NULL;\n fp->len = 0;\n while (defs[fp->len].name != NULL) fp->len++;\n if (fp->len == 0) goto fail;\n fp->defs = defs;\n for (i=0;ilen;i++)\n if (fp->defs[i].rank == -1) { /* Is Fortran routine */\n v = PyFortranObject_NewAsAttr(&(fp->defs[i]));\n if (v==NULL) return NULL;\n PyDict_SetItemString(fp->dict,fp->defs[i].name,v);\n } else\n if ((fp->defs[i].data)!=NULL) { /* Is Fortran variable or array (not allocatable) */\n\tv = PyArray_New(&PyArray_Type, fp->defs[i].rank, fp->defs[i].dims.d,\n\t\t\tfp->defs[i].type, NULL, fp->defs[i].data, 0, FARRAY_FLAGS,\n\t\t\tNULL);\n\tif (v==NULL) return NULL;\n\tPyDict_SetItemString(fp->dict,fp->defs[i].name,v);\n }\n Py_XDECREF(v);\n return (PyObject *)fp;\n fail:\n Py_XDECREF(v);\n return NULL;\n}\n\nPyObject *\nPyFortranObject_NewAsAttr(FortranDataDef* defs) { /* used for calling F90 module routines */\n PyFortranObject *fp = NULL;\n fp = PyObject_New(PyFortranObject, &PyFortran_Type);\n if (fp == NULL) return NULL;\n if ((fp->dict = PyDict_New())==NULL) return NULL;\n fp->len = 1;\n fp->defs = defs;\n return (PyObject *)fp;\n}\n\n/* Fortran methods */\n\nstatic void\nfortran_dealloc(PyFortranObject *fp) {\n Py_XDECREF(fp->dict);\n PyMem_Del(fp);\n}\n\n\nstatic PyMethodDef fortran_methods[] = {\n\t{NULL,\t\tNULL}\t\t/* sentinel */\n};\n\n\nstatic PyObject *\nfortran_doc (FortranDataDef def) {\n char *p;\n PyObject *s = NULL;\n int i;\n unsigned size=100;\n if (def.doc!=NULL)\n size += strlen(def.doc);\n p = (char*)malloc (size);\n if (sprintf(p,\"%s - \",def.name)==0) goto fail;\n if (def.rank==-1) {\n if (def.doc==NULL) {\n if (sprintf(p,\"%sno docs available\",p)==0)\n\tgoto fail;\n } else {\n if (sprintf(p,\"%s%s\",p,def.doc)==0)\n\tgoto fail;\n }\n } else {\n PyArray_Descr *d = PyArray_DescrFromType(def.type);\n if (sprintf(p,\"%s'%c'-\",p,d->type)==0) goto fail;\n if (def.data==NULL) {\n if (sprintf(p,\"%sarray(%\" INTP_FMT,p,def.dims.d[0])==0) goto fail;\n for(i=1;i0) {\n\tif (sprintf(p,\"%sarray(%\"INTP_FMT,p,def.dims.d[0])==0) goto fail;\n\tfor(i=1;isize) {\n fprintf(stderr,\"fortranobject.c:fortran_doc:len(p)=%zd>%d(size): too long doc string required, increase size\\n\",strlen(p),size);\n goto fail;\n }\n s = PyString_FromString(p);\n fail:\n free(p);\n return s;\n}\n\nstatic FortranDataDef *save_def; /* save pointer of an allocatable array */\nstatic void set_data(char *d,intp *f) { /* callback from Fortran */\n if (*f) /* In fortran f=allocated(d) */\n save_def->data = d;\n else\n save_def->data = NULL;\n /* printf(\"set_data: d=%p,f=%d\\n\",d,*f); */\n}\n\nstatic PyObject *\nfortran_getattr(PyFortranObject *fp, char *name) {\n int i,j,k,flag;\n if (fp->dict != NULL) {\n PyObject *v = PyDict_GetItemString(fp->dict, name);\n if (v != NULL) {\n Py_INCREF(v);\n return v;\n }\n }\n for (i=0,j=1;ilen && (j=strcmp(name,fp->defs[i].name));i++);\n if (j==0)\n if (fp->defs[i].rank!=-1) { /* F90 allocatable array */ \n if (fp->defs[i].func==NULL) return NULL;\n for(k=0;kdefs[i].rank;++k) \n\tfp->defs[i].dims.d[k]=-1;\n save_def = &fp->defs[i];\n (*(fp->defs[i].func))(&fp->defs[i].rank,fp->defs[i].dims.d,set_data,&flag);\n if (flag==2)\n\tk = fp->defs[i].rank + 1;\n else\n\tk = fp->defs[i].rank;\n if (fp->defs[i].data !=NULL) { /* array is allocated */\n\tPyObject *v = PyArray_New(&PyArray_Type, k, fp->defs[i].dims.d,\n\t\t\tfp->defs[i].type, NULL, fp->defs[i].data, 0, FARRAY_FLAGS,\n\t\t\tNULL);\n\tif (v==NULL) return NULL;\n\t/* Py_INCREF(v); */\n\treturn v;\n } else { /* array is not allocated */\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n }\n }\n if (strcmp(name,\"__dict__\")==0) {\n Py_INCREF(fp->dict);\n return fp->dict;\n }\n if (strcmp(name,\"__doc__\")==0) {\n PyObject *s = PyString_FromString(\"\");\n for (i=0;ilen;i++)\n PyString_ConcatAndDel(&s,fortran_doc(fp->defs[i]));\n if (PyDict_SetItemString(fp->dict, name, s))\n return NULL;\n return s;\n }\n if ((strcmp(name,\"_cpointer\")==0) && (fp->len==1)) {\n PyObject *cobj = PyCObject_FromVoidPtr((void *)(fp->defs[0].data),NULL);\n if (PyDict_SetItemString(fp->dict, name, cobj))\n return NULL;\n return cobj;\n }\n return Py_FindMethod(fortran_methods, (PyObject *)fp, name);\n}\n\nstatic int\nfortran_setattr(PyFortranObject *fp, char *name, PyObject *v) {\n int i,j,flag;\n PyArrayObject *arr = NULL;\n for (i=0,j=1;ilen && (j=strcmp(name,fp->defs[i].name));i++);\n if (j==0) {\n if (fp->defs[i].rank==-1) {\n PyErr_SetString(PyExc_AttributeError,\"over-writing fortran routine\");\n return -1;\n }\n if (fp->defs[i].func!=NULL) { /* is allocatable array */\n intp dims[F2PY_MAX_DIMS];\n int k;\n save_def = &fp->defs[i];\n if (v!=Py_None) { /* set new value (reallocate if needed --\n\t\t\t see f2py generated code for more\n\t\t\t details ) */\n\tfor(k=0;kdefs[i].rank;k++) dims[k]=-1;\n\tif ((arr = array_from_pyobj(fp->defs[i].type,dims,fp->defs[i].rank,F2PY_INTENT_IN,v))==NULL)\n\t return -1;\n\t(*(fp->defs[i].func))(&fp->defs[i].rank,arr->dimensions,set_data,&flag);\n } else { /* deallocate */\n\tfor(k=0;kdefs[i].rank;k++) dims[k]=0;\n\t(*(fp->defs[i].func))(&fp->defs[i].rank,dims,set_data,&flag);\n\tfor(k=0;kdefs[i].rank;k++) dims[k]=-1;\n }\n memcpy(fp->defs[i].dims.d,dims,fp->defs[i].rank*sizeof(intp));\n } else { /* not allocatable array */\n if ((arr = array_from_pyobj(fp->defs[i].type,fp->defs[i].dims.d,fp->defs[i].rank,F2PY_INTENT_IN,v))==NULL)\n\treturn -1; \n }\n if (fp->defs[i].data!=NULL) { /* copy Python object to Fortran array */\n intp s = PyArray_MultiplyList(fp->defs[i].dims.d,arr->nd);\n if (s==-1)\n\ts = PyArray_MultiplyList(arr->dimensions,arr->nd);\n if (s<0 ||\n\t (memcpy(fp->defs[i].data,arr->data,s*PyArray_ITEMSIZE(arr)))==NULL) {\n\tif ((PyObject*)arr!=v) {\n\t Py_DECREF(arr);\n\t}\n\treturn -1;\n }\n if ((PyObject*)arr!=v) {\n Py_DECREF(arr);\n }\n } else return (fp->defs[i].func==NULL?-1:0);\n return 0; /* succesful */\n }\n if (fp->dict == NULL) {\n fp->dict = PyDict_New();\n if (fp->dict == NULL)\n return -1;\n }\n if (v == NULL) {\n int rv = PyDict_DelItemString(fp->dict, name);\n if (rv < 0)\n PyErr_SetString(PyExc_AttributeError,\"delete non-existing fortran attribute\");\n return rv;\n }\n else\n return PyDict_SetItemString(fp->dict, name, v);\n}\n\nstatic PyObject*\nfortran_call(PyFortranObject *fp, PyObject *arg, PyObject *kw) {\n int i = 0;\n /* printf(\"fortran call\n name=%s,func=%p,data=%p,%p\\n\",fp->defs[i].name,\n fp->defs[i].func,fp->defs[i].data,&fp->defs[i].data); */\n if (fp->defs[i].rank==-1) {/* is Fortran routine */\n if ((fp->defs[i].func==NULL)) {\n PyErr_Format(PyExc_RuntimeError, \"no function to call\");\n return NULL;\n }\n else if (fp->defs[i].data==NULL)\n /* dummy routine */\n return (*((fortranfunc)(fp->defs[i].func)))((PyObject *)fp,arg,kw,NULL);\n else\n return (*((fortranfunc)(fp->defs[i].func)))((PyObject *)fp,arg,kw,\n\t\t\t\t\t\t (void *)fp->defs[i].data);\n }\n PyErr_Format(PyExc_TypeError, \"this fortran object is not callable\");\n return NULL;\n}\n\n\nPyTypeObject PyFortran_Type = {\n PyObject_HEAD_INIT(0)\n 0,\t\t\t/*ob_size*/\n \"fortran\",\t\t\t/*tp_name*/\n sizeof(PyFortranObject),\t/*tp_basicsize*/\n 0,\t\t\t/*tp_itemsize*/\n /* methods */\n (destructor)fortran_dealloc, /*tp_dealloc*/\n 0,\t\t\t/*tp_print*/\n (getattrfunc)fortran_getattr, /*tp_getattr*/\n (setattrfunc)fortran_setattr, /*tp_setattr*/\n 0,\t\t\t/*tp_compare*/\n 0,\t\t\t/*tp_repr*/\n 0,\t\t\t/*tp_as_number*/\n 0,\t\t\t/*tp_as_sequence*/\n 0,\t\t\t/*tp_as_mapping*/\n 0,\t\t\t/*tp_hash*/\n (ternaryfunc)fortran_call, /*tp_call*/\n};\n\n/************************* f2py_report_atexit *******************************/\n\n#ifdef F2PY_REPORT_ATEXIT\nstatic int passed_time = 0;\nstatic int passed_counter = 0;\nstatic int passed_call_time = 0;\nstatic struct timeb start_time;\nstatic struct timeb stop_time;\nstatic struct timeb start_call_time;\nstatic struct timeb stop_call_time;\nstatic int cb_passed_time = 0;\nstatic int cb_passed_counter = 0;\nstatic int cb_passed_call_time = 0;\nstatic struct timeb cb_start_time;\nstatic struct timeb cb_stop_time;\nstatic struct timeb cb_start_call_time;\nstatic struct timeb cb_stop_call_time;\n\nextern void f2py_start_clock(void) { ftime(&start_time); }\nextern\nvoid f2py_start_call_clock(void) {\n f2py_stop_clock();\n ftime(&start_call_time);\n}\nextern\nvoid f2py_stop_clock(void) {\n ftime(&stop_time);\n passed_time += 1000*(stop_time.time - start_time.time);\n passed_time += stop_time.millitm - start_time.millitm;\n}\nextern\nvoid f2py_stop_call_clock(void) {\n ftime(&stop_call_time);\n passed_call_time += 1000*(stop_call_time.time - start_call_time.time);\n passed_call_time += stop_call_time.millitm - start_call_time.millitm;\n passed_counter += 1;\n f2py_start_clock();\n}\n\nextern void f2py_cb_start_clock(void) { ftime(&cb_start_time); }\nextern\nvoid f2py_cb_start_call_clock(void) {\n f2py_cb_stop_clock();\n ftime(&cb_start_call_time);\n}\nextern\nvoid f2py_cb_stop_clock(void) {\n ftime(&cb_stop_time);\n cb_passed_time += 1000*(cb_stop_time.time - cb_start_time.time);\n cb_passed_time += cb_stop_time.millitm - cb_start_time.millitm;\n}\nextern\nvoid f2py_cb_stop_call_clock(void) {\n ftime(&cb_stop_call_time);\n cb_passed_call_time += 1000*(cb_stop_call_time.time - cb_start_call_time.time);\n cb_passed_call_time += cb_stop_call_time.millitm - cb_start_call_time.millitm;\n cb_passed_counter += 1;\n f2py_cb_start_clock();\n}\n\nstatic int f2py_report_on_exit_been_here = 0;\nextern\nvoid f2py_report_on_exit(int exit_flag,void *name) {\n if (f2py_report_on_exit_been_here) {\n fprintf(stderr,\" %s\\n\",(char*)name);\n return;\n }\n f2py_report_on_exit_been_here = 1;\n fprintf(stderr,\" /-----------------------\\\\\\n\");\n fprintf(stderr,\" < F2PY performance report >\\n\");\n fprintf(stderr,\" \\\\-----------------------/\\n\");\n fprintf(stderr,\"Overall time spent in ...\\n\");\n fprintf(stderr,\"(a) wrapped (Fortran/C) functions : %8d msec\\n\",\n\t passed_call_time);\n fprintf(stderr,\"(b) f2py interface, %6d calls : %8d msec\\n\",\n\t passed_counter,passed_time);\n fprintf(stderr,\"(c) call-back (Python) functions : %8d msec\\n\",\n\t cb_passed_call_time);\n fprintf(stderr,\"(d) f2py call-back interface, %6d calls : %8d msec\\n\",\n\t cb_passed_counter,cb_passed_time);\n \n fprintf(stderr,\"(e) wrapped (Fortran/C) functions (acctual) : %8d msec\\n\\n\",\n\t passed_call_time-cb_passed_call_time-cb_passed_time);\n fprintf(stderr,\"Use -DF2PY_REPORT_ATEXIT_DISABLE to disable this message.\\n\");\n fprintf(stderr,\"Exit status: %d\\n\",exit_flag);\n fprintf(stderr,\"Modules : %s\\n\",(char*)name);\n}\n#endif\n\n/********************** report on array copy ****************************/\n\n#ifdef F2PY_REPORT_ON_ARRAY_COPY\nstatic void f2py_report_on_array_copy(PyArrayObject* arr) {\n const long arr_size = PyArray_Size((PyObject *)arr);\n if (arr_size>F2PY_REPORT_ON_ARRAY_COPY) {\n fprintf(stderr,\"copied an array: size=%ld, elsize=%d\\n\", \n\t arr_size, PyArray_ITEMSIZE(arr));\n }\n}\nstatic void f2py_report_on_array_copy_fromany(void) {\n fprintf(stderr,\"created an array from object\\n\");\n}\n\n#define F2PY_REPORT_ON_ARRAY_COPY_FROMARR f2py_report_on_array_copy((PyArrayObject *)arr)\n#define F2PY_REPORT_ON_ARRAY_COPY_FROMANY f2py_report_on_array_copy_fromany()\n#else\n#define F2PY_REPORT_ON_ARRAY_COPY_FROMARR\n#define F2PY_REPORT_ON_ARRAY_COPY_FROMANY\n#endif\n\n\n/************************* array_from_obj *******************************/\n\n/* \n * File: array_from_pyobj.c \n *\n * Description:\n * ------------ \n * Provides array_from_pyobj function that returns a contigious array\n * object with the given dimensions and required storage order, either\n * in row-major (C) or column-major (Fortran) order. The function\n * array_from_pyobj is very flexible about its Python object argument\n * that can be any number, list, tuple, or array.\n * \n * array_from_pyobj is used in f2py generated Python extension\n * modules.\n *\n * Author: Pearu Peterson \n * Created: 13-16 January 2002\n * $Id: fortranobject.c,v 1.52 2005/07/11 07:44:20 pearu Exp $\n */\n\nstatic int \ncount_nonpos(const int rank,\n\t const intp *dims) {\n int i=0,r=0;\n while (ind;\n intp size = PyArray_Size((PyObject *)arr);\n int i;\n printf(\"\\trank = %d, flags = %d, size = %\" INTP_FMT \"\\n\",\n\t rank,arr->flags,size);\n printf(\"\\tstrides = [\");\n for(i=0;istrides[i]);\n }\n printf(\"]\\n\\t dimensions = [\");\n for(i=0;idimensions[i]);\n }\n printf(\"]\\n\");\n}\n#endif\n\n#define SWAPTYPE(a,b,t) {t c; c = (a); (a) = (b); (b) = c; }\n\nstatic int swap_arrays(PyArrayObject* arr1, PyArrayObject* arr2) {\n SWAPTYPE(arr1->data,arr2->data,char*);\n SWAPTYPE(arr1->nd,arr2->nd,int);\n SWAPTYPE(arr1->dimensions,arr2->dimensions,intp*);\n SWAPTYPE(arr1->strides,arr2->strides,intp*);\n SWAPTYPE(arr1->base,arr2->base,PyObject*);\n SWAPTYPE(arr1->descr,arr2->descr,PyArray_Descr*);\n SWAPTYPE(arr1->flags,arr2->flags,int);\n SWAPTYPE(arr1->itemsize, arr2->itemsize, int);\n /* SWAPTYPE(arr1->weakreflist,arr2->weakreflist,PyObject*); */\n return 0;\n}\n\nextern\nPyArrayObject* array_from_pyobj(const int type_num,\n\t\t\t\tintp *dims,\n\t\t\t\tconst int rank,\n\t\t\t\tconst int intent,\n\t\t\t\tPyObject *obj) {\n /* Note about reference counting\n -----------------------------\n If the caller returns the array to Python, it must be done with\n Py_BuildValue(\"N\",arr).\n Otherwise, if obj!=arr then the caller must call Py_DECREF(arr).\n\n Note on intent(cache,out,..)\n ---------------------\n Don't expect correct data when returning intent(cache) array.\n\n */\n char mess[200];\n PyArrayObject *arr = NULL;\n PyArray_Descr *descr = PyArray_DescrFromType(type_num);\n\n if ((intent & F2PY_INTENT_HIDE)\n || ((intent & F2PY_INTENT_CACHE) && (obj==Py_None))\n || ((intent & F2PY_OPTIONAL) && (obj==Py_None))\n ) {\n /* intent(cache), optional, intent(hide) */\n if (count_nonpos(rank,dims)) {\n int i;\n sprintf(mess,\"failed to create intent(cache|hide)|optional array\"\n\t \"-- must have defined dimensions but got (\");\n for(i=0;i=descr->elsize) {\n\tif (check_and_fix_dimensions((PyArrayObject *)obj,rank,dims))\n\t return NULL; /*XXX: set exception */\n\tif (intent & F2PY_INTENT_OUT)\n\t Py_INCREF(obj);\n\treturn (PyArrayObject *)obj;\n }\n sprintf(mess,\"failed to initialize intent(cache) array\");\n if (!PyArray_ISONESEGMENT(obj))\n\tsprintf(mess+strlen(mess),\" -- input must be in one segment\");\n if (PyArray_ITEMSIZE(arr)elsize)\n\tsprintf(mess+strlen(mess),\" -- expected at least elsize=%d but got %d\",\n\t\tdescr->elsize,PyArray_ITEMSIZE(arr)\n\t\t);\n PyErr_SetString(PyExc_ValueError,mess);\n return NULL;\n }\n\n /* here we have always intent(in) or intent(inout) or intent(inplace) */\n\n if (check_and_fix_dimensions(arr,rank,dims))\n return NULL; /*XXX: set exception */\n\n if ((! (intent & F2PY_INTENT_COPY))\n\t&& PyArray_ITEMSIZE(arr)==descr->elsize\n\t&& PyArray_CanCastSafely(arr->descr->type_num,type_num)\n\t) {\n if ((intent & F2PY_INTENT_C)?PyArray_ISCARRAY(arr):PyArray_ISFARRAY(arr)) {\n\tif ((intent & F2PY_INTENT_OUT)) {\n\t Py_INCREF(arr);\n\t}\n\t/* Returning input array */\n\treturn arr;\n }\n }\n\n if (intent & F2PY_INTENT_INOUT) {\n sprintf(mess,\"failed to initialize intent(inout) array\");\n if ((intent & F2PY_INTENT_C) && !PyArray_ISCARRAY(arr))\n\tsprintf(mess+strlen(mess),\" -- input not contiguous\");\n if (!(intent & F2PY_INTENT_C) && !PyArray_ISFARRAY(arr))\n\tsprintf(mess+strlen(mess),\" -- input not fortran contiguous\");\n if (PyArray_ITEMSIZE(arr)!=descr->elsize)\n\tsprintf(mess+strlen(mess),\" -- expected elsize=%d but got %d\",\n\t\tdescr->elsize,\n\t\tPyArray_ITEMSIZE(arr)\n\t\t);\n if (!(PyArray_CanCastSafely(arr->descr->type_num,type_num)))\n\tsprintf(mess+strlen(mess),\" -- cannot cast safely from '%c' to '%c'\",\n\t\tarr->descr->type,descr->type);\n PyErr_SetString(PyExc_ValueError,mess);\n return NULL;\n }\n\n /* here we have always intent(in) or intent(inplace) */\n\n {\n PyArrayObject *retarr = (PyArrayObject *) \\\n\tPyArray_New(&PyArray_Type, rank, dims, type_num,\n\t\t NULL,NULL,0,\n\t\t !(intent&F2PY_INTENT_C),\n\t\t NULL);\n if (retarr==NULL)\n\treturn NULL;\n F2PY_REPORT_ON_ARRAY_COPY_FROMARR;\n if (PyArray_CopyInto(retarr, arr)) {\n\tPy_DECREF(retarr);\n\treturn NULL;\n }\n if (intent & F2PY_INTENT_INPLACE) {\n\tif (swap_arrays(arr,retarr))\n\t return NULL; /* XXX: set exception */\n\tPy_XDECREF(retarr);\n\tif (intent & F2PY_INTENT_OUT)\n\t Py_INCREF(arr);\n } else {\n\tarr = retarr;\n }\n }\n return arr;\n }\n\n if ((intent & F2PY_INTENT_INOUT) \n || (intent & F2PY_INTENT_INPLACE)\n || (intent & F2PY_INTENT_CACHE)) {\n sprintf(mess,\"failed to initialize intent(inout|inplace|cache) array\"\n\t \" -- input must be array but got %s\",\n\t PyString_AsString(PyObject_Str(PyObject_Type(obj)))\n\t );\n PyErr_SetString(PyExc_TypeError,mess);\n return NULL;\n }\n\n {\n PyArray_Typecode typecode = {type_num, 0, 0};\n F2PY_REPORT_ON_ARRAY_COPY_FROMANY;\n arr = (PyArrayObject *) \\\n PyArray_FromAny(obj,&typecode, 0,0,\n\t\t ((intent & F2PY_INTENT_C)?CARRAY_FLAGS:FARRAY_FLAGS));\n if (arr==NULL)\n return NULL;\n if (check_and_fix_dimensions(arr,rank,dims))\n return NULL; /*XXX: set exception */\n return arr;\n }\n\n}\n\n /*****************************************/\n /* Helper functions for array_from_pyobj */\n /*****************************************/\n\nstatic\nint check_and_fix_dimensions(const PyArrayObject* arr,const int rank,intp *dims) {\n /*\n This function fills in blanks (that are -1\\'s) in dims list using\n the dimensions from arr. It also checks that non-blank dims will\n match with the corresponding values in arr dimensions.\n */\n const intp arr_size = (arr->nd)?PyArray_Size((PyObject *)arr):1;\n\n if (rank > arr->nd) { /* [1,2] -> [[1],[2]]; 1 -> [[1]] */\n intp new_size = 1;\n int free_axe = -1;\n int i;\n /* Fill dims where -1 or 0; check dimensions; calc new_size; */\n for(i=0;ind;++i) { \n if (dims[i] >= 0) {\n\tif (dims[i]!=arr->dimensions[i]) {\n\t fprintf(stderr,\"%d-th dimension must be fixed to %\" INTP_FMT\n\t\t \" but got %\" INTP_FMT \"\\n\",\n\t\t i,dims[i], arr->dimensions[i]);\n\t return 1;\n\t}\n\tif (!dims[i]) dims[i] = 1;\n } else {\n\tdims[i] = arr->dimensions[i] ? arr->dimensions[i] : 1;\n }\n new_size *= dims[i];\n }\n for(i=arr->nd;i1) {\n\tfprintf(stderr,\"%d-th dimension must be %\" INTP_FMT\n\t\t\" but got 0 (not defined).\\n\",\n\t\ti,dims[i]);\n\treturn 1;\n } else if (free_axe<0)\n\tfree_axe = i;\n else\n\tdims[i] = 1;\n if (free_axe>=0) {\n dims[free_axe] = arr_size/new_size;\n new_size *= dims[free_axe];\n }\n if (new_size != arr_size) {\n fprintf(stderr,\"confused: new_size=%\" INTP_FMT\n\t \", arr_size=%\" INTP_FMT \" (maybe too many free\"\n\t \" indices)\\n\", new_size,arr_size);\n return 1;\n }\n } else { /* [[1,2]] -> [[1],[2]] */\n int i,j;\n intp d;\n int effrank;\n intp size;\n for (i=0,effrank=0;ind;++i)\n if (arr->dimensions[i]>1) ++effrank;\n if (dims[rank-1]>=0)\n if (effrank>rank) {\n\tfprintf(stderr,\"too many axes: %d (effrank=%d), expected rank=%d\\n\",\n\t\tarr->nd,effrank,rank);\n\treturn 1;\n }\n for (i=0,j=0;ind && arr->dimensions[j]<2) ++j;\n if (j>=arr->nd) d = 1;\n else d = arr->dimensions[j++];\n if (dims[i]>=0) {\n\tif (d>1 && d!=dims[i]) {\n\t fprintf(stderr,\"%d-th dimension must be fixed to %\" INTP_FMT \n\t\t \" but got %\" INTP_FMT \" (real index=%d)\\n\",\n\t\t i,dims[i],d,j-1);\n\t return 1;\t \n\t}\n\tif (!dims[i]) dims[i] = 1;\n } else\n\tdims[i] = d;\n }\n for (i=rank;ind;++i) { /* [[1,2],[3,4]] -> [1,2,3,4] */\n while (jnd && arr->dimensions[j]<2) ++j;\n if (j>=arr->nd) d = 1;\n else d = arr->dimensions[j++];\n dims[rank-1] *= d;\n }\n for (i=0,size=1;ind);\n for (i=0;ind;++i) fprintf(stderr,\" %\" INTP_FMT,arr->dimensions[i]);\n fprintf(stderr,\" ]\\n\");\n return 1;\n }\n }\n return 0;\n}\n\n/* End of file: array_from_pyobj.c */\n\n/************************* copy_ND_array *******************************/\n\nextern\nint copy_ND_array(const PyArrayObject *arr, PyArrayObject *out)\n{\n F2PY_REPORT_ON_ARRAY_COPY_FROMARR;\n return PyArray_CopyInto(out, (PyArrayObject *)arr);\n}\n\n#ifdef __cplusplus\n}\n#endif\n/************************* EOF fortranobject.c *******************************/\n", "source_code_before": "#define FORTRANOBJECT_C\n#include \"fortranobject.h\"\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n/*\n This file implements: FortranObject, array_from_pyobj, copy_ND_array,\n lazy_transpose, transpose_strides,\n\t\t and array_has_column_major_storage.\n\n Author: Pearu Peterson \n $Revision: 1.52 $\n $Date: 2005/07/11 07:44:20 $\n*/\n\n/************************* FortranObject *******************************/\n\ntypedef PyObject *(*fortranfunc)(PyObject *,PyObject *,PyObject *,void *);\n\nPyObject *\nPyFortranObject_New(FortranDataDef* defs, f2py_void_func init) {\n int i;\n PyFortranObject *fp = NULL;\n PyObject *v = NULL;\n if (init!=NULL) /* Initialize F90 module objects */\n (*(init))();\n if ((fp = PyObject_New(PyFortranObject, &PyFortran_Type))==NULL) return NULL;\n if ((fp->dict = PyDict_New())==NULL) return NULL;\n fp->len = 0;\n while (defs[fp->len].name != NULL) fp->len++;\n if (fp->len == 0) goto fail;\n fp->defs = defs;\n for (i=0;ilen;i++)\n if (fp->defs[i].rank == -1) { /* Is Fortran routine */\n v = PyFortranObject_NewAsAttr(&(fp->defs[i]));\n if (v==NULL) return NULL;\n PyDict_SetItemString(fp->dict,fp->defs[i].name,v);\n } else\n if ((fp->defs[i].data)!=NULL) { /* Is Fortran variable or array (not allocatable) */\n\tv = PyArray_New(&PyArray_Type, fp->defs[i].rank, fp->defs[i].dims.d,\n\t\t\tfp->defs[i].type, NULL, fp->defs[i].data, 0, FARRAY_FLAGS,\n\t\t\tNULL);\n\tif (v==NULL) return NULL;\n\tPyDict_SetItemString(fp->dict,fp->defs[i].name,v);\n }\n Py_XDECREF(v);\n return (PyObject *)fp;\n fail:\n Py_XDECREF(v);\n return NULL;\n}\n\nPyObject *\nPyFortranObject_NewAsAttr(FortranDataDef* defs) { /* used for calling F90 module routines */\n PyFortranObject *fp = NULL;\n fp = PyObject_New(PyFortranObject, &PyFortran_Type);\n if (fp == NULL) return NULL;\n if ((fp->dict = PyDict_New())==NULL) return NULL;\n fp->len = 1;\n fp->defs = defs;\n return (PyObject *)fp;\n}\n\n/* Fortran methods */\n\nstatic void\nfortran_dealloc(PyFortranObject *fp) {\n Py_XDECREF(fp->dict);\n PyMem_Del(fp);\n}\n\n\nstatic PyMethodDef fortran_methods[] = {\n\t{NULL,\t\tNULL}\t\t/* sentinel */\n};\n\n\nstatic PyObject *\nfortran_doc (FortranDataDef def) {\n char *p;\n PyObject *s = NULL;\n int i;\n unsigned size=100;\n if (def.doc!=NULL)\n size += strlen(def.doc);\n p = (char*)malloc (size);\n if (sprintf(p,\"%s - \",def.name)==0) goto fail;\n if (def.rank==-1) {\n if (def.doc==NULL) {\n if (sprintf(p,\"%sno docs available\",p)==0)\n\tgoto fail;\n } else {\n if (sprintf(p,\"%s%s\",p,def.doc)==0)\n\tgoto fail;\n }\n } else {\n PyArray_Descr *d = PyArray_DescrFromType(def.type);\n if (sprintf(p,\"%s'%c'-\",p,d->type)==0) goto fail;\n if (def.data==NULL) {\n if (sprintf(p,\"%sarray(%\" INTP_FMT,p,def.dims.d[0])==0) goto fail;\n for(i=1;i0) {\n\tif (sprintf(p,\"%sarray(%\"INTP_FMT,p,def.dims.d[0])==0) goto fail;\n\tfor(i=1;isize) {\n fprintf(stderr,\"fortranobject.c:fortran_doc:len(p)=%zd>%d(size): too long doc string required, increase size\\n\",strlen(p),size);\n goto fail;\n }\n s = PyString_FromString(p);\n fail:\n free(p);\n return s;\n}\n\nstatic FortranDataDef *save_def; /* save pointer of an allocatable array */\nstatic void set_data(char *d,intp *f) { /* callback from Fortran */\n if (*f) /* In fortran f=allocated(d) */\n save_def->data = d;\n else\n save_def->data = NULL;\n /* printf(\"set_data: d=%p,f=%d\\n\",d,*f); */\n}\n\nstatic PyObject *\nfortran_getattr(PyFortranObject *fp, char *name) {\n int i,j,k,flag;\n if (fp->dict != NULL) {\n PyObject *v = PyDict_GetItemString(fp->dict, name);\n if (v != NULL) {\n Py_INCREF(v);\n return v;\n }\n }\n for (i=0,j=1;ilen && (j=strcmp(name,fp->defs[i].name));i++);\n if (j==0)\n if (fp->defs[i].rank!=-1) { /* F90 allocatable array */ \n if (fp->defs[i].func==NULL) return NULL;\n for(k=0;kdefs[i].rank;++k) \n\tfp->defs[i].dims.d[k]=-1;\n save_def = &fp->defs[i];\n (*(fp->defs[i].func))(&fp->defs[i].rank,fp->defs[i].dims.d,set_data,&flag);\n if (flag==2)\n\tk = fp->defs[i].rank + 1;\n else\n\tk = fp->defs[i].rank;\n if (fp->defs[i].data !=NULL) { /* array is allocated */\n\tPyObject *v = PyArray_New(&PyArray_Type, k, fp->defs[i].dims.d,\n\t\t\tfp->defs[i].type, NULL, fp->defs[i].data, 0, FARRAY_FLAGS,\n\t\t\tNULL);\n\tif (v==NULL) return NULL;\n\t/* Py_INCREF(v); */\n\treturn v;\n } else { /* array is not allocated */\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n }\n }\n if (strcmp(name,\"__dict__\")==0) {\n Py_INCREF(fp->dict);\n return fp->dict;\n }\n if (strcmp(name,\"__doc__\")==0) {\n PyObject *s = PyString_FromString(\"\");\n for (i=0;ilen;i++)\n PyString_ConcatAndDel(&s,fortran_doc(fp->defs[i]));\n if (PyDict_SetItemString(fp->dict, name, s))\n return NULL;\n return s;\n }\n if ((strcmp(name,\"_cpointer\")==0) && (fp->len==1)) {\n PyObject *cobj = PyCObject_FromVoidPtr((void *)(fp->defs[0].data),NULL);\n if (PyDict_SetItemString(fp->dict, name, cobj))\n return NULL;\n return cobj;\n }\n return Py_FindMethod(fortran_methods, (PyObject *)fp, name);\n}\n\nstatic int\nfortran_setattr(PyFortranObject *fp, char *name, PyObject *v) {\n int i,j,flag;\n PyArrayObject *arr = NULL;\n for (i=0,j=1;ilen && (j=strcmp(name,fp->defs[i].name));i++);\n if (j==0) {\n if (fp->defs[i].rank==-1) {\n PyErr_SetString(PyExc_AttributeError,\"over-writing fortran routine\");\n return -1;\n }\n if (fp->defs[i].func!=NULL) { /* is allocatable array */\n intp dims[F2PY_MAX_DIMS];\n int k;\n save_def = &fp->defs[i];\n if (v!=Py_None) { /* set new value (reallocate if needed --\n\t\t\t see f2py generated code for more\n\t\t\t details ) */\n\tfor(k=0;kdefs[i].rank;k++) dims[k]=-1;\n\tif ((arr = array_from_pyobj(fp->defs[i].type,dims,fp->defs[i].rank,F2PY_INTENT_IN,v))==NULL)\n\t return -1;\n\t(*(fp->defs[i].func))(&fp->defs[i].rank,arr->dimensions,set_data,&flag);\n } else { /* deallocate */\n\tfor(k=0;kdefs[i].rank;k++) dims[k]=0;\n\t(*(fp->defs[i].func))(&fp->defs[i].rank,dims,set_data,&flag);\n\tfor(k=0;kdefs[i].rank;k++) dims[k]=-1;\n }\n memcpy(fp->defs[i].dims.d,dims,fp->defs[i].rank*sizeof(intp));\n } else { /* not allocatable array */\n if ((arr = array_from_pyobj(fp->defs[i].type,fp->defs[i].dims.d,fp->defs[i].rank,F2PY_INTENT_IN,v))==NULL)\n\treturn -1; \n }\n if (fp->defs[i].data!=NULL) { /* copy Python object to Fortran array */\n intp s = PyArray_MultiplyList(fp->defs[i].dims.d,arr->nd);\n if (s==-1)\n\ts = PyArray_MultiplyList(arr->dimensions,arr->nd);\n if (s<0 ||\n\t (memcpy(fp->defs[i].data,arr->data,s*PyArray_ITEMSIZE(arr)))==NULL) {\n\tif ((PyObject*)arr!=v) {\n\t Py_DECREF(arr);\n\t}\n\treturn -1;\n }\n if ((PyObject*)arr!=v) {\n Py_DECREF(arr);\n }\n } else return (fp->defs[i].func==NULL?-1:0);\n return 0; /* succesful */\n }\n if (fp->dict == NULL) {\n fp->dict = PyDict_New();\n if (fp->dict == NULL)\n return -1;\n }\n if (v == NULL) {\n int rv = PyDict_DelItemString(fp->dict, name);\n if (rv < 0)\n PyErr_SetString(PyExc_AttributeError,\"delete non-existing fortran attribute\");\n return rv;\n }\n else\n return PyDict_SetItemString(fp->dict, name, v);\n}\n\nstatic PyObject*\nfortran_call(PyFortranObject *fp, PyObject *arg, PyObject *kw) {\n int i = 0;\n /* printf(\"fortran call\n name=%s,func=%p,data=%p,%p\\n\",fp->defs[i].name,\n fp->defs[i].func,fp->defs[i].data,&fp->defs[i].data); */\n if (fp->defs[i].rank==-1) {/* is Fortran routine */\n if ((fp->defs[i].func==NULL)) {\n PyErr_Format(PyExc_RuntimeError, \"no function to call\");\n return NULL;\n }\n else if (fp->defs[i].data==NULL)\n /* dummy routine */\n return (*((fortranfunc)(fp->defs[i].func)))((PyObject *)fp,arg,kw,NULL);\n else\n return (*((fortranfunc)(fp->defs[i].func)))((PyObject *)fp,arg,kw,\n\t\t\t\t\t\t (void *)fp->defs[i].data);\n }\n PyErr_Format(PyExc_TypeError, \"this fortran object is not callable\");\n return NULL;\n}\n\n\nPyTypeObject PyFortran_Type = {\n PyObject_HEAD_INIT(0)\n 0,\t\t\t/*ob_size*/\n \"fortran\",\t\t\t/*tp_name*/\n sizeof(PyFortranObject),\t/*tp_basicsize*/\n 0,\t\t\t/*tp_itemsize*/\n /* methods */\n (destructor)fortran_dealloc, /*tp_dealloc*/\n 0,\t\t\t/*tp_print*/\n (getattrfunc)fortran_getattr, /*tp_getattr*/\n (setattrfunc)fortran_setattr, /*tp_setattr*/\n 0,\t\t\t/*tp_compare*/\n 0,\t\t\t/*tp_repr*/\n 0,\t\t\t/*tp_as_number*/\n 0,\t\t\t/*tp_as_sequence*/\n 0,\t\t\t/*tp_as_mapping*/\n 0,\t\t\t/*tp_hash*/\n (ternaryfunc)fortran_call, /*tp_call*/\n};\n\n/************************* f2py_report_atexit *******************************/\n\n#ifdef F2PY_REPORT_ATEXIT\nstatic int passed_time = 0;\nstatic int passed_counter = 0;\nstatic int passed_call_time = 0;\nstatic struct timeb start_time;\nstatic struct timeb stop_time;\nstatic struct timeb start_call_time;\nstatic struct timeb stop_call_time;\nstatic int cb_passed_time = 0;\nstatic int cb_passed_counter = 0;\nstatic int cb_passed_call_time = 0;\nstatic struct timeb cb_start_time;\nstatic struct timeb cb_stop_time;\nstatic struct timeb cb_start_call_time;\nstatic struct timeb cb_stop_call_time;\n\nextern void f2py_start_clock(void) { ftime(&start_time); }\nextern\nvoid f2py_start_call_clock(void) {\n f2py_stop_clock();\n ftime(&start_call_time);\n}\nextern\nvoid f2py_stop_clock(void) {\n ftime(&stop_time);\n passed_time += 1000*(stop_time.time - start_time.time);\n passed_time += stop_time.millitm - start_time.millitm;\n}\nextern\nvoid f2py_stop_call_clock(void) {\n ftime(&stop_call_time);\n passed_call_time += 1000*(stop_call_time.time - start_call_time.time);\n passed_call_time += stop_call_time.millitm - start_call_time.millitm;\n passed_counter += 1;\n f2py_start_clock();\n}\n\nextern void f2py_cb_start_clock(void) { ftime(&cb_start_time); }\nextern\nvoid f2py_cb_start_call_clock(void) {\n f2py_cb_stop_clock();\n ftime(&cb_start_call_time);\n}\nextern\nvoid f2py_cb_stop_clock(void) {\n ftime(&cb_stop_time);\n cb_passed_time += 1000*(cb_stop_time.time - cb_start_time.time);\n cb_passed_time += cb_stop_time.millitm - cb_start_time.millitm;\n}\nextern\nvoid f2py_cb_stop_call_clock(void) {\n ftime(&cb_stop_call_time);\n cb_passed_call_time += 1000*(cb_stop_call_time.time - cb_start_call_time.time);\n cb_passed_call_time += cb_stop_call_time.millitm - cb_start_call_time.millitm;\n cb_passed_counter += 1;\n f2py_cb_start_clock();\n}\n\nstatic int f2py_report_on_exit_been_here = 0;\nextern\nvoid f2py_report_on_exit(int exit_flag,void *name) {\n if (f2py_report_on_exit_been_here) {\n fprintf(stderr,\" %s\\n\",(char*)name);\n return;\n }\n f2py_report_on_exit_been_here = 1;\n fprintf(stderr,\" /-----------------------\\\\\\n\");\n fprintf(stderr,\" < F2PY performance report >\\n\");\n fprintf(stderr,\" \\\\-----------------------/\\n\");\n fprintf(stderr,\"Overall time spent in ...\\n\");\n fprintf(stderr,\"(a) wrapped (Fortran/C) functions : %8d msec\\n\",\n\t passed_call_time);\n fprintf(stderr,\"(b) f2py interface, %6d calls : %8d msec\\n\",\n\t passed_counter,passed_time);\n fprintf(stderr,\"(c) call-back (Python) functions : %8d msec\\n\",\n\t cb_passed_call_time);\n fprintf(stderr,\"(d) f2py call-back interface, %6d calls : %8d msec\\n\",\n\t cb_passed_counter,cb_passed_time);\n \n fprintf(stderr,\"(e) wrapped (Fortran/C) functions (acctual) : %8d msec\\n\\n\",\n\t passed_call_time-cb_passed_call_time-cb_passed_time);\n fprintf(stderr,\"Use -DF2PY_REPORT_ATEXIT_DISABLE to disable this message.\\n\");\n fprintf(stderr,\"Exit status: %d\\n\",exit_flag);\n fprintf(stderr,\"Modules : %s\\n\",(char*)name);\n}\n#endif\n\n/********************** report on array copy ****************************/\n\n#ifdef F2PY_REPORT_ON_ARRAY_COPY\nstatic void f2py_report_on_array_copy(PyArrayObject* arr, char* func_name) {\n const long arr_size = PyArray_Size((PyObject *)arr);\n if (arr_size>F2PY_REPORT_ON_ARRAY_COPY) {\n fprintf(stderr,\"copied an array using %s: size=%ld, elsize=%d\\n\", \n\t func_name, arr_size, PyArray_ITEMSIZE(arr));\n }\n}\n#endif\n\n/************************* lazy_transpose *******************************/\n\nextern\nvoid lazy_transpose(PyArrayObject* arr) {\n /*\n Changes the order of array strides and dimensions. This\n corresponds to the lazy transpose of a Numeric array in-situ.\n Note that this function is assumed to be used even times for a\n given array. Otherwise, the caller should set flags &= ~CONTIGUOUS.\n */\n int rank, i;\n intp s,j; \n rank = arr->nd; \n if (rank < 2) return;\n\n for(i=0,j=rank-1;istrides[i];\n arr->strides[i] = arr->strides[j];\n arr->strides[j] = s;\n s = arr->dimensions[i];\n arr->dimensions[i] = arr->dimensions[j];\n arr->dimensions[j] = s;\n }\n}\n\nextern\nvoid transpose_strides(PyArrayObject* arr) {\n int rank, i;\n intp j;\n rank = arr->nd; \n if (rank < 2) return;\n j = arr->strides[rank-1];\n for(i=0;istrides[i] = j;\n j *= arr->dimensions[i];\n }\n}\n\n/************************* array_from_obj *******************************/\n\n/* \n * File: array_from_pyobj.c \n *\n * Description:\n * ------------ \n * Provides array_from_pyobj function that returns a contigious array\n * object with the given dimensions and required storage order, either\n * in row-major (C) or column-major (Fortran) order. The function\n * array_from_pyobj is very flexible about its Python object argument\n * that can be any number, list, tuple, or array.\n * \n * array_from_pyobj is used in f2py generated Python extension\n * modules.\n *\n * Author: Pearu Peterson \n * Created: 13-16 January 2002\n * $Id: fortranobject.c,v 1.52 2005/07/11 07:44:20 pearu Exp $\n */\n\n\n#define ARR_IS_NULL(arr_is_NULL,mess) \\\nif (arr_is_NULL) { \\\n fprintf(stderr,\"array_from_pyobj:\" mess); \\\n return NULL; \\\n}\n\n#define CHECK_DIMS_DEFINED(rank,dims,mess) \\\nif (count_nonpos(rank,dims)) { int i;\\\n fprintf(stderr,\"array_from_pyobj:\" mess); \\\n fprintf(stderr,\"rank=%d dimensions=[ \",rank); \\\n for(i=0;ielsize) == PyArray_ITEMSIZE(arr))\n\nstatic int \ncount_nonpos(const int rank,\n\t const intp *dims) {\n int i=0,r=0;\n while (ind;\n intp size = PyArray_Size((PyObject *)arr);\n int i;\n printf(\"\\trank = %d, flags = %d, size = %\" INTP_FMT \"\\n\",\n\t rank,arr->flags,size);\n printf(\"\\tstrides = [\");\n for(i=0;istrides[i]);\n }\n printf(\"]\\n\\t dimensions = [\");\n for(i=0;idimensions[i]);\n }\n printf(\"]\\n\");\n}\n#endif\n\n#define SWAPTYPE(a,b,t) {t c; c = (a); (a) = (b); (b) = c; }\n\nstatic int swap_arrays(PyArrayObject* arr1, PyArrayObject* arr2) {\n SWAPTYPE(arr1->data,arr2->data,char*);\n SWAPTYPE(arr1->nd,arr2->nd,int);\n SWAPTYPE(arr1->dimensions,arr2->dimensions,intp*);\n SWAPTYPE(arr1->strides,arr2->strides,intp*);\n SWAPTYPE(arr1->base,arr2->base,PyObject*);\n SWAPTYPE(arr1->descr,arr2->descr,PyArray_Descr*);\n SWAPTYPE(arr1->flags,arr2->flags,int);\n SWAPTYPE(arr1->itemsize, arr2->itemsize, int);\n /* SWAPTYPE(arr1->weakreflist,arr2->weakreflist,PyObject*); */\n return 0;\n}\n\n\t/* useful after a lazy-transpose to update the flags\n\t quickly \n\t*/\n\n#define _lazy_transpose_update_flags(obj) {\t\t \\\n\t\tif (PyArray_ISCONTIGUOUS(obj)) {\t \\\n\t\t\tPyArray_FLAGS(obj) &= ~CONTIGUOUS; \\\n\t\t\tPyArray_FLAGS(obj) |= FORTRAN; \\\n\t\t}\t\t\t\t\t \\\n\t\telse if PyArray_CHKFLAGS(obj, FORTRAN) { \\\n\t\t\tPyArray_FLAGS(obj) &= ~FORTRAN; \\\n\t\t\tPyArray_FLAGS(obj) |= CONTIGUOUS; \\\n\t\t}\t\t\t\t\t \\\n\t}\n\nextern\nPyArrayObject* array_from_pyobj(const int type_num,\n\t\t\t\tintp *dims,\n\t\t\t\tconst int rank,\n\t\t\t\tconst int intent,\n\t\t\t\tPyObject *obj) {\n /* Note about reference counting\n -----------------------------\n If the caller returns the array to Python, it must be done with\n Py_BuildValue(\"N\",arr).\n Otherwise, if obj!=arr then the caller must call Py_DECREF(arr).\n */\n\n if (intent & F2PY_INTENT_CACHE) {\n /* Don't expect correct storage order or anything reasonable when\n returning intent(cache) array. */ \n if ((intent & F2PY_INTENT_HIDE)\n\t|| (obj==Py_None)) {\n PyArrayObject *arr = NULL;\n CHECK_DIMS_DEFINED(rank,dims,\"optional,intent(cache) must\"\n\t\t\t \" have defined dimensions.\\n\");\n arr = (PyArrayObject *)PyArray_SimpleNew(rank,dims,type_num);\n ARR_IS_NULL(arr==NULL,\"PyArray_SimpleNew failed: optional,intent(cache)\\n\");\n return arr;\n }\n if (PyArray_Check(obj) \n\t&& PyArray_ISONESEGMENT(obj)\n\t&& HAS_PROPER_ELSIZE((PyArrayObject *)obj,type_num)\n\t) {\n if (check_and_fix_dimensions((PyArrayObject *)obj,rank,dims))\n\treturn NULL; /*XXX: set exception */\n {\n\tif (intent & F2PY_INTENT_OUT)\n\t Py_INCREF(obj);\n\treturn (PyArrayObject *)obj;\n }\n }\n ARR_IS_NULL(1,\"intent(cache) must be contiguous array with a proper elsize.\\n\");\n }\n\n if (intent & F2PY_INTENT_HIDE) {\n PyArrayObject *arr = NULL;\n CHECK_DIMS_DEFINED(rank,dims,\"intent(hide) must have defined dimensions.\\n\");\n arr = (PyArrayObject *)\n PyArray_New(&PyArray_Type, rank, dims, type_num,\n\t\t NULL,NULL,0,\n\t\t !(intent&F2PY_INTENT_C),\n\t\t NULL);\n ARR_IS_NULL(arr==NULL,\"PyArray_New failed: intent(hide)\\n\");\n PyArray_FILLWBYTE(arr, 0);\n return arr;\n }\n\n if (PyArray_Check(obj)) { /* here we have always intent(in) or\n\t\t\t intent(inout) or intent(inplace) */\n PyArrayObject *arr = (PyArrayObject *)obj;\n\n if (check_and_fix_dimensions(arr,rank,dims))\n return NULL; /*XXX: set exception */\n\n if ((! (intent & F2PY_INTENT_COPY))\n\t&& HAS_PROPER_ELSIZE(arr,type_num)\n\t&& PyArray_CanCastSafely(arr->descr->type_num,type_num)\n\t) {\n if ((intent & F2PY_INTENT_C)?PyArray_ISCARRAY(arr):PyArray_ISFARRAY(arr)) {\n\tif ((intent & F2PY_INTENT_OUT)) {\n\t Py_INCREF(arr);\n\t}\n\treturn arr;\n }\n }\n\n {\n PyArrayObject *retarr = (PyArrayObject *) \\\n\tPyArray_New(&PyArray_Type, rank, dims, type_num,\n\t\t NULL,NULL,0,\n\t\t !(intent&F2PY_INTENT_C),\n\t\t NULL);\n\n ARR_IS_NULL(retarr==NULL,\"PyArray_New failed: intent(in,copy)\\n\");\n if (PyArray_CopyInto(retarr, arr)) {\n\tPy_DECREF(retarr);\n\treturn NULL;\n }\n if (intent & F2PY_INTENT_INPLACE) {\n\tif (swap_arrays(arr,retarr))\n\t return NULL;\n\tPy_XDECREF(retarr);\n\tif (intent & F2PY_INTENT_OUT)\n\t Py_INCREF(arr);\t\n } else {\n\tarr = retarr;\n }\n }\n return arr;\n }\n\n if ((obj==Py_None) && (intent & F2PY_OPTIONAL)) {\n PyArrayObject *arr = NULL;\n CHECK_DIMS_DEFINED(rank,dims,\"optional must have defined dimensions.\\n\");\n arr = (PyArrayObject *)\n PyArray_New(&PyArray_Type, rank, dims, type_num,\n\t\t NULL,NULL,0,\n\t\t !(intent&F2PY_INTENT_C),\n\t\t NULL);\n ARR_IS_NULL(arr==NULL,\"PyArray_New failed: optional\\n\");\n PyArray_FILLWBYTE(arr, 0);\n return arr;\n }\n\n if ((intent & F2PY_INTENT_INOUT) || (intent & F2PY_INTENT_INPLACE)) {\n ARR_IS_NULL(1,\"intent(inout)|intent(inplace) argument must be an array.\\n\");\n }\n\n {\n PyArray_Typecode typecode = {type_num, 0, 0};\n PyArrayObject *arr = (PyArrayObject *) \\\n PyArray_FromAny(obj,&typecode, 0,0,\n\t\t ((intent & F2PY_INTENT_C)?CARRAY_FLAGS:FARRAY_FLAGS));\n ARR_IS_NULL(arr==NULL,\"PyArray_FromAny failed: not a sequence.\\n\");\n if (check_and_fix_dimensions(arr,rank,dims))\n return NULL; /*XXX: set exception */\n return arr;\n }\n\n}\n\nextern\nPyArrayObject* old_array_from_pyobj(const int type_num,\n\t\t\t\tintp *dims,\n\t\t\t\tconst int rank,\n\t\t\t\tconst int intent,\n\t\t\t\tPyObject *obj) {\n /* Note about reference counting\n -----------------------------\n If the caller returns the array to Python, it must be done with\n Py_BuildValue(\"N\",arr).\n Otherwise, if obj!=arr then the caller must call Py_DECREF(arr).\n */\n if (intent & F2PY_INTENT_CACHE) {\n /* Don't expect correct storage order or anything reasonable when\n returning intent(cache) array. */ \n if ((intent & F2PY_INTENT_HIDE)\n\t|| (obj==Py_None)) {\n PyArrayObject *arr = NULL;\n CHECK_DIMS_DEFINED(rank,dims,\"optional,intent(cache) must\"\n\t\t\t \" have defined dimensions.\\n\");\n arr = (PyArrayObject *)PyArray_SimpleNew(rank,dims,type_num);\n ARR_IS_NULL(arr==NULL,\"FromDims failed: optional,intent(cache)\\n\");\n memset(arr->data, 0, PyArray_NBYTES(arr));\n/* if (intent & F2PY_INTENT_OUT) */\n/* \tPy_INCREF(arr); */\n return arr;\n }\n\n if (PyArray_Check(obj) \n\t&& PyArray_ISONESEGMENT(obj)\n\t&& HAS_PROPER_ELSIZE((PyArrayObject *)obj,type_num)\n\t) {\n if (check_and_fix_dimensions((PyArrayObject *)obj,rank,dims))\n\treturn NULL; /*XXX: set exception */\n {\n\tPyArrayObject *obj2;\n\tif (intent & F2PY_INTENT_OUT)\n\t Py_INCREF(obj);\n\tobj2 = (PyArrayObject *) obj;\n\treturn obj2;\n }\n }\n ARR_IS_NULL(1,\"intent(cache) must be contiguous array with a proper elsize.\\n\");\n }\n\n if (intent & F2PY_INTENT_HIDE) {\n PyArrayObject *arr = NULL;\n CHECK_DIMS_DEFINED(rank,dims,\"intent(hide) must have defined dimensions.\\n\");\n arr = (PyArrayObject *)PyArray_SimpleNew(rank, dims, type_num);\n ARR_IS_NULL(arr==NULL,\"FromDims failed: intent(hide)\\n\");\n memset(arr->data, 0, PyArray_NBYTES(arr));\n if (intent & F2PY_INTENT_OUT) {\n if ((!(intent & F2PY_INTENT_C)) && (rank>1)) {\n\ttranspose_strides(arr);\n\tarr->flags &= ~CONTIGUOUS;\n\tarr->flags |= FORTRAN;\n }\n/* Py_INCREF(arr); */\n }\n return arr;\n }\n\n if (PyArray_Check(obj)) { /* here we have always intent(in) or\n\t\t\t intent(inout) or intent(inplace) */\n PyArrayObject *arr;\n int is_cont;\n\n arr = (PyArrayObject *)obj;\n is_cont = (intent & F2PY_INTENT_C) ? \n (ISCONTIGUOUS(arr)) : (2*array_has_column_major_storage(arr));\n if (check_and_fix_dimensions(arr,rank,dims))\n return NULL; /*XXX: set exception */\n if ((intent & F2PY_INTENT_COPY)\n\t|| (! (is_cont\n\t && HAS_PROPER_ELSIZE(arr,type_num)\n\t && PyArray_CanCastSafely(arr->descr->type_num,type_num)\n\t /* Make PyArray_CanCastSafely safer for 64-bit machines: */\n\t /* && (arr->descr->type_num==PyArray_LONG?type_num!=PyArray_DOUBLE:1)*/\n\t ))) {\n PyArrayObject *tmp_arr = NULL;\n if (intent & F2PY_INTENT_INOUT) {\n\tARR_IS_NULL(1,\"intent(inout) array must be contiguous and\"\n\t\t \" with a proper type and size.\\n\")\n\t }\n if ((rank>1) && (! (intent & F2PY_INTENT_C))) {\n\tlazy_transpose(arr);\n\t_lazy_transpose_update_flags(arr);\n }\n/* if (PyArray_CanCastSafely(arr->descr->type_num,type_num)) { */\n/* \ttmp_arr = (PyArrayObject *)PyArray_CopyFromObject(obj,type_num,0,0); */\n/* \tARR_IS_NULL(arr==NULL,\"CopyFromObject failed: array.\\n\"); */\n/* } else */\n {\n\ttmp_arr = (PyArrayObject *)PyArray_SimpleNew(arr->nd,\n\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t type_num);\n\tARR_IS_NULL(tmp_arr==NULL,\"FromDims failed: array with unsafe cast.\\n\");\n\tif (copy_ND_array(arr,tmp_arr))\n\t ARR_IS_NULL(1,\"copy_ND_array failed: array with unsafe cast.\\n\");\n }\n if ((rank>1) && (! (intent & F2PY_INTENT_C))) {\n\tlazy_transpose(arr);\n\t_lazy_transpose_update_flags(arr);\n\tlazy_transpose(tmp_arr);\n\ttmp_arr->flags &= ~CONTIGUOUS;\n\ttmp_arr->flags |= FORTRAN;\n }\n if (intent & F2PY_INTENT_INPLACE) {\n\tif (swap_arrays(arr,tmp_arr))\n\t return NULL;\n\tPy_XDECREF(tmp_arr);\n\tif (intent & F2PY_INTENT_OUT)\n\t Py_INCREF(arr);\n } else {\n\tarr = tmp_arr;\n }\n } else {\n if ((intent & F2PY_INTENT_OUT)) {\n\tPy_INCREF(arr);\n }\n }\n return arr;\n }\n\n if ((obj==Py_None) && (intent & F2PY_OPTIONAL)) {\n PyArrayObject *arr = NULL;\n CHECK_DIMS_DEFINED(rank,dims,\"optional must have defined dimensions.\\n\"); \n arr = (PyArrayObject *)PyArray_SimpleNew(rank,dims,type_num);\n ARR_IS_NULL(arr==NULL,\"FromDims failed: optional.\\n\");\n memset(arr->data, 0, PyArray_NBYTES(arr));\n if (intent & F2PY_INTENT_OUT) {\n if ((!(intent & F2PY_INTENT_C)) && (rank>1)) {\n\ttranspose_strides(arr);\n\tarr->flags &= ~CONTIGUOUS;\n\tarr->flags |= FORTRAN;\n }\n/* Py_INCREF(arr); */\n }\n return arr;\n }\n\n if ((intent & F2PY_INTENT_INOUT) || (intent & F2PY_INTENT_INPLACE)) {\n ARR_IS_NULL(1,\"intent(inout)|intent(inplace) argument must be an array.\\n\");\n }\n\n {\n PyArrayObject *arr = (PyArrayObject *) \\\n PyArray_ContiguousFromObject(obj,type_num,0,0);\n ARR_IS_NULL(arr==NULL,\"ContiguousFromObject failed: not a sequence.\\n\");\n if (check_and_fix_dimensions(arr,rank,dims))\n return NULL; /*XXX: set exception */\n\n if ((rank>1) && (! (intent & F2PY_INTENT_C))) {\n PyArrayObject *tmp_arr = NULL;\n if (rank == 2) {\n\t tmp_arr = (PyArrayObject *) PyArray_CopyAndTranspose((PyObject *)arr);\n\t PyArray_UpdateFlags(tmp_arr, CONTIGUOUS | FORTRAN);\n }\n else {\n\t lazy_transpose(arr);\n\t arr->flags &= ~CONTIGUOUS;\n\t arr->flags |= FORTRAN;\n\t tmp_arr = (PyArrayObject *) PyArray_Copy(arr);\n }\n#ifdef F2PY_REPORT_ON_ARRAY_COPY\n f2py_report_on_array_copy(tmp_arr,\"PyArray_Copy\");\n#endif\n Py_DECREF(arr);\n arr = tmp_arr;\n ARR_IS_NULL(arr==NULL,\"Copy(Array) failed: intent(fortran)\\n\");\n lazy_transpose(arr);\n _lazy_transpose_update_flags(arr);\n }\n/* if (intent & F2PY_INTENT_OUT) */\n/* Py_INCREF(arr); */\n return arr;\n }\n\n}\n\n /*****************************************/\n /* Helper functions for array_from_pyobj */\n /*****************************************/\n\nextern\nint array_has_column_major_storage(const PyArrayObject *ap) {\n /* array_has_column_major_storage(a) is equivalent to\n transpose(a).iscontiguous() but more efficient.\n\n This function can be used in order to decide whether to use a\n Fortran or C version of a wrapped function. This is relevant, for\n example, in choosing a clapack or flapack function depending on\n the storage order of array arguments.\n */\n int sd;\n int i;\n sd = PyArray_ITEMSIZE(ap);\n for (i=0;ind;++i) {\n if (ap->dimensions[i] == 0) return 1;\n if (ap->strides[i] != sd) return 0;\n sd *= ap->dimensions[i];\n }\n return 1;\n}\n\nstatic\nint check_and_fix_dimensions(const PyArrayObject* arr,const int rank,intp *dims) {\n /*\n This function fills in blanks (that are -1\\'s) in dims list using\n the dimensions from arr. It also checks that non-blank dims will\n match with the corresponding values in arr dimensions.\n */\n const intp arr_size = (arr->nd)?PyArray_Size((PyObject *)arr):1;\n\n if (rank > arr->nd) { /* [1,2] -> [[1],[2]]; 1 -> [[1]] */\n intp new_size = 1;\n int free_axe = -1;\n int i;\n /* Fill dims where -1 or 0; check dimensions; calc new_size; */\n for(i=0;ind;++i) { \n if (dims[i] >= 0) {\n\tif (dims[i]!=arr->dimensions[i]) {\n\t fprintf(stderr,\"%d-th dimension must be fixed to %\" INTP_FMT\n\t\t \" but got %\" INTP_FMT \"\\n\",\n\t\t i,dims[i], arr->dimensions[i]);\n\t return 1;\n\t}\n\tif (!dims[i]) dims[i] = 1;\n } else {\n\tdims[i] = arr->dimensions[i] ? arr->dimensions[i] : 1;\n }\n new_size *= dims[i];\n }\n for(i=arr->nd;i1) {\n\tfprintf(stderr,\"%d-th dimension must be %\" INTP_FMT\n\t\t\" but got 0 (not defined).\\n\",\n\t\ti,dims[i]);\n\treturn 1;\n } else if (free_axe<0)\n\tfree_axe = i;\n else\n\tdims[i] = 1;\n if (free_axe>=0) {\n dims[free_axe] = arr_size/new_size;\n new_size *= dims[free_axe];\n }\n if (new_size != arr_size) {\n fprintf(stderr,\"confused: new_size=%\" INTP_FMT\n\t \", arr_size=%\" INTP_FMT \" (maybe too many free\"\n\t \" indices)\\n\", new_size,arr_size);\n return 1;\n }\n } else { /* [[1,2]] -> [[1],[2]] */\n int i,j;\n intp d;\n int effrank;\n intp size;\n for (i=0,effrank=0;ind;++i)\n if (arr->dimensions[i]>1) ++effrank;\n if (dims[rank-1]>=0)\n if (effrank>rank) {\n\tfprintf(stderr,\"too many axes: %d (effrank=%d), expected rank=%d\\n\",\n\t\tarr->nd,effrank,rank);\n\treturn 1;\n }\n for (i=0,j=0;ind && arr->dimensions[j]<2) ++j;\n if (j>=arr->nd) d = 1;\n else d = arr->dimensions[j++];\n if (dims[i]>=0) {\n\tif (d>1 && d!=dims[i]) {\n\t fprintf(stderr,\"%d-th dimension must be fixed to %\" INTP_FMT \n\t\t \" but got %\" INTP_FMT \" (real index=%d)\\n\",\n\t\t i,dims[i],d,j-1);\n\t return 1;\t \n\t}\n\tif (!dims[i]) dims[i] = 1;\n } else\n\tdims[i] = d;\n }\n for (i=rank;ind;++i) { /* [[1,2],[3,4]] -> [1,2,3,4] */\n while (jnd && arr->dimensions[j]<2) ++j;\n if (j>=arr->nd) d = 1;\n else d = arr->dimensions[j++];\n dims[rank-1] *= d;\n }\n for (i=0,size=1;ind);\n for (i=0;ind;++i) fprintf(stderr,\" %\" INTP_FMT,arr->dimensions[i]);\n fprintf(stderr,\" ]\\n\");\n return 1;\n }\n }\n return 0;\n}\n\n/* End of file: array_from_pyobj.c */\n\n/************************* copy_ND_array *******************************/\n\nextern\nint copy_ND_array(const PyArrayObject *in, PyArrayObject *out)\n{\n#ifdef F2PY_REPORT_ON_ARRAY_COPY\n f2py_report_on_array_copy(out, \"CopyInto\");\n#endif\n return PyArray_CopyInto(out, (PyArrayObject *)in);\n}\n\n#ifdef __cplusplus\n}\n#endif\n/************************* EOF fortranobject.c *******************************/\n", "methods": [ { "name": "PyFortranObject_New", "long_name": "PyFortranObject_New( FortranDataDef * defs , f2py_void_func init)", "filename": "fortranobject.c", "nloc": 31, "complexity": 11, "token_count": 312, "parameters": [ "defs", "init" ], "start_line": 20, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 1 }, { "name": "PyFortranObject_NewAsAttr", "long_name": "PyFortranObject_NewAsAttr( FortranDataDef * defs)", "filename": "fortranobject.c", "nloc": 9, "complexity": 3, "token_count": 69, "parameters": [ "defs" ], "start_line": 53, "end_line": 61, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "fortran_dealloc", "long_name": "fortran_dealloc( PyFortranObject * fp)", "filename": "fortranobject.c", "nloc": 4, "complexity": 1, "token_count": 20, "parameters": [ "fp" ], "start_line": 66, "end_line": 69, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "fortran_doc", "long_name": "fortran_doc( FortranDataDef def)", "filename": "fortranobject.c", "nloc": 46, "complexity": 21, "token_count": 434, "parameters": [ "def" ], "start_line": 78, "end_line": 123, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 46, "top_nesting_level": 1 }, { "name": "set_data", "long_name": "set_data( char * d , intp * f)", "filename": "fortranobject.c", "nloc": 6, "complexity": 2, "token_count": 30, "parameters": [ "d", "f" ], "start_line": 126, "end_line": 132, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "fortran_getattr", "long_name": "fortran_getattr( PyFortranObject * fp , char * name)", "filename": "fortranobject.c", "nloc": 52, "complexity": 18, "token_count": 519, "parameters": [ "fp", "name" ], "start_line": 135, "end_line": 187, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "top_nesting_level": 1 }, { "name": "fortran_setattr", "long_name": "fortran_setattr( PyFortranObject * fp , char * name , PyObject * v)", "filename": "fortranobject.c", "nloc": 59, "complexity": 22, "token_count": 647, "parameters": [ "fp", "name", "v" ], "start_line": 190, "end_line": 250, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 61, "top_nesting_level": 1 }, { "name": "fortran_call", "long_name": "fortran_call( PyFortranObject * fp , PyObject * arg , PyObject * kw)", "filename": "fortranobject.c", "nloc": 16, "complexity": 4, "token_count": 166, "parameters": [ "fp", "arg", "kw" ], "start_line": 253, "end_line": 272, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "f2py_start_clock", "long_name": "f2py_start_clock()", "filename": "fortranobject.c", "nloc": 1, "complexity": 1, "token_count": 12, "parameters": [], "start_line": 313, "end_line": 313, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "f2py_start_call_clock", "long_name": "f2py_start_call_clock()", "filename": "fortranobject.c", "nloc": 4, "complexity": 1, "token_count": 16, "parameters": [], "start_line": 315, "end_line": 318, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "f2py_stop_clock", "long_name": "f2py_stop_clock()", "filename": "fortranobject.c", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [], "start_line": 320, "end_line": 324, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "f2py_stop_call_clock", "long_name": "f2py_stop_call_clock()", "filename": "fortranobject.c", "nloc": 7, "complexity": 1, "token_count": 44, "parameters": [], "start_line": 326, "end_line": 332, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "f2py_cb_start_clock", "long_name": "f2py_cb_start_clock()", "filename": "fortranobject.c", "nloc": 1, "complexity": 1, "token_count": 12, "parameters": [], "start_line": 334, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "f2py_cb_start_call_clock", "long_name": "f2py_cb_start_call_clock()", "filename": "fortranobject.c", "nloc": 4, "complexity": 1, "token_count": 16, "parameters": [], "start_line": 336, "end_line": 339, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "f2py_cb_stop_clock", "long_name": "f2py_cb_stop_clock()", "filename": "fortranobject.c", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [], "start_line": 341, "end_line": 345, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "f2py_cb_stop_call_clock", "long_name": "f2py_cb_stop_call_clock()", "filename": "fortranobject.c", "nloc": 7, "complexity": 1, "token_count": 44, "parameters": [], "start_line": 347, "end_line": 353, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "f2py_report_on_exit", "long_name": "f2py_report_on_exit( int exit_flag , * name)", "filename": "fortranobject.c", "nloc": 24, "complexity": 2, "token_count": 146, "parameters": [ "exit_flag", "name" ], "start_line": 357, "end_line": 381, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "f2py_report_on_array_copy", "long_name": "f2py_report_on_array_copy( PyArrayObject * arr)", "filename": "fortranobject.c", "nloc": 7, "complexity": 2, "token_count": 43, "parameters": [ "arr" ], "start_line": 387, "end_line": 393, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "f2py_report_on_array_copy_fromany", "long_name": "f2py_report_on_array_copy_fromany()", "filename": "fortranobject.c", "nloc": 3, "complexity": 1, "token_count": 13, "parameters": [], "start_line": 394, "end_line": 396, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "count_nonpos", "long_name": "count_nonpos( const int rank , const intp * dims)", "filename": "fortranobject.c", "nloc": 9, "complexity": 3, "token_count": 48, "parameters": [ "rank", "dims" ], "start_line": 428, "end_line": 436, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "dump_attrs", "long_name": "dump_attrs( const PyArrayObject * arr)", "filename": "fortranobject.c", "nloc": 16, "complexity": 3, "token_count": 117, "parameters": [ "arr" ], "start_line": 443, "end_line": 458, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "swap_arrays", "long_name": "swap_arrays( PyArrayObject * arr1 , PyArrayObject * arr2)", "filename": "fortranobject.c", "nloc": 11, "complexity": 1, "token_count": 124, "parameters": [ "arr1", "arr2" ], "start_line": 463, "end_line": 474, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "array_from_pyobj", "long_name": "array_from_pyobj( const int type_num , intp * dims , const int rank , const int intent , PyObject * obj)", "filename": "fortranobject.c", "nloc": 130, "complexity": 42, "token_count": 833, "parameters": [ "type_num", "dims", "rank", "intent", "obj" ], "start_line": 477, "end_line": 634, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 158, "top_nesting_level": 1 }, { "name": "check_and_fix_dimensions", "long_name": "check_and_fix_dimensions( const PyArrayObject * arr , const int rank , intp * dims)", "filename": "fortranobject.c", "nloc": 88, "complexity": 33, "token_count": 724, "parameters": [ "arr", "rank", "dims" ], "start_line": 641, "end_line": 735, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 95, "top_nesting_level": 1 }, { "name": "copy_ND_array", "long_name": "copy_ND_array( const PyArrayObject * arr , PyArrayObject * out)", "filename": "fortranobject.c", "nloc": 5, "complexity": 1, "token_count": 27, "parameters": [ "arr", "out" ], "start_line": 742, "end_line": 746, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 } ], "methods_before": [ { "name": "PyFortranObject_New", "long_name": "PyFortranObject_New( FortranDataDef * defs , f2py_void_func init)", "filename": "fortranobject.c", "nloc": 31, "complexity": 11, "token_count": 312, "parameters": [ "defs", "init" ], "start_line": 22, "end_line": 52, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 1 }, { "name": "PyFortranObject_NewAsAttr", "long_name": "PyFortranObject_NewAsAttr( FortranDataDef * defs)", "filename": "fortranobject.c", "nloc": 9, "complexity": 3, "token_count": 69, "parameters": [ "defs" ], "start_line": 55, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "fortran_dealloc", "long_name": "fortran_dealloc( PyFortranObject * fp)", "filename": "fortranobject.c", "nloc": 4, "complexity": 1, "token_count": 20, "parameters": [ "fp" ], "start_line": 68, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "fortran_doc", "long_name": "fortran_doc( FortranDataDef def)", "filename": "fortranobject.c", "nloc": 46, "complexity": 21, "token_count": 434, "parameters": [ "def" ], "start_line": 80, "end_line": 125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 46, "top_nesting_level": 1 }, { "name": "set_data", "long_name": "set_data( char * d , intp * f)", "filename": "fortranobject.c", "nloc": 6, "complexity": 2, "token_count": 30, "parameters": [ "d", "f" ], "start_line": 128, "end_line": 134, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "fortran_getattr", "long_name": "fortran_getattr( PyFortranObject * fp , char * name)", "filename": "fortranobject.c", "nloc": 52, "complexity": 18, "token_count": 519, "parameters": [ "fp", "name" ], "start_line": 137, "end_line": 189, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "top_nesting_level": 1 }, { "name": "fortran_setattr", "long_name": "fortran_setattr( PyFortranObject * fp , char * name , PyObject * v)", "filename": "fortranobject.c", "nloc": 59, "complexity": 22, "token_count": 647, "parameters": [ "fp", "name", "v" ], "start_line": 192, "end_line": 252, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 61, "top_nesting_level": 1 }, { "name": "fortran_call", "long_name": "fortran_call( PyFortranObject * fp , PyObject * arg , PyObject * kw)", "filename": "fortranobject.c", "nloc": 16, "complexity": 4, "token_count": 166, "parameters": [ "fp", "arg", "kw" ], "start_line": 255, "end_line": 274, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "f2py_start_clock", "long_name": "f2py_start_clock()", "filename": "fortranobject.c", "nloc": 1, "complexity": 1, "token_count": 12, "parameters": [], "start_line": 315, "end_line": 315, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "f2py_start_call_clock", "long_name": "f2py_start_call_clock()", "filename": "fortranobject.c", "nloc": 4, "complexity": 1, "token_count": 16, "parameters": [], "start_line": 317, "end_line": 320, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "f2py_stop_clock", "long_name": "f2py_stop_clock()", "filename": "fortranobject.c", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [], "start_line": 322, "end_line": 326, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "f2py_stop_call_clock", "long_name": "f2py_stop_call_clock()", "filename": "fortranobject.c", "nloc": 7, "complexity": 1, "token_count": 44, "parameters": [], "start_line": 328, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "f2py_cb_start_clock", "long_name": "f2py_cb_start_clock()", "filename": "fortranobject.c", "nloc": 1, "complexity": 1, "token_count": 12, "parameters": [], "start_line": 336, "end_line": 336, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "f2py_cb_start_call_clock", "long_name": "f2py_cb_start_call_clock()", "filename": "fortranobject.c", "nloc": 4, "complexity": 1, "token_count": 16, "parameters": [], "start_line": 338, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "f2py_cb_stop_clock", "long_name": "f2py_cb_stop_clock()", "filename": "fortranobject.c", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [], "start_line": 343, "end_line": 347, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "f2py_cb_stop_call_clock", "long_name": "f2py_cb_stop_call_clock()", "filename": "fortranobject.c", "nloc": 7, "complexity": 1, "token_count": 44, "parameters": [], "start_line": 349, "end_line": 355, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "f2py_report_on_exit", "long_name": "f2py_report_on_exit( int exit_flag , * name)", "filename": "fortranobject.c", "nloc": 24, "complexity": 2, "token_count": 146, "parameters": [ "exit_flag", "name" ], "start_line": 359, "end_line": 383, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "f2py_report_on_array_copy", "long_name": "f2py_report_on_array_copy( PyArrayObject * arr , char * func_name)", "filename": "fortranobject.c", "nloc": 7, "complexity": 2, "token_count": 49, "parameters": [ "arr", "func_name" ], "start_line": 389, "end_line": 395, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "lazy_transpose", "long_name": "lazy_transpose( PyArrayObject * arr)", "filename": "fortranobject.c", "nloc": 14, "complexity": 3, "token_count": 122, "parameters": [ "arr" ], "start_line": 401, "end_line": 421, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "transpose_strides", "long_name": "transpose_strides( PyArrayObject * arr)", "filename": "fortranobject.c", "nloc": 11, "complexity": 3, "token_count": 75, "parameters": [ "arr" ], "start_line": 424, "end_line": 434, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "count_nonpos", "long_name": "count_nonpos( const int rank , const intp * dims)", "filename": "fortranobject.c", "nloc": 9, "complexity": 3, "token_count": 48, "parameters": [ "rank", "dims" ], "start_line": 477, "end_line": 485, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "dump_attrs", "long_name": "dump_attrs( const PyArrayObject * arr)", "filename": "fortranobject.c", "nloc": 16, "complexity": 3, "token_count": 117, "parameters": [ "arr" ], "start_line": 492, "end_line": 507, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "swap_arrays", "long_name": "swap_arrays( PyArrayObject * arr1 , PyArrayObject * arr2)", "filename": "fortranobject.c", "nloc": 11, "complexity": 1, "token_count": 124, "parameters": [ "arr1", "arr2" ], "start_line": 512, "end_line": 523, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "array_from_pyobj", "long_name": "array_from_pyobj( const int type_num , intp * dims , const int rank , const int intent , PyObject * obj)", "filename": "fortranobject.c", "nloc": 105, "complexity": 28, "token_count": 628, "parameters": [ "type_num", "dims", "rank", "intent", "obj" ], "start_line": 541, "end_line": 665, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 125, "top_nesting_level": 1 }, { "name": "old_array_from_pyobj", "long_name": "old_array_from_pyobj( const int type_num , intp * dims , const int rank , const int intent , PyObject * obj)", "filename": "fortranobject.c", "nloc": 146, "complexity": 42, "token_count": 904, "parameters": [ "type_num", "dims", "rank", "intent", "obj" ], "start_line": 668, "end_line": 845, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 178, "top_nesting_level": 1 }, { "name": "array_has_column_major_storage", "long_name": "array_has_column_major_storage( const PyArrayObject * ap)", "filename": "fortranobject.c", "nloc": 11, "complexity": 4, "token_count": 80, "parameters": [ "ap" ], "start_line": 852, "end_line": 870, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 1 }, { "name": "check_and_fix_dimensions", "long_name": "check_and_fix_dimensions( const PyArrayObject * arr , const int rank , intp * dims)", "filename": "fortranobject.c", "nloc": 88, "complexity": 33, "token_count": 724, "parameters": [ "arr", "rank", "dims" ], "start_line": 873, "end_line": 967, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 95, "top_nesting_level": 1 }, { "name": "copy_ND_array", "long_name": "copy_ND_array( const PyArrayObject * in , PyArrayObject * out)", "filename": "fortranobject.c", "nloc": 5, "complexity": 2, "token_count": 32, "parameters": [ "in", "out" ], "start_line": 974, "end_line": 980, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "copy_ND_array", "long_name": "copy_ND_array( const PyArrayObject * arr , PyArrayObject * out)", "filename": "fortranobject.c", "nloc": 5, "complexity": 1, "token_count": 27, "parameters": [ "arr", "out" ], "start_line": 742, "end_line": 746, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "f2py_report_on_array_copy", "long_name": "f2py_report_on_array_copy( PyArrayObject * arr)", "filename": "fortranobject.c", "nloc": 7, "complexity": 2, "token_count": 43, "parameters": [ "arr" ], "start_line": 387, "end_line": 393, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "copy_ND_array", "long_name": "copy_ND_array( const PyArrayObject * in , PyArrayObject * out)", "filename": "fortranobject.c", "nloc": 5, "complexity": 2, "token_count": 32, "parameters": [ "in", "out" ], "start_line": 974, "end_line": 980, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "f2py_report_on_array_copy_fromany", "long_name": "f2py_report_on_array_copy_fromany()", "filename": "fortranobject.c", "nloc": 3, "complexity": 1, "token_count": 13, "parameters": [], "start_line": 394, "end_line": 396, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "array_from_pyobj", "long_name": "array_from_pyobj( const int type_num , intp * dims , const int rank , const int intent , PyObject * obj)", "filename": "fortranobject.c", "nloc": 130, "complexity": 42, "token_count": 833, "parameters": [ "type_num", "dims", "rank", "intent", "obj" ], "start_line": 477, "end_line": 634, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 158, "top_nesting_level": 1 }, { "name": "lazy_transpose", "long_name": "lazy_transpose( PyArrayObject * arr)", "filename": "fortranobject.c", "nloc": 14, "complexity": 3, "token_count": 122, "parameters": [ "arr" ], "start_line": 401, "end_line": 421, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "old_array_from_pyobj", "long_name": "old_array_from_pyobj( const int type_num , intp * dims , const int rank , const int intent , PyObject * obj)", "filename": "fortranobject.c", "nloc": 146, "complexity": 42, "token_count": 904, "parameters": [ "type_num", "dims", "rank", "intent", "obj" ], "start_line": 668, "end_line": 845, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 178, "top_nesting_level": 1 }, { "name": "array_has_column_major_storage", "long_name": "array_has_column_major_storage( const PyArrayObject * ap)", "filename": "fortranobject.c", "nloc": 11, "complexity": 4, "token_count": 80, "parameters": [ "ap" ], "start_line": 852, "end_line": 870, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 1 }, { "name": "transpose_strides", "long_name": "transpose_strides( PyArrayObject * arr)", "filename": "fortranobject.c", "nloc": 11, "complexity": 3, "token_count": 75, "parameters": [ "arr" ], "start_line": 424, "end_line": 434, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "f2py_report_on_array_copy", "long_name": "f2py_report_on_array_copy( PyArrayObject * arr , char * func_name)", "filename": "fortranobject.c", "nloc": 7, "complexity": 2, "token_count": 49, "parameters": [ "arr", "func_name" ], "start_line": 389, "end_line": 395, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 } ], "nloc": 612, "complexity": 178, "token_count": 4742, "diff_parsed": { "added": [ " This file implements: FortranObject, array_from_pyobj, copy_ND_array", "static void f2py_report_on_array_copy(PyArrayObject* arr) {", " fprintf(stderr,\"copied an array: size=%ld, elsize=%d\\n\",", "\t arr_size, PyArray_ITEMSIZE(arr));", "static void f2py_report_on_array_copy_fromany(void) {", " fprintf(stderr,\"created an array from object\\n\");", "#define F2PY_REPORT_ON_ARRAY_COPY_FROMARR f2py_report_on_array_copy((PyArrayObject *)arr)", "#define F2PY_REPORT_ON_ARRAY_COPY_FROMANY f2py_report_on_array_copy_fromany()", "#else", "#define F2PY_REPORT_ON_ARRAY_COPY_FROMARR", "#define F2PY_REPORT_ON_ARRAY_COPY_FROMANY", "#endif", "", " Note on intent(cache,out,..)", " ---------------------", " Don't expect correct data when returning intent(cache) array.", " */", " char mess[200];", " PyArrayObject *arr = NULL;", " PyArray_Descr *descr = PyArray_DescrFromType(type_num);", "", " if ((intent & F2PY_INTENT_HIDE)", " || ((intent & F2PY_INTENT_CACHE) && (obj==Py_None))", " || ((intent & F2PY_OPTIONAL) && (obj==Py_None))", " ) {", " /* intent(cache), optional, intent(hide) */", " if (count_nonpos(rank,dims)) {", " int i;", " sprintf(mess,\"failed to create intent(cache|hide)|optional array\"", "\t \"-- must have defined dimensions but got (\");", " for(i=0;i=descr->elsize) {", "\tif (check_and_fix_dimensions((PyArrayObject *)obj,rank,dims))", "\t return NULL; /*XXX: set exception */", "\tif (intent & F2PY_INTENT_OUT)", "\t Py_INCREF(obj);", "\treturn (PyArrayObject *)obj;", " }", " sprintf(mess,\"failed to initialize intent(cache) array\");", " if (!PyArray_ISONESEGMENT(obj))", "\tsprintf(mess+strlen(mess),\" -- input must be in one segment\");", " if (PyArray_ITEMSIZE(arr)elsize)", "\tsprintf(mess+strlen(mess),\" -- expected at least elsize=%d but got %d\",", "\t\tdescr->elsize,PyArray_ITEMSIZE(arr)", "\t\t);", " PyErr_SetString(PyExc_ValueError,mess);", " return NULL;", " }", "", " /* here we have always intent(in) or intent(inout) or intent(inplace) */", "\t&& PyArray_ITEMSIZE(arr)==descr->elsize", "\t/* Returning input array */", " if (intent & F2PY_INTENT_INOUT) {", " sprintf(mess,\"failed to initialize intent(inout) array\");", " if ((intent & F2PY_INTENT_C) && !PyArray_ISCARRAY(arr))", "\tsprintf(mess+strlen(mess),\" -- input not contiguous\");", " if (!(intent & F2PY_INTENT_C) && !PyArray_ISFARRAY(arr))", "\tsprintf(mess+strlen(mess),\" -- input not fortran contiguous\");", " if (PyArray_ITEMSIZE(arr)!=descr->elsize)", "\tsprintf(mess+strlen(mess),\" -- expected elsize=%d but got %d\",", "\t\tdescr->elsize,", "\t\tPyArray_ITEMSIZE(arr)", "\t\t);", " if (!(PyArray_CanCastSafely(arr->descr->type_num,type_num)))", "\tsprintf(mess+strlen(mess),\" -- cannot cast safely from '%c' to '%c'\",", "\t\tarr->descr->type,descr->type);", " PyErr_SetString(PyExc_ValueError,mess);", " return NULL;", " }", "", " /* here we have always intent(in) or intent(inplace) */", "", " if (retarr==NULL)", "\treturn NULL;", " F2PY_REPORT_ON_ARRAY_COPY_FROMARR;", "\t return NULL; /* XXX: set exception */", "\t Py_INCREF(arr);", " if ((intent & F2PY_INTENT_INOUT)", " || (intent & F2PY_INTENT_INPLACE)", " || (intent & F2PY_INTENT_CACHE)) {", " sprintf(mess,\"failed to initialize intent(inout|inplace|cache) array\"", "\t \" -- input must be array but got %s\",", "\t PyString_AsString(PyObject_Str(PyObject_Type(obj)))", "\t );", " PyErr_SetString(PyExc_TypeError,mess);", " return NULL;", " F2PY_REPORT_ON_ARRAY_COPY_FROMANY;", " arr = (PyArrayObject *) \\", " if (arr==NULL)", " return NULL;", "int copy_ND_array(const PyArrayObject *arr, PyArrayObject *out)", " F2PY_REPORT_ON_ARRAY_COPY_FROMARR;", " return PyArray_CopyInto(out, (PyArrayObject *)arr);" ], "deleted": [ " This file implements: FortranObject, array_from_pyobj, copy_ND_array,", " lazy_transpose, transpose_strides,", "\t\t and array_has_column_major_storage.", "static void f2py_report_on_array_copy(PyArrayObject* arr, char* func_name) {", " fprintf(stderr,\"copied an array using %s: size=%ld, elsize=%d\\n\",", "\t func_name, arr_size, PyArray_ITEMSIZE(arr));", "#endif", "", "/************************* lazy_transpose *******************************/", "", "extern", "void lazy_transpose(PyArrayObject* arr) {", " /*", " Changes the order of array strides and dimensions. This", " corresponds to the lazy transpose of a Numeric array in-situ.", " Note that this function is assumed to be used even times for a", " given array. Otherwise, the caller should set flags &= ~CONTIGUOUS.", " */", " int rank, i;", " intp s,j;", " rank = arr->nd;", " if (rank < 2) return;", "", " for(i=0,j=rank-1;istrides[i];", " arr->strides[i] = arr->strides[j];", " arr->strides[j] = s;", " s = arr->dimensions[i];", " arr->dimensions[i] = arr->dimensions[j];", " arr->dimensions[j] = s;", " }", "extern", "void transpose_strides(PyArrayObject* arr) {", " int rank, i;", " intp j;", " rank = arr->nd;", " if (rank < 2) return;", " j = arr->strides[rank-1];", " for(i=0;istrides[i] = j;", " j *= arr->dimensions[i];", " }", "}", "", "#define ARR_IS_NULL(arr_is_NULL,mess) \\", "if (arr_is_NULL) { \\", " fprintf(stderr,\"array_from_pyobj:\" mess); \\", " return NULL; \\", "}", "", "#define CHECK_DIMS_DEFINED(rank,dims,mess) \\", "if (count_nonpos(rank,dims)) { int i;\\", " fprintf(stderr,\"array_from_pyobj:\" mess); \\", " fprintf(stderr,\"rank=%d dimensions=[ \",rank); \\", " for(i=0;ielsize) == PyArray_ITEMSIZE(arr))", "", "\t/* useful after a lazy-transpose to update the flags", "\t quickly", "\t*/", "", "#define _lazy_transpose_update_flags(obj) {\t\t \\", "\t\tif (PyArray_ISCONTIGUOUS(obj)) {\t \\", "\t\t\tPyArray_FLAGS(obj) &= ~CONTIGUOUS; \\", "\t\t\tPyArray_FLAGS(obj) |= FORTRAN; \\", "\t\t}\t\t\t\t\t \\", "\t\telse if PyArray_CHKFLAGS(obj, FORTRAN) { \\", "\t\t\tPyArray_FLAGS(obj) &= ~FORTRAN; \\", "\t\t\tPyArray_FLAGS(obj) |= CONTIGUOUS; \\", "\t\t}\t\t\t\t\t \\", "\t}", "", " */", " if (intent & F2PY_INTENT_CACHE) {", " /* Don't expect correct storage order or anything reasonable when", " returning intent(cache) array. */", " if ((intent & F2PY_INTENT_HIDE)", "\t|| (obj==Py_None)) {", " PyArrayObject *arr = NULL;", " CHECK_DIMS_DEFINED(rank,dims,\"optional,intent(cache) must\"", "\t\t\t \" have defined dimensions.\\n\");", " arr = (PyArrayObject *)PyArray_SimpleNew(rank,dims,type_num);", " ARR_IS_NULL(arr==NULL,\"PyArray_SimpleNew failed: optional,intent(cache)\\n\");", " return arr;", " }", " if (PyArray_Check(obj)", "\t&& PyArray_ISONESEGMENT(obj)", "\t&& HAS_PROPER_ELSIZE((PyArrayObject *)obj,type_num)", "\t) {", " if (check_and_fix_dimensions((PyArrayObject *)obj,rank,dims))", "\treturn NULL; /*XXX: set exception */", " {", "\tif (intent & F2PY_INTENT_OUT)", "\t Py_INCREF(obj);", "\treturn (PyArrayObject *)obj;", " }", " }", " ARR_IS_NULL(1,\"intent(cache) must be contiguous array with a proper elsize.\\n\");", " }", " if (intent & F2PY_INTENT_HIDE) {", " PyArrayObject *arr = NULL;", " CHECK_DIMS_DEFINED(rank,dims,\"intent(hide) must have defined dimensions.\\n\");", " ARR_IS_NULL(arr==NULL,\"PyArray_New failed: intent(hide)\\n\");", " PyArray_FILLWBYTE(arr, 0);", " if (PyArray_Check(obj)) { /* here we have always intent(in) or", "\t\t\t intent(inout) or intent(inplace) */", " PyArrayObject *arr = (PyArrayObject *)obj;", "\t&& HAS_PROPER_ELSIZE(arr,type_num)", "", " ARR_IS_NULL(retarr==NULL,\"PyArray_New failed: intent(in,copy)\\n\");", "\t return NULL;", "\t Py_INCREF(arr);", " if ((obj==Py_None) && (intent & F2PY_OPTIONAL)) {", " PyArrayObject *arr = NULL;", " CHECK_DIMS_DEFINED(rank,dims,\"optional must have defined dimensions.\\n\");", " arr = (PyArrayObject *)", " PyArray_New(&PyArray_Type, rank, dims, type_num,", "\t\t NULL,NULL,0,", "\t\t !(intent&F2PY_INTENT_C),", "\t\t NULL);", " ARR_IS_NULL(arr==NULL,\"PyArray_New failed: optional\\n\");", " PyArray_FILLWBYTE(arr, 0);", " return arr;", " }", "", " if ((intent & F2PY_INTENT_INOUT) || (intent & F2PY_INTENT_INPLACE)) {", " ARR_IS_NULL(1,\"intent(inout)|intent(inplace) argument must be an array.\\n\");", " PyArrayObject *arr = (PyArrayObject *) \\", " ARR_IS_NULL(arr==NULL,\"PyArray_FromAny failed: not a sequence.\\n\");", " if (check_and_fix_dimensions(arr,rank,dims))", " return NULL; /*XXX: set exception */", " return arr;", " }", "", "}", "", "extern", "PyArrayObject* old_array_from_pyobj(const int type_num,", "\t\t\t\tintp *dims,", "\t\t\t\tconst int rank,", "\t\t\t\tconst int intent,", "\t\t\t\tPyObject *obj) {", " /* Note about reference counting", " -----------------------------", " If the caller returns the array to Python, it must be done with", " Py_BuildValue(\"N\",arr).", " Otherwise, if obj!=arr then the caller must call Py_DECREF(arr).", " */", " if (intent & F2PY_INTENT_CACHE) {", " /* Don't expect correct storage order or anything reasonable when", " returning intent(cache) array. */", " if ((intent & F2PY_INTENT_HIDE)", "\t|| (obj==Py_None)) {", " PyArrayObject *arr = NULL;", " CHECK_DIMS_DEFINED(rank,dims,\"optional,intent(cache) must\"", "\t\t\t \" have defined dimensions.\\n\");", " arr = (PyArrayObject *)PyArray_SimpleNew(rank,dims,type_num);", " ARR_IS_NULL(arr==NULL,\"FromDims failed: optional,intent(cache)\\n\");", " memset(arr->data, 0, PyArray_NBYTES(arr));", "/* if (intent & F2PY_INTENT_OUT) */", "/* \tPy_INCREF(arr); */", " return arr;", " }", "", " if (PyArray_Check(obj)", "\t&& PyArray_ISONESEGMENT(obj)", "\t&& HAS_PROPER_ELSIZE((PyArrayObject *)obj,type_num)", "\t) {", " if (check_and_fix_dimensions((PyArrayObject *)obj,rank,dims))", "\treturn NULL; /*XXX: set exception */", " {", "\tPyArrayObject *obj2;", "\tif (intent & F2PY_INTENT_OUT)", "\t Py_INCREF(obj);", "\tobj2 = (PyArrayObject *) obj;", "\treturn obj2;", " }", " }", " ARR_IS_NULL(1,\"intent(cache) must be contiguous array with a proper elsize.\\n\");", " }", "", " if (intent & F2PY_INTENT_HIDE) {", " PyArrayObject *arr = NULL;", " CHECK_DIMS_DEFINED(rank,dims,\"intent(hide) must have defined dimensions.\\n\");", " arr = (PyArrayObject *)PyArray_SimpleNew(rank, dims, type_num);", " ARR_IS_NULL(arr==NULL,\"FromDims failed: intent(hide)\\n\");", " memset(arr->data, 0, PyArray_NBYTES(arr));", " if (intent & F2PY_INTENT_OUT) {", " if ((!(intent & F2PY_INTENT_C)) && (rank>1)) {", "\ttranspose_strides(arr);", "\tarr->flags &= ~CONTIGUOUS;", "\tarr->flags |= FORTRAN;", " }", "/* Py_INCREF(arr); */", " }", " return arr;", " }", "", " if (PyArray_Check(obj)) { /* here we have always intent(in) or", "\t\t\t intent(inout) or intent(inplace) */", " PyArrayObject *arr;", " int is_cont;", "", " arr = (PyArrayObject *)obj;", " is_cont = (intent & F2PY_INTENT_C) ?", " (ISCONTIGUOUS(arr)) : (2*array_has_column_major_storage(arr));", " if (check_and_fix_dimensions(arr,rank,dims))", " return NULL; /*XXX: set exception */", " if ((intent & F2PY_INTENT_COPY)", "\t|| (! (is_cont", "\t && HAS_PROPER_ELSIZE(arr,type_num)", "\t && PyArray_CanCastSafely(arr->descr->type_num,type_num)", "\t /* Make PyArray_CanCastSafely safer for 64-bit machines: */", "\t /* && (arr->descr->type_num==PyArray_LONG?type_num!=PyArray_DOUBLE:1)*/", "\t ))) {", " PyArrayObject *tmp_arr = NULL;", " if (intent & F2PY_INTENT_INOUT) {", "\tARR_IS_NULL(1,\"intent(inout) array must be contiguous and\"", "\t\t \" with a proper type and size.\\n\")", "\t }", " if ((rank>1) && (! (intent & F2PY_INTENT_C))) {", "\tlazy_transpose(arr);", "\t_lazy_transpose_update_flags(arr);", " }", "/* if (PyArray_CanCastSafely(arr->descr->type_num,type_num)) { */", "/* \ttmp_arr = (PyArrayObject *)PyArray_CopyFromObject(obj,type_num,0,0); */", "/* \tARR_IS_NULL(arr==NULL,\"CopyFromObject failed: array.\\n\"); */", "/* } else */", " {", "\ttmp_arr = (PyArrayObject *)PyArray_SimpleNew(arr->nd,", "\t\t\t\t\t\t arr->dimensions,", "\t\t\t\t\t\t type_num);", "\tARR_IS_NULL(tmp_arr==NULL,\"FromDims failed: array with unsafe cast.\\n\");", "\tif (copy_ND_array(arr,tmp_arr))", "\t ARR_IS_NULL(1,\"copy_ND_array failed: array with unsafe cast.\\n\");", " }", " if ((rank>1) && (! (intent & F2PY_INTENT_C))) {", "\tlazy_transpose(arr);", "\t_lazy_transpose_update_flags(arr);", "\tlazy_transpose(tmp_arr);", "\ttmp_arr->flags &= ~CONTIGUOUS;", "\ttmp_arr->flags |= FORTRAN;", " }", " if (intent & F2PY_INTENT_INPLACE) {", "\tif (swap_arrays(arr,tmp_arr))", "\t return NULL;", "\tPy_XDECREF(tmp_arr);", "\tif (intent & F2PY_INTENT_OUT)", "\t Py_INCREF(arr);", " } else {", "\tarr = tmp_arr;", " }", " } else {", " if ((intent & F2PY_INTENT_OUT)) {", "\tPy_INCREF(arr);", " }", " }", " return arr;", " }", "", " if ((obj==Py_None) && (intent & F2PY_OPTIONAL)) {", " PyArrayObject *arr = NULL;", " CHECK_DIMS_DEFINED(rank,dims,\"optional must have defined dimensions.\\n\");", " arr = (PyArrayObject *)PyArray_SimpleNew(rank,dims,type_num);", " ARR_IS_NULL(arr==NULL,\"FromDims failed: optional.\\n\");", " memset(arr->data, 0, PyArray_NBYTES(arr));", " if (intent & F2PY_INTENT_OUT) {", " if ((!(intent & F2PY_INTENT_C)) && (rank>1)) {", "\ttranspose_strides(arr);", "\tarr->flags &= ~CONTIGUOUS;", "\tarr->flags |= FORTRAN;", " }", "/* Py_INCREF(arr); */", " }", " return arr;", " }", "", " if ((intent & F2PY_INTENT_INOUT) || (intent & F2PY_INTENT_INPLACE)) {", " ARR_IS_NULL(1,\"intent(inout)|intent(inplace) argument must be an array.\\n\");", " }", "", " {", " PyArrayObject *arr = (PyArrayObject *) \\", " PyArray_ContiguousFromObject(obj,type_num,0,0);", " ARR_IS_NULL(arr==NULL,\"ContiguousFromObject failed: not a sequence.\\n\");", "", " if ((rank>1) && (! (intent & F2PY_INTENT_C))) {", " PyArrayObject *tmp_arr = NULL;", " if (rank == 2) {", "\t tmp_arr = (PyArrayObject *) PyArray_CopyAndTranspose((PyObject *)arr);", "\t PyArray_UpdateFlags(tmp_arr, CONTIGUOUS | FORTRAN);", " }", " else {", "\t lazy_transpose(arr);", "\t arr->flags &= ~CONTIGUOUS;", "\t arr->flags |= FORTRAN;", "\t tmp_arr = (PyArrayObject *) PyArray_Copy(arr);", " }", "#ifdef F2PY_REPORT_ON_ARRAY_COPY", " f2py_report_on_array_copy(tmp_arr,\"PyArray_Copy\");", "#endif", " Py_DECREF(arr);", " arr = tmp_arr;", " ARR_IS_NULL(arr==NULL,\"Copy(Array) failed: intent(fortran)\\n\");", " lazy_transpose(arr);", " _lazy_transpose_update_flags(arr);", " }", "/* if (intent & F2PY_INTENT_OUT) */", "/* Py_INCREF(arr); */", "extern", "int array_has_column_major_storage(const PyArrayObject *ap) {", " /* array_has_column_major_storage(a) is equivalent to", " transpose(a).iscontiguous() but more efficient.", "", " This function can be used in order to decide whether to use a", " Fortran or C version of a wrapped function. This is relevant, for", " example, in choosing a clapack or flapack function depending on", " the storage order of array arguments.", " */", " int sd;", " int i;", " sd = PyArray_ITEMSIZE(ap);", " for (i=0;ind;++i) {", " if (ap->dimensions[i] == 0) return 1;", " if (ap->strides[i] != sd) return 0;", " sd *= ap->dimensions[i];", " }", " return 1;", "}", "", "int copy_ND_array(const PyArrayObject *in, PyArrayObject *out)", "#ifdef F2PY_REPORT_ON_ARRAY_COPY", " f2py_report_on_array_copy(out, \"CopyInto\");", "#endif", " return PyArray_CopyInto(out, (PyArrayObject *)in);" ] } }, { "old_path": "scipy/f2py2e/src/fortranobject.h", "new_path": "scipy/f2py2e/src/fortranobject.h", "filename": "fortranobject.h", "extension": "h", "change_type": "MODIFY", "diff": "@@ -106,14 +106,11 @@ typedef struct {\n #define F2PY_OPTIONAL 128\n #define F2PY_INTENT_INPLACE 256\n \n- extern void lazy_transpose(PyArrayObject* arr); /* Obsolete?? */\n- extern void transpose_strides(PyArrayObject* arr);\n extern PyArrayObject* array_from_pyobj(const int type_num,\n \t\t\t\t\t intp *dims,\n \t\t\t\t\t const int rank,\n \t\t\t\t\t const int intent,\n \t\t\t\t\t PyObject *obj);\n- extern int array_has_column_major_storage(const PyArrayObject *ap);\n extern int copy_ND_array(const PyArrayObject *in, PyArrayObject *out);\n \n #ifdef DEBUG_COPY_ND_ARRAY\n", "added_lines": 0, "deleted_lines": 3, "source_code": "#ifndef Py_FORTRANOBJECT_H\n#define Py_FORTRANOBJECT_H\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#include \"Python.h\"\n\n#ifdef FORTRANOBJECT_C\n#define NO_IMPORT_ARRAY\n#endif\n#define PY_ARRAY_UNIQUE_SYMBOL PyArray_API\n#include \"scipy/arrayobject.h\"\n\n /*\n#ifdef F2PY_REPORT_ATEXIT_DISABLE\n#undef F2PY_REPORT_ATEXIT\n#else\n\n#ifndef __FreeBSD__\n#ifndef __WIN32__\n#ifndef __APPLE__\n#define F2PY_REPORT_ATEXIT\n#endif\n#endif\n#endif\n\n#endif\n */\n\n#ifdef F2PY_REPORT_ATEXIT\n#include \n extern void f2py_start_clock(void);\n extern void f2py_stop_clock(void);\n extern void f2py_start_call_clock(void);\n extern void f2py_stop_call_clock(void);\n extern void f2py_cb_start_clock(void);\n extern void f2py_cb_stop_clock(void);\n extern void f2py_cb_start_call_clock(void);\n extern void f2py_cb_stop_call_clock(void);\n extern void f2py_report_on_exit(int,void*);\n#endif\n\n#ifdef DMALLOC\n#include \"dmalloc.h\"\n#endif\n\n/* Fortran object interface */\n\n/*\n123456789-123456789-123456789-123456789-123456789-123456789-123456789-12\n\nPyFortranObject represents various Fortran objects:\nFortran (module) routines, COMMON blocks, module data. \n\nAuthor: Pearu Peterson \n*/\n\n#define F2PY_MAX_DIMS 40\n\ntypedef void (*f2py_set_data_func)(char*,intp*);\ntypedef void (*f2py_void_func)(void);\ntypedef void (*f2py_init_func)(int*,intp*,f2py_set_data_func,int*);\n\n /*typedef void* (*f2py_c_func)(void*,...);*/\n\ntypedef void *(*f2pycfunc)(void);\n\ntypedef struct {\n char *name; /* attribute (array||routine) name */\n int rank; /* array rank, 0 for scalar, max is F2PY_MAX_DIMS,\n\t\t\t\t|| rank=-1 for Fortran routine */\n struct {intp d[F2PY_MAX_DIMS];} dims; /* dimensions of the array, || not used */\n int type; /* PyArray_ || not used */\n char *data; /* pointer to array || Fortran routine */\n f2py_init_func func; /* initialization function for\n\t\t\t\tallocatable arrays:\n\t\t\t\tfunc(&rank,dims,set_ptr_func,name,len(name))\n\t\t\t\t|| C/API wrapper for Fortran routine */\n char *doc; /* documentation string; only recommended\n\t\t\t\tfor routines. */\n} FortranDataDef;\n\ntypedef struct {\n PyObject_HEAD\n int len; /* Number of attributes */\n FortranDataDef *defs; /* An array of FortranDataDef's */ \n PyObject *dict; /* Fortran object attribute dictionary */\n} PyFortranObject;\n\n#define PyFortran_Check(op) ((op)->ob_type == &PyFortran_Type)\n#define PyFortran_Check1(op) (0==strcmp((op)->ob_type->tp_name,\"fortran\"))\n\n extern PyTypeObject PyFortran_Type;\n extern PyObject * PyFortranObject_New(FortranDataDef* defs, f2py_void_func init);\n extern PyObject * PyFortranObject_NewAsAttr(FortranDataDef* defs);\n\n#define ISCONTIGUOUS(m) ((m)->flags & CONTIGUOUS)\n#define F2PY_INTENT_IN 1\n#define F2PY_INTENT_INOUT 2\n#define F2PY_INTENT_OUT 4\n#define F2PY_INTENT_HIDE 8\n#define F2PY_INTENT_CACHE 16\n#define F2PY_INTENT_COPY 32\n#define F2PY_INTENT_C 64\n#define F2PY_OPTIONAL 128\n#define F2PY_INTENT_INPLACE 256\n\n extern PyArrayObject* array_from_pyobj(const int type_num,\n\t\t\t\t\t intp *dims,\n\t\t\t\t\t const int rank,\n\t\t\t\t\t const int intent,\n\t\t\t\t\t PyObject *obj);\n extern int copy_ND_array(const PyArrayObject *in, PyArrayObject *out);\n\n#ifdef DEBUG_COPY_ND_ARRAY\n extern void dump_attrs(const PyArrayObject* arr);\n#endif\n\n#ifdef __cplusplus\n}\n#endif\n#endif /* !Py_FORTRANOBJECT_H */\n", "source_code_before": "#ifndef Py_FORTRANOBJECT_H\n#define Py_FORTRANOBJECT_H\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#include \"Python.h\"\n\n#ifdef FORTRANOBJECT_C\n#define NO_IMPORT_ARRAY\n#endif\n#define PY_ARRAY_UNIQUE_SYMBOL PyArray_API\n#include \"scipy/arrayobject.h\"\n\n /*\n#ifdef F2PY_REPORT_ATEXIT_DISABLE\n#undef F2PY_REPORT_ATEXIT\n#else\n\n#ifndef __FreeBSD__\n#ifndef __WIN32__\n#ifndef __APPLE__\n#define F2PY_REPORT_ATEXIT\n#endif\n#endif\n#endif\n\n#endif\n */\n\n#ifdef F2PY_REPORT_ATEXIT\n#include \n extern void f2py_start_clock(void);\n extern void f2py_stop_clock(void);\n extern void f2py_start_call_clock(void);\n extern void f2py_stop_call_clock(void);\n extern void f2py_cb_start_clock(void);\n extern void f2py_cb_stop_clock(void);\n extern void f2py_cb_start_call_clock(void);\n extern void f2py_cb_stop_call_clock(void);\n extern void f2py_report_on_exit(int,void*);\n#endif\n\n#ifdef DMALLOC\n#include \"dmalloc.h\"\n#endif\n\n/* Fortran object interface */\n\n/*\n123456789-123456789-123456789-123456789-123456789-123456789-123456789-12\n\nPyFortranObject represents various Fortran objects:\nFortran (module) routines, COMMON blocks, module data. \n\nAuthor: Pearu Peterson \n*/\n\n#define F2PY_MAX_DIMS 40\n\ntypedef void (*f2py_set_data_func)(char*,intp*);\ntypedef void (*f2py_void_func)(void);\ntypedef void (*f2py_init_func)(int*,intp*,f2py_set_data_func,int*);\n\n /*typedef void* (*f2py_c_func)(void*,...);*/\n\ntypedef void *(*f2pycfunc)(void);\n\ntypedef struct {\n char *name; /* attribute (array||routine) name */\n int rank; /* array rank, 0 for scalar, max is F2PY_MAX_DIMS,\n\t\t\t\t|| rank=-1 for Fortran routine */\n struct {intp d[F2PY_MAX_DIMS];} dims; /* dimensions of the array, || not used */\n int type; /* PyArray_ || not used */\n char *data; /* pointer to array || Fortran routine */\n f2py_init_func func; /* initialization function for\n\t\t\t\tallocatable arrays:\n\t\t\t\tfunc(&rank,dims,set_ptr_func,name,len(name))\n\t\t\t\t|| C/API wrapper for Fortran routine */\n char *doc; /* documentation string; only recommended\n\t\t\t\tfor routines. */\n} FortranDataDef;\n\ntypedef struct {\n PyObject_HEAD\n int len; /* Number of attributes */\n FortranDataDef *defs; /* An array of FortranDataDef's */ \n PyObject *dict; /* Fortran object attribute dictionary */\n} PyFortranObject;\n\n#define PyFortran_Check(op) ((op)->ob_type == &PyFortran_Type)\n#define PyFortran_Check1(op) (0==strcmp((op)->ob_type->tp_name,\"fortran\"))\n\n extern PyTypeObject PyFortran_Type;\n extern PyObject * PyFortranObject_New(FortranDataDef* defs, f2py_void_func init);\n extern PyObject * PyFortranObject_NewAsAttr(FortranDataDef* defs);\n\n#define ISCONTIGUOUS(m) ((m)->flags & CONTIGUOUS)\n#define F2PY_INTENT_IN 1\n#define F2PY_INTENT_INOUT 2\n#define F2PY_INTENT_OUT 4\n#define F2PY_INTENT_HIDE 8\n#define F2PY_INTENT_CACHE 16\n#define F2PY_INTENT_COPY 32\n#define F2PY_INTENT_C 64\n#define F2PY_OPTIONAL 128\n#define F2PY_INTENT_INPLACE 256\n\n extern void lazy_transpose(PyArrayObject* arr); /* Obsolete?? */\n extern void transpose_strides(PyArrayObject* arr);\n extern PyArrayObject* array_from_pyobj(const int type_num,\n\t\t\t\t\t intp *dims,\n\t\t\t\t\t const int rank,\n\t\t\t\t\t const int intent,\n\t\t\t\t\t PyObject *obj);\n extern int array_has_column_major_storage(const PyArrayObject *ap);\n extern int copy_ND_array(const PyArrayObject *in, PyArrayObject *out);\n\n#ifdef DEBUG_COPY_ND_ARRAY\n extern void dump_attrs(const PyArrayObject* arr);\n#endif\n\n#ifdef __cplusplus\n}\n#endif\n#endif /* !Py_FORTRANOBJECT_H */\n", "methods": [], "methods_before": [], "changed_methods": [], "nloc": 44, "complexity": 0, "token_count": 265, "diff_parsed": { "added": [], "deleted": [ " extern void lazy_transpose(PyArrayObject* arr); /* Obsolete?? */", " extern void transpose_strides(PyArrayObject* arr);", " extern int array_has_column_major_storage(const PyArrayObject *ap);" ] } }, { "old_path": "scipy/f2py2e/tests/array_from_pyobj/setup.py", "new_path": "scipy/f2py2e/tests/array_from_pyobj/setup.py", "filename": "setup.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -2,17 +2,21 @@\n import os\n def configuration(parent_name='',top_path=None):\n from scipy.distutils.misc_util import Configuration\n- import scipy.f2py as f2py\n- f2pydir=os.path.dirname(os.path.abspath(f2py.__file__))\n- f2pydir=os.path.abspath('../../')\n+\n+ config = Configuration('array_from_pyobj',parent_name,top_path)\n+ #import scipy.f2py as f2py\n+ #f2pydir=os.path.dirname(os.path.abspath(f2py.__file__))\n+ f2pydir=os.path.join(config.local_path,'..','..')\n fobjhsrc = os.path.join(f2pydir,'src','fortranobject.h')\n fobjcsrc = os.path.join(f2pydir,'src','fortranobject.c')\n- config = Configuration('array_from_pyobj',parent_name,top_path)\n config.add_extension('wrap',\n sources = ['wrapmodule.c',fobjcsrc],\n include_dirs = [os.path.dirname(fobjhsrc)],\n depends = [fobjhsrc,fobjcsrc],\n- define_macros = [('DEBUG_COPY_ND_ARRAY',1)]\n+ define_macros = [('DEBUG_COPY_ND_ARRAY',1),\n+ #('F2PY_REPORT_ON_ARRAY_COPY',1),\n+ #('F2PY_REPORT_ATEXIT',1)\n+ ]\n )\n \n return config\n", "added_lines": 9, "deleted_lines": 5, "source_code": "\nimport os\ndef configuration(parent_name='',top_path=None):\n from scipy.distutils.misc_util import Configuration\n\n config = Configuration('array_from_pyobj',parent_name,top_path)\n #import scipy.f2py as f2py\n #f2pydir=os.path.dirname(os.path.abspath(f2py.__file__))\n f2pydir=os.path.join(config.local_path,'..','..')\n fobjhsrc = os.path.join(f2pydir,'src','fortranobject.h')\n fobjcsrc = os.path.join(f2pydir,'src','fortranobject.c')\n config.add_extension('wrap',\n sources = ['wrapmodule.c',fobjcsrc],\n include_dirs = [os.path.dirname(fobjhsrc)],\n depends = [fobjhsrc,fobjcsrc],\n define_macros = [('DEBUG_COPY_ND_ARRAY',1),\n #('F2PY_REPORT_ON_ARRAY_COPY',1),\n #('F2PY_REPORT_ATEXIT',1)\n ]\n )\n\n return config\n\nif __name__ == \"__main__\":\n from scipy.distutils.core import setup\n setup(**configuration(top_path='').todict())\n", "source_code_before": "\nimport os\ndef configuration(parent_name='',top_path=None):\n from scipy.distutils.misc_util import Configuration\n import scipy.f2py as f2py\n f2pydir=os.path.dirname(os.path.abspath(f2py.__file__))\n f2pydir=os.path.abspath('../../')\n fobjhsrc = os.path.join(f2pydir,'src','fortranobject.h')\n fobjcsrc = os.path.join(f2pydir,'src','fortranobject.c')\n config = Configuration('array_from_pyobj',parent_name,top_path)\n config.add_extension('wrap',\n sources = ['wrapmodule.c',fobjcsrc],\n include_dirs = [os.path.dirname(fobjhsrc)],\n depends = [fobjhsrc,fobjcsrc],\n define_macros = [('DEBUG_COPY_ND_ARRAY',1)]\n )\n\n return config\n\nif __name__ == \"__main__\":\n from scipy.distutils.core import setup\n setup(**configuration(top_path='').todict())\n", "methods": [ { "name": "configuration", "long_name": "configuration( parent_name = '' , top_path = None )", "filename": "setup.py", "nloc": 14, "complexity": 1, "token_count": 121, "parameters": [ "parent_name", "top_path" ], "start_line": 3, "end_line": 22, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 } ], "methods_before": [ { "name": "configuration", "long_name": "configuration( parent_name = '' , top_path = None )", "filename": "setup.py", "nloc": 15, "complexity": 1, "token_count": 139, "parameters": [ "parent_name", "top_path" ], "start_line": 3, "end_line": 18, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "configuration", "long_name": "configuration( parent_name = '' , top_path = None )", "filename": "setup.py", "nloc": 14, "complexity": 1, "token_count": 121, "parameters": [ "parent_name", "top_path" ], "start_line": 3, "end_line": 22, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 } ], "nloc": 18, "complexity": 1, "token_count": 151, "diff_parsed": { "added": [ "", " config = Configuration('array_from_pyobj',parent_name,top_path)", " #import scipy.f2py as f2py", " #f2pydir=os.path.dirname(os.path.abspath(f2py.__file__))", " f2pydir=os.path.join(config.local_path,'..','..')", " define_macros = [('DEBUG_COPY_ND_ARRAY',1),", " #('F2PY_REPORT_ON_ARRAY_COPY',1),", " #('F2PY_REPORT_ATEXIT',1)", " ]" ], "deleted": [ " import scipy.f2py as f2py", " f2pydir=os.path.dirname(os.path.abspath(f2py.__file__))", " f2pydir=os.path.abspath('../../')", " config = Configuration('array_from_pyobj',parent_name,top_path)", " define_macros = [('DEBUG_COPY_ND_ARRAY',1)]" ] } }, { "old_path": "scipy/f2py2e/tests/array_from_pyobj/tests/test_array_from_pyobj.py", "new_path": "scipy/f2py2e/tests/array_from_pyobj/tests/test_array_from_pyobj.py", "filename": "test_array_from_pyobj.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -3,7 +3,7 @@\n import copy\n \n from scipy.test.testing import *\n-from scipy.base import array, typeinfo, alltrue, ndarray, asarray, can_cast\n+from scipy.base import array, typeinfo, alltrue, ndarray, asarray, can_cast,zeros\n set_package_path()\n from array_from_pyobj import wrap\n del sys.path[0]\n@@ -109,7 +109,10 @@ def _init(self,name):\n self.dtypechar = typeinfo[self.NAME][0]\n \n def cast_types(self):\n- return map(Type,self._cast_dict[self.NAME])\n+ return map(self.__class__,self._cast_dict[self.NAME])\n+\n+ def all_types(self):\n+ return map(self.__class__,self._type_names)\n \n def smaller_types(self):\n bits = typeinfo[self.NAME][3]\n@@ -144,24 +147,6 @@ def __init__(self,typ,dims,intent,obj):\n self.obj_copy = copy.deepcopy(obj)\n self.obj = obj\n \n- self.pyarr = array(array(obj,\n- dtype = typ.dtypechar).reshape(*dims),\n- fortran=not self.intent.is_intent('c'))\n- assert self.pyarr.dtypechar==typ.dtypechar,\\\n- `self.pyarr.dtypechar,typ.dtypechar`\n- assert self.pyarr.flags['OWNDATA']\n- self.pyarr_attr = wrap.array_attrs(self.pyarr)\n-\n- if len(dims)>1:\n- if self.intent.is_intent('c'):\n- assert not self.pyarr.flags['FORTRAN']\n- assert self.pyarr.flags['CONTIGUOUS']\n- assert not self.pyarr_attr[6] & wrap.FORTRAN\n- else:\n- assert self.pyarr.flags['FORTRAN']\n- assert not self.pyarr.flags['CONTIGUOUS']\n- assert self.pyarr_attr[6] & wrap.FORTRAN\n-\n # arr.dtypechar may be different from typ.dtypechar\n self.arr = wrap.call(typ.type_num,dims,intent.flags,obj)\n \n@@ -179,6 +164,35 @@ def __init__(self,typ,dims,intent,obj):\n assert not self.arr.flags['CONTIGUOUS']\n assert self.arr_attr[6] & wrap.FORTRAN\n \n+ if obj is None:\n+ self.pyarr = None\n+ self.pyarr_attr = None\n+ return\n+\n+ if intent.is_intent('cache'):\n+ assert isinstance(obj,ndarray),`type(obj)`\n+ self.pyarr = array(obj).reshape(*dims)\n+ \n+ else:\n+ self.pyarr = array(array(obj,\n+ dtype = typ.dtypechar).reshape(*dims),\n+ fortran=not self.intent.is_intent('c'))\n+ assert self.pyarr.dtypechar==typ.dtypechar,\\\n+ `self.pyarr.dtypechar,typ.dtypechar`\n+ assert self.pyarr.flags['OWNDATA']\n+ self.pyarr_attr = wrap.array_attrs(self.pyarr)\n+\n+ if len(dims)>1:\n+ if self.intent.is_intent('c'):\n+ assert not self.pyarr.flags['FORTRAN']\n+ assert self.pyarr.flags['CONTIGUOUS']\n+ assert not self.pyarr_attr[6] & wrap.FORTRAN\n+ else:\n+ assert self.pyarr.flags['FORTRAN']\n+ assert not self.pyarr.flags['CONTIGUOUS']\n+ assert self.pyarr_attr[6] & wrap.FORTRAN\n+\n+\n assert self.arr_attr[1]==self.pyarr_attr[1] # nd\n assert self.arr_attr[2]==self.pyarr_attr[2] # dimensions\n if self.arr_attr[1]<=1:\n@@ -189,8 +203,12 @@ def __init__(self,typ,dims,intent,obj):\n assert self.arr_attr[6]==self.pyarr_attr[6],\\\n `self.arr_attr[6],self.pyarr_attr[6],flags2names(0*self.arr_attr[6]-self.pyarr_attr[6]),flags2names(self.arr_attr[6]),intent` # flags\n \n- assert self.arr_attr[5][3]==self.type.elsize,\\\n- `self.arr_attr[5][3],self.type.elsize`\n+ if intent.is_intent('cache'):\n+ assert self.arr_attr[5][3]>=self.type.elsize,\\\n+ `self.arr_attr[5][3],self.type.elsize`\n+ else:\n+ assert self.arr_attr[5][3]==self.type.elsize,\\\n+ `self.arr_attr[5][3],self.type.elsize`\n assert self.arr_equal(self.pyarr,self.arr)\n \n if isinstance(self.obj,ndarray):\n@@ -243,6 +261,41 @@ def check_in_from_2casttype(self):\n else:\n assert not a.has_shared_memory(),`t.dtype`\n \n+ def check_inout_2seq(self):\n+ obj = array(self.num2seq,dtype=self.type.dtype)\n+ a = self.array([len(self.num2seq)],intent.inout,obj)\n+ assert a.has_shared_memory()\n+\n+ try:\n+ a = self.array([2],intent.in_.inout,self.num2seq)\n+ except TypeError,msg:\n+ if not str(msg).startswith('failed to initialize intent(inout|inplace|cache) array'):\n+ raise\n+ else:\n+ raise SystemError,'intent(inout) should have failed on sequence'\n+\n+ def check_f_inout_23seq(self):\n+ obj = array(self.num23seq,dtype=self.type.dtype,fortran=1)\n+ shape = (len(self.num23seq),len(self.num23seq[0]))\n+ a = self.array(shape,intent.in_.inout,obj)\n+ assert a.has_shared_memory()\n+\n+ obj = array(self.num23seq,dtype=self.type.dtype,fortran=0)\n+ shape = (len(self.num23seq),len(self.num23seq[0]))\n+ try:\n+ a = self.array(shape,intent.in_.inout,obj)\n+ except ValueError,msg:\n+ if not str(msg).startswith('failed to initialize intent(inout) array'):\n+ raise\n+ else:\n+ raise SystemError,'intent(inout) should have failed on improper array'\n+\n+ def check_c_inout_23seq(self):\n+ obj = array(self.num23seq,dtype=self.type.dtype)\n+ shape = (len(self.num23seq),len(self.num23seq[0]))\n+ a = self.array(shape,intent.in_.c.inout,obj)\n+ assert a.has_shared_memory()\n+\n def check_in_copy_from_2casttype(self):\n for t in self.type.cast_types():\n obj = array(self.num2seq,dtype=t.dtype)\n@@ -295,10 +348,160 @@ def check_c_copy_in_from_23casttype(self):\n intent.in_.c.copy,obj)\n assert not a.has_shared_memory(),`t.dtype`\n \n+ def check_in_cache_from_2casttype(self):\n+ for t in self.type.all_types():\n+ if t.elsize != self.type.elsize:\n+ continue\n+ obj = array(self.num2seq,dtype=t.dtype)\n+ shape = (len(self.num2seq),)\n+ a = self.array(shape,intent.in_.c.cache,obj) \n+ assert a.has_shared_memory(),`t.dtype`\n+\n+ a = self.array(shape,intent.in_.cache,obj) \n+ assert a.has_shared_memory(),`t.dtype`\n+ \n+ obj = array(self.num2seq,dtype=t.dtype,fortran=1)\n+ a = self.array(shape,intent.in_.c.cache,obj) \n+ assert a.has_shared_memory(),`t.dtype`\n+\n+ a = self.array(shape,intent.in_.cache,obj)\n+ assert a.has_shared_memory(),`t.dtype`\n+\n+ try:\n+ a = self.array(shape,intent.in_.cache,obj[::-1])\n+ except ValueError,msg:\n+ if not str(msg).startswith('failed to initialize intent(cache) array'):\n+ raise\n+ else:\n+ raise SystemError,'intent(cache) should have failed on multisegmented array'\n+ def check_in_cache_from_2casttype_failure(self):\n+ for t in self.type.all_types():\n+ if t.elsize >= self.type.elsize:\n+ continue\n+ obj = array(self.num2seq,dtype=t.dtype)\n+ shape = (len(self.num2seq),)\n+ try:\n+ a = self.array(shape,intent.in_.cache,obj)\n+ except ValueError,msg:\n+ if not str(msg).startswith('failed to initialize intent(cache) array'):\n+ raise\n+ else:\n+ raise SystemError,'intent(cache) should have failed on smaller array'\n+\n+ def check_cache_hidden(self):\n+ shape = (2,)\n+ a = self.array(shape,intent.cache.hide,None)\n+ assert a.arr.shape==shape\n+\n+ shape = (2,3)\n+ a = self.array(shape,intent.cache.hide,None)\n+ assert a.arr.shape==shape\n+\n+ shape = (-1,3)\n+ try:\n+ a = self.array(shape,intent.cache.hide,None)\n+ except ValueError,msg:\n+ if not str(msg).startswith('failed to create intent(cache|hide)|optional array'):\n+ raise\n+ else:\n+ raise SystemError,'intent(cache) should have failed on undefined dimensions'\n+\n+ def check_hidden(self):\n+ shape = (2,)\n+ a = self.array(shape,intent.hide,None)\n+ assert a.arr.shape==shape\n+ assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))\n+\n+ shape = (2,3)\n+ a = self.array(shape,intent.hide,None)\n+ assert a.arr.shape==shape\n+ assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))\n+ assert a.arr.flags['FORTRAN'] and not a.arr.flags['CONTIGUOUS']\n+\n+ shape = (2,3)\n+ a = self.array(shape,intent.c.hide,None)\n+ assert a.arr.shape==shape\n+ assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))\n+ assert not a.arr.flags['FORTRAN'] and a.arr.flags['CONTIGUOUS']\n+\n+ shape = (-1,3)\n+ try:\n+ a = self.array(shape,intent.hide,None)\n+ except ValueError,msg:\n+ if not str(msg).startswith('failed to create intent(cache|hide)|optional array'):\n+ raise\n+ else:\n+ raise SystemError,'intent(hide) should have failed on undefined dimensions'\n+\n+ def check_optional_none(self):\n+ shape = (2,)\n+ a = self.array(shape,intent.optional,None)\n+ assert a.arr.shape==shape\n+ assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))\n+\n+ shape = (2,3)\n+ a = self.array(shape,intent.optional,None)\n+ assert a.arr.shape==shape\n+ assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))\n+ assert a.arr.flags['FORTRAN'] and not a.arr.flags['CONTIGUOUS']\n+\n+ shape = (2,3)\n+ a = self.array(shape,intent.c.optional,None)\n+ assert a.arr.shape==shape\n+ assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))\n+ assert not a.arr.flags['FORTRAN'] and a.arr.flags['CONTIGUOUS']\n+\n+ def check_optional_from_2seq(self):\n+ obj = self.num2seq\n+ shape = (len(obj),)\n+ a = self.array(shape,intent.optional,obj)\n+ assert a.arr.shape==shape\n+ assert not a.has_shared_memory()\n+\n+ def check_optional_from_23seq(self):\n+ obj = self.num23seq\n+ shape = (len(obj),len(obj[0]))\n+ a = self.array(shape,intent.optional,obj)\n+ assert a.arr.shape==shape\n+ assert not a.has_shared_memory()\n+\n+ a = self.array(shape,intent.optional.c,obj)\n+ assert a.arr.shape==shape\n+ assert not a.has_shared_memory()\n+\n+ def check_inplace(self):\n+ obj = array(self.num23seq,dtype=self.type.dtype)\n+ assert not obj.flags['FORTRAN'] and obj.flags['CONTIGUOUS']\n+ shape = obj.shape\n+ a = self.array(shape,intent.inplace,obj)\n+ assert obj[1][2]==a.arr[1][2],`obj,a.arr`\n+ a.arr[1][2]=54\n+ assert obj[1][2]==a.arr[1][2]==array(54,dtype=self.type.dtype),`obj,a.arr`\n+ assert a.arr is obj\n+ assert obj.flags['FORTRAN'] # obj attributes are changed inplace!\n+ assert not obj.flags['CONTIGUOUS']\n+\n+ def check_inplace_from_casttype(self):\n+ for t in self.type.cast_types():\n+ if t is self.type:\n+ continue\n+ obj = array(self.num23seq,dtype=t.dtype)\n+ assert obj.dtype==t.dtype\n+ assert obj.dtype is not self.type.dtype\n+ assert not obj.flags['FORTRAN'] and obj.flags['CONTIGUOUS']\n+ shape = obj.shape\n+ a = self.array(shape,intent.inplace,obj)\n+ assert obj[1][2]==a.arr[1][2],`obj,a.arr`\n+ a.arr[1][2]=54\n+ assert obj[1][2]==a.arr[1][2]==array(54,dtype=self.type.dtype),`obj,a.arr`\n+ assert a.arr is obj\n+ assert obj.flags['FORTRAN'] # obj attributes are changed inplace!\n+ assert not obj.flags['CONTIGUOUS']\n+ assert obj.dtype is self.type.dtype # obj type is changed inplace!\n \n for t in Type._type_names:\n exec '''\\\n-class test_%s(unittest.TestCase,\n+class test_%s_gen(unittest.TestCase,\n _test_shared_memory\n ):\n type = Type(%r)\n", "added_lines": 226, "deleted_lines": 23, "source_code": "import unittest\nimport sys\nimport copy\n\nfrom scipy.test.testing import *\nfrom scipy.base import array, typeinfo, alltrue, ndarray, asarray, can_cast,zeros\nset_package_path()\nfrom array_from_pyobj import wrap\ndel sys.path[0]\n\ndef flags_info(arr):\n flags = wrap.array_attrs(arr)[6]\n return flags2names(flags)\n\ndef flags2names(flags):\n info = []\n for flagname in ['CONTIGUOUS','FORTRAN','OWNDATA','ENSURECOPY',\n 'ENSUREARRAY','ALIGNED','NOTSWAPPED','WRITEABLE',\n 'UPDATEIFCOPY','BEHAVED_FLAGS','BEHAVED_FLAGS_RO',\n 'CARRAY_FLAGS','FARRAY_FLAGS'\n ]:\n if abs(flags) & getattr(wrap,flagname):\n info.append(flagname)\n return info\n\nclass Intent:\n def __init__(self,intent_list=[]):\n self.intent_list = intent_list[:]\n flags = 0\n for i in intent_list:\n if i=='optional':\n flags |= wrap.F2PY_OPTIONAL\n else:\n flags |= getattr(wrap,'F2PY_INTENT_'+i.upper())\n self.flags = flags\n def __getattr__(self,name):\n name = name.lower()\n if name=='in_': name='in'\n return self.__class__(self.intent_list+[name])\n def __str__(self):\n return 'intent(%s)' % (','.join(self.intent_list))\n def __repr__(self):\n return 'Intent(%r)' % (self.intent_list)\n def is_intent(self,*names):\n for name in names:\n if name not in self.intent_list:\n return False\n return True\n def is_intent_exact(self,*names):\n return len(self.intent_list)==len(names) and self.is_intent(*names)\n\nintent = Intent()\n\nclass Type(object):\n\n _type_names = ['BOOL','BYTE','UBYTE','SHORT','USHORT','INT','UINT',\n 'LONG','ULONG','LONGLONG','ULONGLONG',\n 'FLOAT','DOUBLE','LONGDOUBLE','CFLOAT','CDOUBLE',\n 'CLONGDOUBLE']\n _type_cache = {}\n\n _cast_dict = {'BOOL':['BOOL']}\n _cast_dict['BYTE'] = _cast_dict['BOOL'] + ['BYTE']\n _cast_dict['UBYTE'] = _cast_dict['BOOL'] + ['UBYTE']\n _cast_dict['BYTE'] = ['BYTE']\n _cast_dict['UBYTE'] = ['UBYTE']\n _cast_dict['SHORT'] = _cast_dict['BYTE'] + ['UBYTE','SHORT']\n _cast_dict['USHORT'] = _cast_dict['UBYTE'] + ['BYTE','USHORT']\n _cast_dict['INT'] = _cast_dict['SHORT'] + ['USHORT','INT']\n _cast_dict['UINT'] = _cast_dict['USHORT'] + ['SHORT','UINT']\n\n _cast_dict['LONG'] = _cast_dict['INT'] + ['LONG']\n _cast_dict['ULONG'] = _cast_dict['UINT'] + ['ULONG']\n\n _cast_dict['LONGLONG'] = _cast_dict['LONG'] + ['ULONG','LONGLONG']\n _cast_dict['ULONGLONG'] = _cast_dict['ULONG'] + ['LONG','ULONGLONG']\n\n _cast_dict['FLOAT'] = _cast_dict['SHORT'] + ['USHORT','FLOAT']\n _cast_dict['DOUBLE'] = _cast_dict['INT'] + ['UINT','FLOAT','DOUBLE']\n _cast_dict['LONGDOUBLE'] = _cast_dict['LONG'] + ['ULONG','FLOAT','DOUBLE','LONGDOUBLE']\n\n _cast_dict['CFLOAT'] = _cast_dict['FLOAT'] + ['CFLOAT']\n _cast_dict['CDOUBLE'] = _cast_dict['DOUBLE'] + ['CFLOAT','CDOUBLE']\n _cast_dict['CLONGDOUBLE'] = _cast_dict['LONGDOUBLE'] + ['CFLOAT','CDOUBLE','CLONGDOUBLE']\n \n \n def __new__(cls,name):\n if isinstance(name,type):\n dtype = name\n name = None\n for n,i in typeinfo.items():\n if isinstance(i,tuple) and dtype is i[-1]:\n name = n\n break\n obj = cls._type_cache.get(name.upper(),None)\n if obj is not None:\n return obj\n obj = object.__new__(cls)\n obj._init(name)\n cls._type_cache[name.upper()] = obj\n return obj\n \n def _init(self,name):\n self.NAME = name.upper()\n self.type_num = getattr(wrap,'PyArray_'+self.NAME)\n assert_equal(self.type_num,typeinfo[self.NAME][1])\n self.dtype = typeinfo[self.NAME][-1]\n self.elsize = typeinfo[self.NAME][2] / 8\n self.dtypechar = typeinfo[self.NAME][0]\n\n def cast_types(self):\n return map(self.__class__,self._cast_dict[self.NAME])\n\n def all_types(self):\n return map(self.__class__,self._type_names)\n\n def smaller_types(self):\n bits = typeinfo[self.NAME][3]\n types = []\n for name in self._type_names:\n if typeinfo[name][3]bits:\n types.append(Type(name))\n return types\n\nclass Array:\n def __init__(self,typ,dims,intent,obj):\n self.type = typ\n self.dims = dims\n self.intent = intent\n self.obj_copy = copy.deepcopy(obj)\n self.obj = obj\n\n # arr.dtypechar may be different from typ.dtypechar\n self.arr = wrap.call(typ.type_num,dims,intent.flags,obj)\n\n self.arr_attr = wrap.array_attrs(self.arr)\n\n if len(dims)>1:\n if self.intent.is_intent('c'):\n assert intent.flags & wrap.F2PY_INTENT_C\n assert not self.arr.flags['FORTRAN'],`self.arr.flags,obj.flags`\n assert self.arr.flags['CONTIGUOUS']\n assert not self.arr_attr[6] & wrap.FORTRAN\n else:\n assert not intent.flags & wrap.F2PY_INTENT_C\n assert self.arr.flags['FORTRAN']\n assert not self.arr.flags['CONTIGUOUS']\n assert self.arr_attr[6] & wrap.FORTRAN\n\n if obj is None:\n self.pyarr = None\n self.pyarr_attr = None\n return\n\n if intent.is_intent('cache'):\n assert isinstance(obj,ndarray),`type(obj)`\n self.pyarr = array(obj).reshape(*dims)\n \n else:\n self.pyarr = array(array(obj,\n dtype = typ.dtypechar).reshape(*dims),\n fortran=not self.intent.is_intent('c'))\n assert self.pyarr.dtypechar==typ.dtypechar,\\\n `self.pyarr.dtypechar,typ.dtypechar`\n assert self.pyarr.flags['OWNDATA']\n self.pyarr_attr = wrap.array_attrs(self.pyarr)\n\n if len(dims)>1:\n if self.intent.is_intent('c'):\n assert not self.pyarr.flags['FORTRAN']\n assert self.pyarr.flags['CONTIGUOUS']\n assert not self.pyarr_attr[6] & wrap.FORTRAN\n else:\n assert self.pyarr.flags['FORTRAN']\n assert not self.pyarr.flags['CONTIGUOUS']\n assert self.pyarr_attr[6] & wrap.FORTRAN\n\n\n assert self.arr_attr[1]==self.pyarr_attr[1] # nd\n assert self.arr_attr[2]==self.pyarr_attr[2] # dimensions\n if self.arr_attr[1]<=1:\n assert self.arr_attr[3]==self.pyarr_attr[3],\\\n `self.arr_attr[3],self.pyarr_attr[3],self.arr.tostring(),self.pyarr.tostring()` # strides\n assert self.arr_attr[5][-2:]==self.pyarr_attr[5][-2:],\\\n `self.arr_attr[5],self.pyarr_attr[5]` # descr\n assert self.arr_attr[6]==self.pyarr_attr[6],\\\n `self.arr_attr[6],self.pyarr_attr[6],flags2names(0*self.arr_attr[6]-self.pyarr_attr[6]),flags2names(self.arr_attr[6]),intent` # flags\n\n if intent.is_intent('cache'):\n assert self.arr_attr[5][3]>=self.type.elsize,\\\n `self.arr_attr[5][3],self.type.elsize`\n else:\n assert self.arr_attr[5][3]==self.type.elsize,\\\n `self.arr_attr[5][3],self.type.elsize`\n assert self.arr_equal(self.pyarr,self.arr)\n \n if isinstance(self.obj,ndarray):\n if typ.elsize==Type(obj.dtype).elsize:\n if not intent.is_intent('copy') and self.arr_attr[1]<=1:\n assert self.has_shared_memory()\n\n def arr_equal(self,arr1,arr2):\n if arr1.shape != arr2.shape:\n return False\n return alltrue(arr1==arr2)\n\n def __str__(self):\n return str(self.arr)\n\n def has_shared_memory(self):\n \"\"\"Check that created array shares data with input array.\n \"\"\"\n if self.obj is self.arr:\n return True\n if not isinstance(self.obj,ndarray):\n return False\n obj_attr = wrap.array_attrs(self.obj)\n return obj_attr[0]==self.arr_attr[0]\n\n##################################################\n\nclass test_intent(unittest.TestCase):\n def check_in_out(self):\n assert_equal(str(intent.in_.out),'intent(in,out)')\n assert intent.in_.c.is_intent('c')\n assert not intent.in_.c.is_intent_exact('c')\n assert intent.in_.c.is_intent_exact('c','in')\n assert intent.in_.c.is_intent_exact('in','c')\n assert not intent.in_.is_intent('c')\n\nclass _test_shared_memory:\n num2seq = [1,2]\n num23seq = [[1,2,3],[4,5,6]]\n def check_in_from_2seq(self):\n a = self.array([2],intent.in_,self.num2seq)\n assert not a.has_shared_memory()\n\n def check_in_from_2casttype(self):\n for t in self.type.cast_types():\n obj = array(self.num2seq,dtype=t.dtype)\n a = self.array([len(self.num2seq)],intent.in_,obj)\n if t.elsize==self.type.elsize:\n assert a.has_shared_memory(),`self.type.dtype,t.dtype`\n else:\n assert not a.has_shared_memory(),`t.dtype`\n\n def check_inout_2seq(self):\n obj = array(self.num2seq,dtype=self.type.dtype)\n a = self.array([len(self.num2seq)],intent.inout,obj)\n assert a.has_shared_memory()\n\n try:\n a = self.array([2],intent.in_.inout,self.num2seq)\n except TypeError,msg:\n if not str(msg).startswith('failed to initialize intent(inout|inplace|cache) array'):\n raise\n else:\n raise SystemError,'intent(inout) should have failed on sequence'\n\n def check_f_inout_23seq(self):\n obj = array(self.num23seq,dtype=self.type.dtype,fortran=1)\n shape = (len(self.num23seq),len(self.num23seq[0]))\n a = self.array(shape,intent.in_.inout,obj)\n assert a.has_shared_memory()\n\n obj = array(self.num23seq,dtype=self.type.dtype,fortran=0)\n shape = (len(self.num23seq),len(self.num23seq[0]))\n try:\n a = self.array(shape,intent.in_.inout,obj)\n except ValueError,msg:\n if not str(msg).startswith('failed to initialize intent(inout) array'):\n raise\n else:\n raise SystemError,'intent(inout) should have failed on improper array'\n\n def check_c_inout_23seq(self):\n obj = array(self.num23seq,dtype=self.type.dtype)\n shape = (len(self.num23seq),len(self.num23seq[0]))\n a = self.array(shape,intent.in_.c.inout,obj)\n assert a.has_shared_memory()\n\n def check_in_copy_from_2casttype(self):\n for t in self.type.cast_types():\n obj = array(self.num2seq,dtype=t.dtype)\n a = self.array([len(self.num2seq)],intent.in_.copy,obj)\n assert not a.has_shared_memory(),`t.dtype`\n\n def check_c_in_from_23seq(self):\n a = self.array([len(self.num23seq),len(self.num23seq[0])],\n intent.in_,self.num23seq)\n assert not a.has_shared_memory()\n\n def check_in_from_23casttype(self):\n for t in self.type.cast_types():\n obj = array(self.num23seq,dtype=t.dtype)\n a = self.array([len(self.num23seq),len(self.num23seq[0])],\n intent.in_,obj)\n assert not a.has_shared_memory(),`t.dtype`\n\n def check_f_in_from_23casttype(self):\n for t in self.type.cast_types():\n obj = array(self.num23seq,dtype=t.dtype,fortran=1)\n a = self.array([len(self.num23seq),len(self.num23seq[0])],\n intent.in_,obj)\n if t.elsize==self.type.elsize:\n assert a.has_shared_memory(),`t.dtype`\n else:\n assert not a.has_shared_memory(),`t.dtype`\n\n def check_c_in_from_23casttype(self):\n for t in self.type.cast_types():\n obj = array(self.num23seq,dtype=t.dtype)\n a = self.array([len(self.num23seq),len(self.num23seq[0])],\n intent.in_.c,obj)\n if t.elsize==self.type.elsize:\n assert a.has_shared_memory(),`t.dtype`\n else:\n assert not a.has_shared_memory(),`t.dtype`\n\n def check_f_copy_in_from_23casttype(self):\n for t in self.type.cast_types():\n obj = array(self.num23seq,dtype=t.dtype,fortran=1)\n a = self.array([len(self.num23seq),len(self.num23seq[0])],\n intent.in_.copy,obj)\n assert not a.has_shared_memory(),`t.dtype`\n\n def check_c_copy_in_from_23casttype(self):\n for t in self.type.cast_types():\n obj = array(self.num23seq,dtype=t.dtype)\n a = self.array([len(self.num23seq),len(self.num23seq[0])],\n intent.in_.c.copy,obj)\n assert not a.has_shared_memory(),`t.dtype`\n\n def check_in_cache_from_2casttype(self):\n for t in self.type.all_types():\n if t.elsize != self.type.elsize:\n continue\n obj = array(self.num2seq,dtype=t.dtype)\n shape = (len(self.num2seq),)\n a = self.array(shape,intent.in_.c.cache,obj) \n assert a.has_shared_memory(),`t.dtype`\n\n a = self.array(shape,intent.in_.cache,obj) \n assert a.has_shared_memory(),`t.dtype`\n \n obj = array(self.num2seq,dtype=t.dtype,fortran=1)\n a = self.array(shape,intent.in_.c.cache,obj) \n assert a.has_shared_memory(),`t.dtype`\n\n a = self.array(shape,intent.in_.cache,obj)\n assert a.has_shared_memory(),`t.dtype`\n\n try:\n a = self.array(shape,intent.in_.cache,obj[::-1])\n except ValueError,msg:\n if not str(msg).startswith('failed to initialize intent(cache) array'):\n raise\n else:\n raise SystemError,'intent(cache) should have failed on multisegmented array'\n def check_in_cache_from_2casttype_failure(self):\n for t in self.type.all_types():\n if t.elsize >= self.type.elsize:\n continue\n obj = array(self.num2seq,dtype=t.dtype)\n shape = (len(self.num2seq),)\n try:\n a = self.array(shape,intent.in_.cache,obj)\n except ValueError,msg:\n if not str(msg).startswith('failed to initialize intent(cache) array'):\n raise\n else:\n raise SystemError,'intent(cache) should have failed on smaller array'\n\n def check_cache_hidden(self):\n shape = (2,)\n a = self.array(shape,intent.cache.hide,None)\n assert a.arr.shape==shape\n\n shape = (2,3)\n a = self.array(shape,intent.cache.hide,None)\n assert a.arr.shape==shape\n\n shape = (-1,3)\n try:\n a = self.array(shape,intent.cache.hide,None)\n except ValueError,msg:\n if not str(msg).startswith('failed to create intent(cache|hide)|optional array'):\n raise\n else:\n raise SystemError,'intent(cache) should have failed on undefined dimensions'\n\n def check_hidden(self):\n shape = (2,)\n a = self.array(shape,intent.hide,None)\n assert a.arr.shape==shape\n assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))\n\n shape = (2,3)\n a = self.array(shape,intent.hide,None)\n assert a.arr.shape==shape\n assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))\n assert a.arr.flags['FORTRAN'] and not a.arr.flags['CONTIGUOUS']\n\n shape = (2,3)\n a = self.array(shape,intent.c.hide,None)\n assert a.arr.shape==shape\n assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))\n assert not a.arr.flags['FORTRAN'] and a.arr.flags['CONTIGUOUS']\n\n shape = (-1,3)\n try:\n a = self.array(shape,intent.hide,None)\n except ValueError,msg:\n if not str(msg).startswith('failed to create intent(cache|hide)|optional array'):\n raise\n else:\n raise SystemError,'intent(hide) should have failed on undefined dimensions'\n\n def check_optional_none(self):\n shape = (2,)\n a = self.array(shape,intent.optional,None)\n assert a.arr.shape==shape\n assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))\n\n shape = (2,3)\n a = self.array(shape,intent.optional,None)\n assert a.arr.shape==shape\n assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))\n assert a.arr.flags['FORTRAN'] and not a.arr.flags['CONTIGUOUS']\n\n shape = (2,3)\n a = self.array(shape,intent.c.optional,None)\n assert a.arr.shape==shape\n assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))\n assert not a.arr.flags['FORTRAN'] and a.arr.flags['CONTIGUOUS']\n\n def check_optional_from_2seq(self):\n obj = self.num2seq\n shape = (len(obj),)\n a = self.array(shape,intent.optional,obj)\n assert a.arr.shape==shape\n assert not a.has_shared_memory()\n\n def check_optional_from_23seq(self):\n obj = self.num23seq\n shape = (len(obj),len(obj[0]))\n a = self.array(shape,intent.optional,obj)\n assert a.arr.shape==shape\n assert not a.has_shared_memory()\n\n a = self.array(shape,intent.optional.c,obj)\n assert a.arr.shape==shape\n assert not a.has_shared_memory()\n\n def check_inplace(self):\n obj = array(self.num23seq,dtype=self.type.dtype)\n assert not obj.flags['FORTRAN'] and obj.flags['CONTIGUOUS']\n shape = obj.shape\n a = self.array(shape,intent.inplace,obj)\n assert obj[1][2]==a.arr[1][2],`obj,a.arr`\n a.arr[1][2]=54\n assert obj[1][2]==a.arr[1][2]==array(54,dtype=self.type.dtype),`obj,a.arr`\n assert a.arr is obj\n assert obj.flags['FORTRAN'] # obj attributes are changed inplace!\n assert not obj.flags['CONTIGUOUS']\n\n def check_inplace_from_casttype(self):\n for t in self.type.cast_types():\n if t is self.type:\n continue\n obj = array(self.num23seq,dtype=t.dtype)\n assert obj.dtype==t.dtype\n assert obj.dtype is not self.type.dtype\n assert not obj.flags['FORTRAN'] and obj.flags['CONTIGUOUS']\n shape = obj.shape\n a = self.array(shape,intent.inplace,obj)\n assert obj[1][2]==a.arr[1][2],`obj,a.arr`\n a.arr[1][2]=54\n assert obj[1][2]==a.arr[1][2]==array(54,dtype=self.type.dtype),`obj,a.arr`\n assert a.arr is obj\n assert obj.flags['FORTRAN'] # obj attributes are changed inplace!\n assert not obj.flags['CONTIGUOUS']\n assert obj.dtype is self.type.dtype # obj type is changed inplace!\n\nfor t in Type._type_names:\n exec '''\\\nclass test_%s_gen(unittest.TestCase,\n _test_shared_memory\n ):\n type = Type(%r)\n array = lambda self,dims,intent,obj: Array(Type(%r),dims,intent,obj)\n''' % (t,t,t)\n\nif __name__ == \"__main__\":\n ScipyTest().run()\n", "source_code_before": "import unittest\nimport sys\nimport copy\n\nfrom scipy.test.testing import *\nfrom scipy.base import array, typeinfo, alltrue, ndarray, asarray, can_cast\nset_package_path()\nfrom array_from_pyobj import wrap\ndel sys.path[0]\n\ndef flags_info(arr):\n flags = wrap.array_attrs(arr)[6]\n return flags2names(flags)\n\ndef flags2names(flags):\n info = []\n for flagname in ['CONTIGUOUS','FORTRAN','OWNDATA','ENSURECOPY',\n 'ENSUREARRAY','ALIGNED','NOTSWAPPED','WRITEABLE',\n 'UPDATEIFCOPY','BEHAVED_FLAGS','BEHAVED_FLAGS_RO',\n 'CARRAY_FLAGS','FARRAY_FLAGS'\n ]:\n if abs(flags) & getattr(wrap,flagname):\n info.append(flagname)\n return info\n\nclass Intent:\n def __init__(self,intent_list=[]):\n self.intent_list = intent_list[:]\n flags = 0\n for i in intent_list:\n if i=='optional':\n flags |= wrap.F2PY_OPTIONAL\n else:\n flags |= getattr(wrap,'F2PY_INTENT_'+i.upper())\n self.flags = flags\n def __getattr__(self,name):\n name = name.lower()\n if name=='in_': name='in'\n return self.__class__(self.intent_list+[name])\n def __str__(self):\n return 'intent(%s)' % (','.join(self.intent_list))\n def __repr__(self):\n return 'Intent(%r)' % (self.intent_list)\n def is_intent(self,*names):\n for name in names:\n if name not in self.intent_list:\n return False\n return True\n def is_intent_exact(self,*names):\n return len(self.intent_list)==len(names) and self.is_intent(*names)\n\nintent = Intent()\n\nclass Type(object):\n\n _type_names = ['BOOL','BYTE','UBYTE','SHORT','USHORT','INT','UINT',\n 'LONG','ULONG','LONGLONG','ULONGLONG',\n 'FLOAT','DOUBLE','LONGDOUBLE','CFLOAT','CDOUBLE',\n 'CLONGDOUBLE']\n _type_cache = {}\n\n _cast_dict = {'BOOL':['BOOL']}\n _cast_dict['BYTE'] = _cast_dict['BOOL'] + ['BYTE']\n _cast_dict['UBYTE'] = _cast_dict['BOOL'] + ['UBYTE']\n _cast_dict['BYTE'] = ['BYTE']\n _cast_dict['UBYTE'] = ['UBYTE']\n _cast_dict['SHORT'] = _cast_dict['BYTE'] + ['UBYTE','SHORT']\n _cast_dict['USHORT'] = _cast_dict['UBYTE'] + ['BYTE','USHORT']\n _cast_dict['INT'] = _cast_dict['SHORT'] + ['USHORT','INT']\n _cast_dict['UINT'] = _cast_dict['USHORT'] + ['SHORT','UINT']\n\n _cast_dict['LONG'] = _cast_dict['INT'] + ['LONG']\n _cast_dict['ULONG'] = _cast_dict['UINT'] + ['ULONG']\n\n _cast_dict['LONGLONG'] = _cast_dict['LONG'] + ['ULONG','LONGLONG']\n _cast_dict['ULONGLONG'] = _cast_dict['ULONG'] + ['LONG','ULONGLONG']\n\n _cast_dict['FLOAT'] = _cast_dict['SHORT'] + ['USHORT','FLOAT']\n _cast_dict['DOUBLE'] = _cast_dict['INT'] + ['UINT','FLOAT','DOUBLE']\n _cast_dict['LONGDOUBLE'] = _cast_dict['LONG'] + ['ULONG','FLOAT','DOUBLE','LONGDOUBLE']\n\n _cast_dict['CFLOAT'] = _cast_dict['FLOAT'] + ['CFLOAT']\n _cast_dict['CDOUBLE'] = _cast_dict['DOUBLE'] + ['CFLOAT','CDOUBLE']\n _cast_dict['CLONGDOUBLE'] = _cast_dict['LONGDOUBLE'] + ['CFLOAT','CDOUBLE','CLONGDOUBLE']\n \n \n def __new__(cls,name):\n if isinstance(name,type):\n dtype = name\n name = None\n for n,i in typeinfo.items():\n if isinstance(i,tuple) and dtype is i[-1]:\n name = n\n break\n obj = cls._type_cache.get(name.upper(),None)\n if obj is not None:\n return obj\n obj = object.__new__(cls)\n obj._init(name)\n cls._type_cache[name.upper()] = obj\n return obj\n \n def _init(self,name):\n self.NAME = name.upper()\n self.type_num = getattr(wrap,'PyArray_'+self.NAME)\n assert_equal(self.type_num,typeinfo[self.NAME][1])\n self.dtype = typeinfo[self.NAME][-1]\n self.elsize = typeinfo[self.NAME][2] / 8\n self.dtypechar = typeinfo[self.NAME][0]\n\n def cast_types(self):\n return map(Type,self._cast_dict[self.NAME])\n\n def smaller_types(self):\n bits = typeinfo[self.NAME][3]\n types = []\n for name in self._type_names:\n if typeinfo[name][3]bits:\n types.append(Type(name))\n return types\n\nclass Array:\n def __init__(self,typ,dims,intent,obj):\n self.type = typ\n self.dims = dims\n self.intent = intent\n self.obj_copy = copy.deepcopy(obj)\n self.obj = obj\n\n self.pyarr = array(array(obj,\n dtype = typ.dtypechar).reshape(*dims),\n fortran=not self.intent.is_intent('c'))\n assert self.pyarr.dtypechar==typ.dtypechar,\\\n `self.pyarr.dtypechar,typ.dtypechar`\n assert self.pyarr.flags['OWNDATA']\n self.pyarr_attr = wrap.array_attrs(self.pyarr)\n\n if len(dims)>1:\n if self.intent.is_intent('c'):\n assert not self.pyarr.flags['FORTRAN']\n assert self.pyarr.flags['CONTIGUOUS']\n assert not self.pyarr_attr[6] & wrap.FORTRAN\n else:\n assert self.pyarr.flags['FORTRAN']\n assert not self.pyarr.flags['CONTIGUOUS']\n assert self.pyarr_attr[6] & wrap.FORTRAN\n\n # arr.dtypechar may be different from typ.dtypechar\n self.arr = wrap.call(typ.type_num,dims,intent.flags,obj)\n\n self.arr_attr = wrap.array_attrs(self.arr)\n\n if len(dims)>1:\n if self.intent.is_intent('c'):\n assert intent.flags & wrap.F2PY_INTENT_C\n assert not self.arr.flags['FORTRAN'],`self.arr.flags,obj.flags`\n assert self.arr.flags['CONTIGUOUS']\n assert not self.arr_attr[6] & wrap.FORTRAN\n else:\n assert not intent.flags & wrap.F2PY_INTENT_C\n assert self.arr.flags['FORTRAN']\n assert not self.arr.flags['CONTIGUOUS']\n assert self.arr_attr[6] & wrap.FORTRAN\n\n assert self.arr_attr[1]==self.pyarr_attr[1] # nd\n assert self.arr_attr[2]==self.pyarr_attr[2] # dimensions\n if self.arr_attr[1]<=1:\n assert self.arr_attr[3]==self.pyarr_attr[3],\\\n `self.arr_attr[3],self.pyarr_attr[3],self.arr.tostring(),self.pyarr.tostring()` # strides\n assert self.arr_attr[5][-2:]==self.pyarr_attr[5][-2:],\\\n `self.arr_attr[5],self.pyarr_attr[5]` # descr\n assert self.arr_attr[6]==self.pyarr_attr[6],\\\n `self.arr_attr[6],self.pyarr_attr[6],flags2names(0*self.arr_attr[6]-self.pyarr_attr[6]),flags2names(self.arr_attr[6]),intent` # flags\n\n assert self.arr_attr[5][3]==self.type.elsize,\\\n `self.arr_attr[5][3],self.type.elsize`\n assert self.arr_equal(self.pyarr,self.arr)\n \n if isinstance(self.obj,ndarray):\n if typ.elsize==Type(obj.dtype).elsize:\n if not intent.is_intent('copy') and self.arr_attr[1]<=1:\n assert self.has_shared_memory()\n\n def arr_equal(self,arr1,arr2):\n if arr1.shape != arr2.shape:\n return False\n return alltrue(arr1==arr2)\n\n def __str__(self):\n return str(self.arr)\n\n def has_shared_memory(self):\n \"\"\"Check that created array shares data with input array.\n \"\"\"\n if self.obj is self.arr:\n return True\n if not isinstance(self.obj,ndarray):\n return False\n obj_attr = wrap.array_attrs(self.obj)\n return obj_attr[0]==self.arr_attr[0]\n\n##################################################\n\nclass test_intent(unittest.TestCase):\n def check_in_out(self):\n assert_equal(str(intent.in_.out),'intent(in,out)')\n assert intent.in_.c.is_intent('c')\n assert not intent.in_.c.is_intent_exact('c')\n assert intent.in_.c.is_intent_exact('c','in')\n assert intent.in_.c.is_intent_exact('in','c')\n assert not intent.in_.is_intent('c')\n\nclass _test_shared_memory:\n num2seq = [1,2]\n num23seq = [[1,2,3],[4,5,6]]\n def check_in_from_2seq(self):\n a = self.array([2],intent.in_,self.num2seq)\n assert not a.has_shared_memory()\n\n def check_in_from_2casttype(self):\n for t in self.type.cast_types():\n obj = array(self.num2seq,dtype=t.dtype)\n a = self.array([len(self.num2seq)],intent.in_,obj)\n if t.elsize==self.type.elsize:\n assert a.has_shared_memory(),`self.type.dtype,t.dtype`\n else:\n assert not a.has_shared_memory(),`t.dtype`\n\n def check_in_copy_from_2casttype(self):\n for t in self.type.cast_types():\n obj = array(self.num2seq,dtype=t.dtype)\n a = self.array([len(self.num2seq)],intent.in_.copy,obj)\n assert not a.has_shared_memory(),`t.dtype`\n\n def check_c_in_from_23seq(self):\n a = self.array([len(self.num23seq),len(self.num23seq[0])],\n intent.in_,self.num23seq)\n assert not a.has_shared_memory()\n\n def check_in_from_23casttype(self):\n for t in self.type.cast_types():\n obj = array(self.num23seq,dtype=t.dtype)\n a = self.array([len(self.num23seq),len(self.num23seq[0])],\n intent.in_,obj)\n assert not a.has_shared_memory(),`t.dtype`\n\n def check_f_in_from_23casttype(self):\n for t in self.type.cast_types():\n obj = array(self.num23seq,dtype=t.dtype,fortran=1)\n a = self.array([len(self.num23seq),len(self.num23seq[0])],\n intent.in_,obj)\n if t.elsize==self.type.elsize:\n assert a.has_shared_memory(),`t.dtype`\n else:\n assert not a.has_shared_memory(),`t.dtype`\n\n def check_c_in_from_23casttype(self):\n for t in self.type.cast_types():\n obj = array(self.num23seq,dtype=t.dtype)\n a = self.array([len(self.num23seq),len(self.num23seq[0])],\n intent.in_.c,obj)\n if t.elsize==self.type.elsize:\n assert a.has_shared_memory(),`t.dtype`\n else:\n assert not a.has_shared_memory(),`t.dtype`\n\n def check_f_copy_in_from_23casttype(self):\n for t in self.type.cast_types():\n obj = array(self.num23seq,dtype=t.dtype,fortran=1)\n a = self.array([len(self.num23seq),len(self.num23seq[0])],\n intent.in_.copy,obj)\n assert not a.has_shared_memory(),`t.dtype`\n\n def check_c_copy_in_from_23casttype(self):\n for t in self.type.cast_types():\n obj = array(self.num23seq,dtype=t.dtype)\n a = self.array([len(self.num23seq),len(self.num23seq[0])],\n intent.in_.c.copy,obj)\n assert not a.has_shared_memory(),`t.dtype`\n\n\nfor t in Type._type_names:\n exec '''\\\nclass test_%s(unittest.TestCase,\n _test_shared_memory\n ):\n type = Type(%r)\n array = lambda self,dims,intent,obj: Array(Type(%r),dims,intent,obj)\n''' % (t,t,t)\n\nif __name__ == \"__main__\":\n ScipyTest().run()\n", "methods": [ { "name": "flags_info", "long_name": "flags_info( arr )", "filename": "test_array_from_pyobj.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "arr" ], "start_line": 11, "end_line": 13, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "flags2names", "long_name": "flags2names( flags )", "filename": "test_array_from_pyobj.py", "nloc": 10, "complexity": 3, "token_count": 61, "parameters": [ "flags" ], "start_line": 15, "end_line": 24, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , intent_list = [ ] )", "filename": "test_array_from_pyobj.py", "nloc": 9, "complexity": 3, "token_count": 57, "parameters": [ "self", "intent_list" ], "start_line": 27, "end_line": 35, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "test_array_from_pyobj.py", "nloc": 4, "complexity": 2, "token_count": 35, "parameters": [ "self", "name" ], "start_line": 36, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "test_array_from_pyobj.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 40, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "test_array_from_pyobj.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 42, "end_line": 43, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "is_intent", "long_name": "is_intent( self , * names )", "filename": "test_array_from_pyobj.py", "nloc": 5, "complexity": 3, "token_count": 25, "parameters": [ "self", "names" ], "start_line": 44, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "is_intent_exact", "long_name": "is_intent_exact( self , * names )", "filename": "test_array_from_pyobj.py", "nloc": 2, "complexity": 2, "token_count": 28, "parameters": [ "self", "names" ], "start_line": 49, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__new__", "long_name": "__new__( cls , name )", "filename": "test_array_from_pyobj.py", "nloc": 15, "complexity": 6, "token_count": 104, "parameters": [ "cls", "name" ], "start_line": 87, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "_init", "long_name": "_init( self , name )", "filename": "test_array_from_pyobj.py", "nloc": 7, "complexity": 1, "token_count": 88, "parameters": [ "self", "name" ], "start_line": 103, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "cast_types", "long_name": "cast_types( self )", "filename": "test_array_from_pyobj.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 111, "end_line": 112, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "all_types", "long_name": "all_types( self )", "filename": "test_array_from_pyobj.py", "nloc": 2, "complexity": 1, "token_count": 16, "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": "smaller_types", "long_name": "smaller_types( self )", "filename": "test_array_from_pyobj.py", "nloc": 7, "complexity": 3, "token_count": 49, "parameters": [ "self" ], "start_line": 117, "end_line": 123, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "equal_types", "long_name": "equal_types( self )", "filename": "test_array_from_pyobj.py", "nloc": 8, "complexity": 4, "token_count": 57, "parameters": [ "self" ], "start_line": 125, "end_line": 132, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "larger_types", "long_name": "larger_types( self )", "filename": "test_array_from_pyobj.py", "nloc": 7, "complexity": 3, "token_count": 49, "parameters": [ "self" ], "start_line": 134, "end_line": 140, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , typ , dims , intent , obj )", "filename": "test_array_from_pyobj.py", "nloc": 63, "complexity": 13, "token_count": 728, "parameters": [ "self", "typ", "dims", "intent", "obj" ], "start_line": 143, "end_line": 217, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 1 }, { "name": "arr_equal", "long_name": "arr_equal( self , arr1 , arr2 )", "filename": "test_array_from_pyobj.py", "nloc": 4, "complexity": 2, "token_count": 27, "parameters": [ "self", "arr1", "arr2" ], "start_line": 219, "end_line": 222, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "test_array_from_pyobj.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 224, "end_line": 225, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "has_shared_memory", "long_name": "has_shared_memory( self )", "filename": "test_array_from_pyobj.py", "nloc": 7, "complexity": 3, "token_count": 52, "parameters": [ "self" ], "start_line": 227, "end_line": 235, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_in_out", "long_name": "check_in_out( self )", "filename": "test_array_from_pyobj.py", "nloc": 7, "complexity": 1, "token_count": 77, "parameters": [ "self" ], "start_line": 240, "end_line": 246, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_in_from_2seq", "long_name": "check_in_from_2seq( self )", "filename": "test_array_from_pyobj.py", "nloc": 3, "complexity": 1, "token_count": 30, "parameters": [ "self" ], "start_line": 251, "end_line": 253, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_in_from_2casttype", "long_name": "check_in_from_2casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 8, "complexity": 3, "token_count": 95, "parameters": [ "self" ], "start_line": 255, "end_line": 262, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_inout_2seq", "long_name": "check_inout_2seq( self )", "filename": "test_array_from_pyobj.py", "nloc": 11, "complexity": 3, "token_count": 94, "parameters": [ "self" ], "start_line": 264, "end_line": 275, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "check_f_inout_23seq", "long_name": "check_f_inout_23seq( self )", "filename": "test_array_from_pyobj.py", "nloc": 14, "complexity": 3, "token_count": 149, "parameters": [ "self" ], "start_line": 277, "end_line": 291, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "check_c_inout_23seq", "long_name": "check_c_inout_23seq( self )", "filename": "test_array_from_pyobj.py", "nloc": 5, "complexity": 1, "token_count": 65, "parameters": [ "self" ], "start_line": 293, "end_line": 297, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_in_copy_from_2casttype", "long_name": "check_in_copy_from_2casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 5, "complexity": 2, "token_count": 66, "parameters": [ "self" ], "start_line": 299, "end_line": 303, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_c_in_from_23seq", "long_name": "check_c_in_from_23seq( self )", "filename": "test_array_from_pyobj.py", "nloc": 4, "complexity": 1, "token_count": 45, "parameters": [ "self" ], "start_line": 305, "end_line": 308, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_in_from_23casttype", "long_name": "check_in_from_23casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 6, "complexity": 2, "token_count": 74, "parameters": [ "self" ], "start_line": 310, "end_line": 315, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_f_in_from_23casttype", "long_name": "check_f_in_from_23casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 9, "complexity": 3, "token_count": 103, "parameters": [ "self" ], "start_line": 317, "end_line": 325, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_c_in_from_23casttype", "long_name": "check_c_in_from_23casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 9, "complexity": 3, "token_count": 101, "parameters": [ "self" ], "start_line": 327, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_f_copy_in_from_23casttype", "long_name": "check_f_copy_in_from_23casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 6, "complexity": 2, "token_count": 80, "parameters": [ "self" ], "start_line": 337, "end_line": 342, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_c_copy_in_from_23casttype", "long_name": "check_c_copy_in_from_23casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 6, "complexity": 2, "token_count": 78, "parameters": [ "self" ], "start_line": 344, "end_line": 349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_in_cache_from_2casttype", "long_name": "check_in_cache_from_2casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 22, "complexity": 5, "token_count": 234, "parameters": [ "self" ], "start_line": 351, "end_line": 376, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "check_in_cache_from_2casttype_failure", "long_name": "check_in_cache_from_2casttype_failure( self )", "filename": "test_array_from_pyobj.py", "nloc": 13, "complexity": 5, "token_count": 95, "parameters": [ "self" ], "start_line": 377, "end_line": 389, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "check_cache_hidden", "long_name": "check_cache_hidden( self )", "filename": "test_array_from_pyobj.py", "nloc": 15, "complexity": 3, "token_count": 116, "parameters": [ "self" ], "start_line": 391, "end_line": 407, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "check_hidden", "long_name": "check_hidden( self )", "filename": "test_array_from_pyobj.py", "nloc": 23, "complexity": 5, "token_count": 245, "parameters": [ "self" ], "start_line": 409, "end_line": 434, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "check_optional_none", "long_name": "check_optional_none( self )", "filename": "test_array_from_pyobj.py", "nloc": 15, "complexity": 3, "token_count": 197, "parameters": [ "self" ], "start_line": 436, "end_line": 452, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "check_optional_from_2seq", "long_name": "check_optional_from_2seq( self )", "filename": "test_array_from_pyobj.py", "nloc": 6, "complexity": 1, "token_count": 48, "parameters": [ "self" ], "start_line": 454, "end_line": 459, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_optional_from_23seq", "long_name": "check_optional_from_23seq( self )", "filename": "test_array_from_pyobj.py", "nloc": 9, "complexity": 1, "token_count": 86, "parameters": [ "self" ], "start_line": 461, "end_line": 470, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "check_inplace", "long_name": "check_inplace( self )", "filename": "test_array_from_pyobj.py", "nloc": 11, "complexity": 2, "token_count": 152, "parameters": [ "self" ], "start_line": 472, "end_line": 482, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "check_inplace_from_casttype", "long_name": "check_inplace_from_casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 17, "complexity": 4, "token_count": 198, "parameters": [ "self" ], "start_line": 484, "end_line": 500, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 } ], "methods_before": [ { "name": "flags_info", "long_name": "flags_info( arr )", "filename": "test_array_from_pyobj.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "arr" ], "start_line": 11, "end_line": 13, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "flags2names", "long_name": "flags2names( flags )", "filename": "test_array_from_pyobj.py", "nloc": 10, "complexity": 3, "token_count": 61, "parameters": [ "flags" ], "start_line": 15, "end_line": 24, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , intent_list = [ ] )", "filename": "test_array_from_pyobj.py", "nloc": 9, "complexity": 3, "token_count": 57, "parameters": [ "self", "intent_list" ], "start_line": 27, "end_line": 35, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "test_array_from_pyobj.py", "nloc": 4, "complexity": 2, "token_count": 35, "parameters": [ "self", "name" ], "start_line": 36, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "test_array_from_pyobj.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 40, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "test_array_from_pyobj.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 42, "end_line": 43, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "is_intent", "long_name": "is_intent( self , * names )", "filename": "test_array_from_pyobj.py", "nloc": 5, "complexity": 3, "token_count": 25, "parameters": [ "self", "names" ], "start_line": 44, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "is_intent_exact", "long_name": "is_intent_exact( self , * names )", "filename": "test_array_from_pyobj.py", "nloc": 2, "complexity": 2, "token_count": 28, "parameters": [ "self", "names" ], "start_line": 49, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__new__", "long_name": "__new__( cls , name )", "filename": "test_array_from_pyobj.py", "nloc": 15, "complexity": 6, "token_count": 104, "parameters": [ "cls", "name" ], "start_line": 87, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "_init", "long_name": "_init( self , name )", "filename": "test_array_from_pyobj.py", "nloc": 7, "complexity": 1, "token_count": 88, "parameters": [ "self", "name" ], "start_line": 103, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "cast_types", "long_name": "cast_types( self )", "filename": "test_array_from_pyobj.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 111, "end_line": 112, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "smaller_types", "long_name": "smaller_types( self )", "filename": "test_array_from_pyobj.py", "nloc": 7, "complexity": 3, "token_count": 49, "parameters": [ "self" ], "start_line": 114, "end_line": 120, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "equal_types", "long_name": "equal_types( self )", "filename": "test_array_from_pyobj.py", "nloc": 8, "complexity": 4, "token_count": 57, "parameters": [ "self" ], "start_line": 122, "end_line": 129, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "larger_types", "long_name": "larger_types( self )", "filename": "test_array_from_pyobj.py", "nloc": 7, "complexity": 3, "token_count": 49, "parameters": [ "self" ], "start_line": 131, "end_line": 137, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , typ , dims , intent , obj )", "filename": "test_array_from_pyobj.py", "nloc": 51, "complexity": 10, "token_count": 629, "parameters": [ "self", "typ", "dims", "intent", "obj" ], "start_line": 140, "end_line": 199, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 60, "top_nesting_level": 1 }, { "name": "arr_equal", "long_name": "arr_equal( self , arr1 , arr2 )", "filename": "test_array_from_pyobj.py", "nloc": 4, "complexity": 2, "token_count": 27, "parameters": [ "self", "arr1", "arr2" ], "start_line": 201, "end_line": 204, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "test_array_from_pyobj.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 206, "end_line": 207, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "has_shared_memory", "long_name": "has_shared_memory( self )", "filename": "test_array_from_pyobj.py", "nloc": 7, "complexity": 3, "token_count": 52, "parameters": [ "self" ], "start_line": 209, "end_line": 217, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_in_out", "long_name": "check_in_out( self )", "filename": "test_array_from_pyobj.py", "nloc": 7, "complexity": 1, "token_count": 77, "parameters": [ "self" ], "start_line": 222, "end_line": 228, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_in_from_2seq", "long_name": "check_in_from_2seq( self )", "filename": "test_array_from_pyobj.py", "nloc": 3, "complexity": 1, "token_count": 30, "parameters": [ "self" ], "start_line": 233, "end_line": 235, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_in_from_2casttype", "long_name": "check_in_from_2casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 8, "complexity": 3, "token_count": 95, "parameters": [ "self" ], "start_line": 237, "end_line": 244, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_in_copy_from_2casttype", "long_name": "check_in_copy_from_2casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 5, "complexity": 2, "token_count": 66, "parameters": [ "self" ], "start_line": 246, "end_line": 250, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_c_in_from_23seq", "long_name": "check_c_in_from_23seq( self )", "filename": "test_array_from_pyobj.py", "nloc": 4, "complexity": 1, "token_count": 45, "parameters": [ "self" ], "start_line": 252, "end_line": 255, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_in_from_23casttype", "long_name": "check_in_from_23casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 6, "complexity": 2, "token_count": 74, "parameters": [ "self" ], "start_line": 257, "end_line": 262, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_f_in_from_23casttype", "long_name": "check_f_in_from_23casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 9, "complexity": 3, "token_count": 103, "parameters": [ "self" ], "start_line": 264, "end_line": 272, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_c_in_from_23casttype", "long_name": "check_c_in_from_23casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 9, "complexity": 3, "token_count": 101, "parameters": [ "self" ], "start_line": 274, "end_line": 282, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_f_copy_in_from_23casttype", "long_name": "check_f_copy_in_from_23casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 6, "complexity": 2, "token_count": 80, "parameters": [ "self" ], "start_line": 284, "end_line": 289, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_c_copy_in_from_23casttype", "long_name": "check_c_copy_in_from_23casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 6, "complexity": 2, "token_count": 78, "parameters": [ "self" ], "start_line": 291, "end_line": 296, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "check_optional_from_2seq", "long_name": "check_optional_from_2seq( self )", "filename": "test_array_from_pyobj.py", "nloc": 6, "complexity": 1, "token_count": 48, "parameters": [ "self" ], "start_line": 454, "end_line": 459, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_in_cache_from_2casttype", "long_name": "check_in_cache_from_2casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 22, "complexity": 5, "token_count": 234, "parameters": [ "self" ], "start_line": 351, "end_line": 376, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "cast_types", "long_name": "cast_types( self )", "filename": "test_array_from_pyobj.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 111, "end_line": 112, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_inout_2seq", "long_name": "check_inout_2seq( self )", "filename": "test_array_from_pyobj.py", "nloc": 11, "complexity": 3, "token_count": 94, "parameters": [ "self" ], "start_line": 264, "end_line": 275, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "all_types", "long_name": "all_types( self )", "filename": "test_array_from_pyobj.py", "nloc": 2, "complexity": 1, "token_count": 16, "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": "check_inplace", "long_name": "check_inplace( self )", "filename": "test_array_from_pyobj.py", "nloc": 11, "complexity": 2, "token_count": 152, "parameters": [ "self" ], "start_line": 472, "end_line": 482, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "check_f_inout_23seq", "long_name": "check_f_inout_23seq( self )", "filename": "test_array_from_pyobj.py", "nloc": 14, "complexity": 3, "token_count": 149, "parameters": [ "self" ], "start_line": 277, "end_line": 291, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "check_in_cache_from_2casttype_failure", "long_name": "check_in_cache_from_2casttype_failure( self )", "filename": "test_array_from_pyobj.py", "nloc": 13, "complexity": 5, "token_count": 95, "parameters": [ "self" ], "start_line": 377, "end_line": 389, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "check_hidden", "long_name": "check_hidden( self )", "filename": "test_array_from_pyobj.py", "nloc": 23, "complexity": 5, "token_count": 245, "parameters": [ "self" ], "start_line": 409, "end_line": 434, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "check_optional_from_23seq", "long_name": "check_optional_from_23seq( self )", "filename": "test_array_from_pyobj.py", "nloc": 9, "complexity": 1, "token_count": 86, "parameters": [ "self" ], "start_line": 461, "end_line": 470, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "check_inplace_from_casttype", "long_name": "check_inplace_from_casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 17, "complexity": 4, "token_count": 198, "parameters": [ "self" ], "start_line": 484, "end_line": 500, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "check_c_inout_23seq", "long_name": "check_c_inout_23seq( self )", "filename": "test_array_from_pyobj.py", "nloc": 5, "complexity": 1, "token_count": 65, "parameters": [ "self" ], "start_line": 293, "end_line": 297, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_cache_hidden", "long_name": "check_cache_hidden( self )", "filename": "test_array_from_pyobj.py", "nloc": 15, "complexity": 3, "token_count": 116, "parameters": [ "self" ], "start_line": 391, "end_line": 407, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , typ , dims , intent , obj )", "filename": "test_array_from_pyobj.py", "nloc": 63, "complexity": 13, "token_count": 728, "parameters": [ "self", "typ", "dims", "intent", "obj" ], "start_line": 143, "end_line": 217, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 1 }, { "name": "check_optional_none", "long_name": "check_optional_none( self )", "filename": "test_array_from_pyobj.py", "nloc": 15, "complexity": 3, "token_count": 197, "parameters": [ "self" ], "start_line": 436, "end_line": 452, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 } ], "nloc": 435, "complexity": 110, "token_count": 4363, "diff_parsed": { "added": [ "from scipy.base import array, typeinfo, alltrue, ndarray, asarray, can_cast,zeros", " return map(self.__class__,self._cast_dict[self.NAME])", "", " def all_types(self):", " return map(self.__class__,self._type_names)", " if obj is None:", " self.pyarr = None", " self.pyarr_attr = None", " return", "", " if intent.is_intent('cache'):", " assert isinstance(obj,ndarray),`type(obj)`", " self.pyarr = array(obj).reshape(*dims)", "", " else:", " self.pyarr = array(array(obj,", " dtype = typ.dtypechar).reshape(*dims),", " fortran=not self.intent.is_intent('c'))", " assert self.pyarr.dtypechar==typ.dtypechar,\\", " `self.pyarr.dtypechar,typ.dtypechar`", " assert self.pyarr.flags['OWNDATA']", " self.pyarr_attr = wrap.array_attrs(self.pyarr)", "", " if len(dims)>1:", " if self.intent.is_intent('c'):", " assert not self.pyarr.flags['FORTRAN']", " assert self.pyarr.flags['CONTIGUOUS']", " assert not self.pyarr_attr[6] & wrap.FORTRAN", " else:", " assert self.pyarr.flags['FORTRAN']", " assert not self.pyarr.flags['CONTIGUOUS']", " assert self.pyarr_attr[6] & wrap.FORTRAN", "", "", " if intent.is_intent('cache'):", " assert self.arr_attr[5][3]>=self.type.elsize,\\", " `self.arr_attr[5][3],self.type.elsize`", " else:", " assert self.arr_attr[5][3]==self.type.elsize,\\", " `self.arr_attr[5][3],self.type.elsize`", " def check_inout_2seq(self):", " obj = array(self.num2seq,dtype=self.type.dtype)", " a = self.array([len(self.num2seq)],intent.inout,obj)", " assert a.has_shared_memory()", "", " try:", " a = self.array([2],intent.in_.inout,self.num2seq)", " except TypeError,msg:", " if not str(msg).startswith('failed to initialize intent(inout|inplace|cache) array'):", " raise", " else:", " raise SystemError,'intent(inout) should have failed on sequence'", "", " def check_f_inout_23seq(self):", " obj = array(self.num23seq,dtype=self.type.dtype,fortran=1)", " shape = (len(self.num23seq),len(self.num23seq[0]))", " a = self.array(shape,intent.in_.inout,obj)", " assert a.has_shared_memory()", "", " obj = array(self.num23seq,dtype=self.type.dtype,fortran=0)", " shape = (len(self.num23seq),len(self.num23seq[0]))", " try:", " a = self.array(shape,intent.in_.inout,obj)", " except ValueError,msg:", " if not str(msg).startswith('failed to initialize intent(inout) array'):", " raise", " else:", " raise SystemError,'intent(inout) should have failed on improper array'", "", " def check_c_inout_23seq(self):", " obj = array(self.num23seq,dtype=self.type.dtype)", " shape = (len(self.num23seq),len(self.num23seq[0]))", " a = self.array(shape,intent.in_.c.inout,obj)", " assert a.has_shared_memory()", "", " def check_in_cache_from_2casttype(self):", " for t in self.type.all_types():", " if t.elsize != self.type.elsize:", " continue", " obj = array(self.num2seq,dtype=t.dtype)", " shape = (len(self.num2seq),)", " a = self.array(shape,intent.in_.c.cache,obj)", " assert a.has_shared_memory(),`t.dtype`", "", " a = self.array(shape,intent.in_.cache,obj)", " assert a.has_shared_memory(),`t.dtype`", "", " obj = array(self.num2seq,dtype=t.dtype,fortran=1)", " a = self.array(shape,intent.in_.c.cache,obj)", " assert a.has_shared_memory(),`t.dtype`", "", " a = self.array(shape,intent.in_.cache,obj)", " assert a.has_shared_memory(),`t.dtype`", "", " try:", " a = self.array(shape,intent.in_.cache,obj[::-1])", " except ValueError,msg:", " if not str(msg).startswith('failed to initialize intent(cache) array'):", " raise", " else:", " raise SystemError,'intent(cache) should have failed on multisegmented array'", " def check_in_cache_from_2casttype_failure(self):", " for t in self.type.all_types():", " if t.elsize >= self.type.elsize:", " continue", " obj = array(self.num2seq,dtype=t.dtype)", " shape = (len(self.num2seq),)", " try:", " a = self.array(shape,intent.in_.cache,obj)", " except ValueError,msg:", " if not str(msg).startswith('failed to initialize intent(cache) array'):", " raise", " else:", " raise SystemError,'intent(cache) should have failed on smaller array'", "", " def check_cache_hidden(self):", " shape = (2,)", " a = self.array(shape,intent.cache.hide,None)", " assert a.arr.shape==shape", "", " shape = (2,3)", " a = self.array(shape,intent.cache.hide,None)", " assert a.arr.shape==shape", "", " shape = (-1,3)", " try:", " a = self.array(shape,intent.cache.hide,None)", " except ValueError,msg:", " if not str(msg).startswith('failed to create intent(cache|hide)|optional array'):", " raise", " else:", " raise SystemError,'intent(cache) should have failed on undefined dimensions'", "", " def check_hidden(self):", " shape = (2,)", " a = self.array(shape,intent.hide,None)", " assert a.arr.shape==shape", " assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))", "", " shape = (2,3)", " a = self.array(shape,intent.hide,None)", " assert a.arr.shape==shape", " assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))", " assert a.arr.flags['FORTRAN'] and not a.arr.flags['CONTIGUOUS']", "", " shape = (2,3)", " a = self.array(shape,intent.c.hide,None)", " assert a.arr.shape==shape", " assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))", " assert not a.arr.flags['FORTRAN'] and a.arr.flags['CONTIGUOUS']", "", " shape = (-1,3)", " try:", " a = self.array(shape,intent.hide,None)", " except ValueError,msg:", " if not str(msg).startswith('failed to create intent(cache|hide)|optional array'):", " raise", " else:", " raise SystemError,'intent(hide) should have failed on undefined dimensions'", "", " def check_optional_none(self):", " shape = (2,)", " a = self.array(shape,intent.optional,None)", " assert a.arr.shape==shape", " assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))", "", " shape = (2,3)", " a = self.array(shape,intent.optional,None)", " assert a.arr.shape==shape", " assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))", " assert a.arr.flags['FORTRAN'] and not a.arr.flags['CONTIGUOUS']", "", " shape = (2,3)", " a = self.array(shape,intent.c.optional,None)", " assert a.arr.shape==shape", " assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))", " assert not a.arr.flags['FORTRAN'] and a.arr.flags['CONTIGUOUS']", "", " def check_optional_from_2seq(self):", " obj = self.num2seq", " shape = (len(obj),)", " a = self.array(shape,intent.optional,obj)", " assert a.arr.shape==shape", " assert not a.has_shared_memory()", "", " def check_optional_from_23seq(self):", " obj = self.num23seq", " shape = (len(obj),len(obj[0]))", " a = self.array(shape,intent.optional,obj)", " assert a.arr.shape==shape", " assert not a.has_shared_memory()", "", " a = self.array(shape,intent.optional.c,obj)", " assert a.arr.shape==shape", " assert not a.has_shared_memory()", "", " def check_inplace(self):", " obj = array(self.num23seq,dtype=self.type.dtype)", " assert not obj.flags['FORTRAN'] and obj.flags['CONTIGUOUS']", " shape = obj.shape", " a = self.array(shape,intent.inplace,obj)", " assert obj[1][2]==a.arr[1][2],`obj,a.arr`", " a.arr[1][2]=54", " assert obj[1][2]==a.arr[1][2]==array(54,dtype=self.type.dtype),`obj,a.arr`", " assert a.arr is obj", " assert obj.flags['FORTRAN'] # obj attributes are changed inplace!", " assert not obj.flags['CONTIGUOUS']", "", " def check_inplace_from_casttype(self):", " for t in self.type.cast_types():", " if t is self.type:", " continue", " obj = array(self.num23seq,dtype=t.dtype)", " assert obj.dtype==t.dtype", " assert obj.dtype is not self.type.dtype", " assert not obj.flags['FORTRAN'] and obj.flags['CONTIGUOUS']", " shape = obj.shape", " a = self.array(shape,intent.inplace,obj)", " assert obj[1][2]==a.arr[1][2],`obj,a.arr`", " a.arr[1][2]=54", " assert obj[1][2]==a.arr[1][2]==array(54,dtype=self.type.dtype),`obj,a.arr`", " assert a.arr is obj", " assert obj.flags['FORTRAN'] # obj attributes are changed inplace!", " assert not obj.flags['CONTIGUOUS']", " assert obj.dtype is self.type.dtype # obj type is changed inplace!", "class test_%s_gen(unittest.TestCase," ], "deleted": [ "from scipy.base import array, typeinfo, alltrue, ndarray, asarray, can_cast", " return map(Type,self._cast_dict[self.NAME])", " self.pyarr = array(array(obj,", " dtype = typ.dtypechar).reshape(*dims),", " fortran=not self.intent.is_intent('c'))", " assert self.pyarr.dtypechar==typ.dtypechar,\\", " `self.pyarr.dtypechar,typ.dtypechar`", " assert self.pyarr.flags['OWNDATA']", " self.pyarr_attr = wrap.array_attrs(self.pyarr)", "", " if len(dims)>1:", " if self.intent.is_intent('c'):", " assert not self.pyarr.flags['FORTRAN']", " assert self.pyarr.flags['CONTIGUOUS']", " assert not self.pyarr_attr[6] & wrap.FORTRAN", " else:", " assert self.pyarr.flags['FORTRAN']", " assert not self.pyarr.flags['CONTIGUOUS']", " assert self.pyarr_attr[6] & wrap.FORTRAN", "", " assert self.arr_attr[5][3]==self.type.elsize,\\", " `self.arr_attr[5][3],self.type.elsize`", "class test_%s(unittest.TestCase," ] } }, { "old_path": "scipy/f2py2e/tests/array_from_pyobj/wrapmodule.c", "new_path": "scipy/f2py2e/tests/array_from_pyobj/wrapmodule.c", "filename": "wrapmodule.c", "extension": "c", "change_type": "MODIFY", "diff": "@@ -184,6 +184,10 @@ DL_EXPORT(void) initwrap(void) {\n if (PyErr_Occurred())\n Py_FatalError(\"can't initialize module wrap\");\n \n+#ifdef F2PY_REPORT_ATEXIT\n+ on_exit(f2py_report_on_exit,(void*)\"array_from_pyobj.wrap.call\");\n+#endif\n+\n }\n #ifdef __cplusplus\n }\n", "added_lines": 4, "deleted_lines": 0, "source_code": "/* File: wrapmodule.c\n * This file is auto-generated with f2py (version:2_1330).\n * Hand edited by Pearu.\n * f2py is a Fortran to Python Interface Generator (FPIG), Second Edition,\n * written by Pearu Peterson .\n * See http://cens.ioc.ee/projects/f2py2e/\n * Generation date: Fri Oct 21 22:41:12 2005\n * $Revision:$\n * $Date:$\n * Do not edit this file directly unless you know what you are doing!!!\n */\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n/*********************** See f2py2e/cfuncs.py: includes ***********************/\n#include \"Python.h\"\n#include \"fortranobject.h\"\n#include \n\nstatic PyObject *wrap_error;\nstatic PyObject *wrap_module;\n\n/************************************ call ************************************/\nstatic char doc_f2py_rout_wrap_call[] = \"\\\nFunction signature:\\n\\\n arr = call(type_num,dims,intent,obj)\\n\\\nRequired arguments:\\n\"\n\" type_num : input int\\n\"\n\" dims : input int-sequence\\n\"\n\" intent : input int\\n\"\n\" obj : input python object\\n\"\n\"Return objects:\\n\"\n\" arr : array\";\nstatic PyObject *f2py_rout_wrap_call(PyObject *capi_self,\n\t\t\t\t PyObject *capi_args) {\n PyObject * volatile capi_buildvalue = NULL;\n int type_num = 0;\n intp *dims = NULL;\n PyObject *dims_capi = Py_None;\n int rank = 0;\n int intent = 0;\n PyArrayObject *capi_arr_tmp = NULL;\n PyObject *arr_capi = Py_None;\n int i;\n\n if (!PyArg_ParseTuple(capi_args,\"iOiO|:wrap.call\",\\\n\t\t\t&type_num,&dims_capi,&intent,&arr_capi))\n return NULL;\n rank = PySequence_Length(dims_capi);\n dims = malloc(rank*sizeof(intp));\n for (i=0;idata);\n dimensions = PyTuple_New(arr->nd);\n strides = PyTuple_New(arr->nd);\n for (i=0;ind;++i) {\n PyTuple_SetItem(dimensions,i,PyInt_FromLong(arr->dimensions[i]));\n PyTuple_SetItem(strides,i,PyInt_FromLong(arr->strides[i]));\n }\n return Py_BuildValue(\"siOOO(cciii)ii\",s,arr->nd,\n\t\t dimensions,strides,\n\t\t (arr->base==NULL?Py_None:arr->base),\n\t\t arr->descr->kind,\n\t\t arr->descr->type,\n\t\t arr->descr->type_num,\n\t\t arr->descr->elsize,\n\t\t arr->descr->alignment,\n\t\t arr->flags,\n\t\t arr->itemsize);\n}\n\nstatic PyMethodDef f2py_module_methods[] = {\n\n {\"call\",f2py_rout_wrap_call,METH_VARARGS,doc_f2py_rout_wrap_call},\n {\"array_attrs\",f2py_rout_wrap_attrs,METH_VARARGS,doc_f2py_rout_wrap_attrs},\n {NULL,NULL}\n};\n\nDL_EXPORT(void) initwrap(void) {\n PyObject *m,*d, *s;\n m = wrap_module = Py_InitModule(\"wrap\", f2py_module_methods);\n PyFortran_Type.ob_type = &PyType_Type;\n import_array();\n if (PyErr_Occurred())\n Py_FatalError(\"can't initialize module wrap (failed to import scipy.base)\");\n d = PyModule_GetDict(m);\n s = PyString_FromString(\"This module 'wrap' is auto-generated with f2py (version:2_1330).\\nFunctions:\\n\"\n\" arr = call(type_num,dims,intent,obj)\\n\"\n\".\");\n PyDict_SetItemString(d, \"__doc__\", s);\n wrap_error = PyErr_NewException (\"wrap.error\", NULL, NULL);\n Py_DECREF(s);\n PyDict_SetItemString(d, \"F2PY_INTENT_IN\", PyInt_FromLong(F2PY_INTENT_IN));\n PyDict_SetItemString(d, \"F2PY_INTENT_INOUT\", PyInt_FromLong(F2PY_INTENT_INOUT));\n PyDict_SetItemString(d, \"F2PY_INTENT_OUT\", PyInt_FromLong(F2PY_INTENT_OUT));\n PyDict_SetItemString(d, \"F2PY_INTENT_HIDE\", PyInt_FromLong(F2PY_INTENT_HIDE));\n PyDict_SetItemString(d, \"F2PY_INTENT_CACHE\", PyInt_FromLong(F2PY_INTENT_CACHE));\n PyDict_SetItemString(d, \"F2PY_INTENT_COPY\", PyInt_FromLong(F2PY_INTENT_COPY));\n PyDict_SetItemString(d, \"F2PY_INTENT_C\", PyInt_FromLong(F2PY_INTENT_C));\n PyDict_SetItemString(d, \"F2PY_OPTIONAL\", PyInt_FromLong(F2PY_OPTIONAL));\n PyDict_SetItemString(d, \"F2PY_INTENT_INPLACE\", PyInt_FromLong(F2PY_INTENT_INPLACE));\n PyDict_SetItemString(d, \"PyArray_BOOL\", PyInt_FromLong(PyArray_BOOL));\n PyDict_SetItemString(d, \"PyArray_BYTE\", PyInt_FromLong(PyArray_BYTE));\n PyDict_SetItemString(d, \"PyArray_UBYTE\", PyInt_FromLong(PyArray_UBYTE));\n PyDict_SetItemString(d, \"PyArray_SHORT\", PyInt_FromLong(PyArray_SHORT));\n PyDict_SetItemString(d, \"PyArray_USHORT\", PyInt_FromLong(PyArray_USHORT));\n PyDict_SetItemString(d, \"PyArray_INT\", PyInt_FromLong(PyArray_INT));\n PyDict_SetItemString(d, \"PyArray_UINT\", PyInt_FromLong(PyArray_UINT));\n PyDict_SetItemString(d, \"PyArray_INTP\", PyInt_FromLong(PyArray_INTP));\n PyDict_SetItemString(d, \"PyArray_UINTP\", PyInt_FromLong(PyArray_UINTP));\n PyDict_SetItemString(d, \"PyArray_LONG\", PyInt_FromLong(PyArray_LONG));\n PyDict_SetItemString(d, \"PyArray_ULONG\", PyInt_FromLong(PyArray_ULONG));\n PyDict_SetItemString(d, \"PyArray_LONGLONG\", PyInt_FromLong(PyArray_LONGLONG));\n PyDict_SetItemString(d, \"PyArray_ULONGLONG\", PyInt_FromLong(PyArray_ULONGLONG));\n PyDict_SetItemString(d, \"PyArray_FLOAT\", PyInt_FromLong(PyArray_FLOAT));\n PyDict_SetItemString(d, \"PyArray_DOUBLE\", PyInt_FromLong(PyArray_DOUBLE));\n PyDict_SetItemString(d, \"PyArray_LONGDOUBLE\", PyInt_FromLong(PyArray_LONGDOUBLE));\n PyDict_SetItemString(d, \"PyArray_CFLOAT\", PyInt_FromLong(PyArray_CFLOAT));\n PyDict_SetItemString(d, \"PyArray_CDOUBLE\", PyInt_FromLong(PyArray_CDOUBLE));\n PyDict_SetItemString(d, \"PyArray_CLONGDOUBLE\", PyInt_FromLong(PyArray_CLONGDOUBLE));\n PyDict_SetItemString(d, \"PyArray_OBJECT\", PyInt_FromLong(PyArray_OBJECT));\n PyDict_SetItemString(d, \"PyArray_STRING\", PyInt_FromLong(PyArray_STRING));\n PyDict_SetItemString(d, \"PyArray_UNICODE\", PyInt_FromLong(PyArray_UNICODE));\n PyDict_SetItemString(d, \"PyArray_VOID\", PyInt_FromLong(PyArray_VOID));\n PyDict_SetItemString(d, \"PyArray_NTYPES\", PyInt_FromLong(PyArray_NTYPES));\n PyDict_SetItemString(d, \"PyArray_NOTYPE\", PyInt_FromLong(PyArray_NOTYPE));\n PyDict_SetItemString(d, \"PyArray_UDERDEF\", PyInt_FromLong(PyArray_USERDEF));\n\n PyDict_SetItemString(d, \"CONTIGUOUS\", PyInt_FromLong(CONTIGUOUS));\n PyDict_SetItemString(d, \"FORTRAN\", PyInt_FromLong(FORTRAN));\n PyDict_SetItemString(d, \"OWNDATA\", PyInt_FromLong(OWNDATA));\n PyDict_SetItemString(d, \"ENSURECOPY\", PyInt_FromLong(ENSURECOPY));\n PyDict_SetItemString(d, \"ENSUREARRAY\", PyInt_FromLong(ENSUREARRAY));\n PyDict_SetItemString(d, \"ALIGNED\", PyInt_FromLong(ALIGNED));\n PyDict_SetItemString(d, \"NOTSWAPPED\", PyInt_FromLong(NOTSWAPPED));\n PyDict_SetItemString(d, \"WRITEABLE\", PyInt_FromLong(WRITEABLE));\n PyDict_SetItemString(d, \"UPDATEIFCOPY\", PyInt_FromLong(UPDATEIFCOPY));\n\n PyDict_SetItemString(d, \"BEHAVED_FLAGS\", PyInt_FromLong(BEHAVED_FLAGS));\n PyDict_SetItemString(d, \"BEHAVED_FLAGS_RO\", PyInt_FromLong(BEHAVED_FLAGS_RO));\n PyDict_SetItemString(d, \"CARRAY_FLAGS\", PyInt_FromLong(CARRAY_FLAGS));\n PyDict_SetItemString(d, \"FARRAY_FLAGS\", PyInt_FromLong(FARRAY_FLAGS));\n PyDict_SetItemString(d, \"DEFAULT_FLAGS\", PyInt_FromLong(DEFAULT_FLAGS));\n PyDict_SetItemString(d, \"UPDATE_ALL_FLAGS\", PyInt_FromLong(UPDATE_ALL_FLAGS));\n\n if (PyErr_Occurred())\n Py_FatalError(\"can't initialize module wrap\");\n\n#ifdef F2PY_REPORT_ATEXIT\n on_exit(f2py_report_on_exit,(void*)\"array_from_pyobj.wrap.call\");\n#endif\n\n}\n#ifdef __cplusplus\n}\n#endif\n", "source_code_before": "/* File: wrapmodule.c\n * This file is auto-generated with f2py (version:2_1330).\n * Hand edited by Pearu.\n * f2py is a Fortran to Python Interface Generator (FPIG), Second Edition,\n * written by Pearu Peterson .\n * See http://cens.ioc.ee/projects/f2py2e/\n * Generation date: Fri Oct 21 22:41:12 2005\n * $Revision:$\n * $Date:$\n * Do not edit this file directly unless you know what you are doing!!!\n */\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n/*********************** See f2py2e/cfuncs.py: includes ***********************/\n#include \"Python.h\"\n#include \"fortranobject.h\"\n#include \n\nstatic PyObject *wrap_error;\nstatic PyObject *wrap_module;\n\n/************************************ call ************************************/\nstatic char doc_f2py_rout_wrap_call[] = \"\\\nFunction signature:\\n\\\n arr = call(type_num,dims,intent,obj)\\n\\\nRequired arguments:\\n\"\n\" type_num : input int\\n\"\n\" dims : input int-sequence\\n\"\n\" intent : input int\\n\"\n\" obj : input python object\\n\"\n\"Return objects:\\n\"\n\" arr : array\";\nstatic PyObject *f2py_rout_wrap_call(PyObject *capi_self,\n\t\t\t\t PyObject *capi_args) {\n PyObject * volatile capi_buildvalue = NULL;\n int type_num = 0;\n intp *dims = NULL;\n PyObject *dims_capi = Py_None;\n int rank = 0;\n int intent = 0;\n PyArrayObject *capi_arr_tmp = NULL;\n PyObject *arr_capi = Py_None;\n int i;\n\n if (!PyArg_ParseTuple(capi_args,\"iOiO|:wrap.call\",\\\n\t\t\t&type_num,&dims_capi,&intent,&arr_capi))\n return NULL;\n rank = PySequence_Length(dims_capi);\n dims = malloc(rank*sizeof(intp));\n for (i=0;idata);\n dimensions = PyTuple_New(arr->nd);\n strides = PyTuple_New(arr->nd);\n for (i=0;ind;++i) {\n PyTuple_SetItem(dimensions,i,PyInt_FromLong(arr->dimensions[i]));\n PyTuple_SetItem(strides,i,PyInt_FromLong(arr->strides[i]));\n }\n return Py_BuildValue(\"siOOO(cciii)ii\",s,arr->nd,\n\t\t dimensions,strides,\n\t\t (arr->base==NULL?Py_None:arr->base),\n\t\t arr->descr->kind,\n\t\t arr->descr->type,\n\t\t arr->descr->type_num,\n\t\t arr->descr->elsize,\n\t\t arr->descr->alignment,\n\t\t arr->flags,\n\t\t arr->itemsize);\n}\n\nstatic PyMethodDef f2py_module_methods[] = {\n\n {\"call\",f2py_rout_wrap_call,METH_VARARGS,doc_f2py_rout_wrap_call},\n {\"array_attrs\",f2py_rout_wrap_attrs,METH_VARARGS,doc_f2py_rout_wrap_attrs},\n {NULL,NULL}\n};\n\nDL_EXPORT(void) initwrap(void) {\n PyObject *m,*d, *s;\n m = wrap_module = Py_InitModule(\"wrap\", f2py_module_methods);\n PyFortran_Type.ob_type = &PyType_Type;\n import_array();\n if (PyErr_Occurred())\n Py_FatalError(\"can't initialize module wrap (failed to import scipy.base)\");\n d = PyModule_GetDict(m);\n s = PyString_FromString(\"This module 'wrap' is auto-generated with f2py (version:2_1330).\\nFunctions:\\n\"\n\" arr = call(type_num,dims,intent,obj)\\n\"\n\".\");\n PyDict_SetItemString(d, \"__doc__\", s);\n wrap_error = PyErr_NewException (\"wrap.error\", NULL, NULL);\n Py_DECREF(s);\n PyDict_SetItemString(d, \"F2PY_INTENT_IN\", PyInt_FromLong(F2PY_INTENT_IN));\n PyDict_SetItemString(d, \"F2PY_INTENT_INOUT\", PyInt_FromLong(F2PY_INTENT_INOUT));\n PyDict_SetItemString(d, \"F2PY_INTENT_OUT\", PyInt_FromLong(F2PY_INTENT_OUT));\n PyDict_SetItemString(d, \"F2PY_INTENT_HIDE\", PyInt_FromLong(F2PY_INTENT_HIDE));\n PyDict_SetItemString(d, \"F2PY_INTENT_CACHE\", PyInt_FromLong(F2PY_INTENT_CACHE));\n PyDict_SetItemString(d, \"F2PY_INTENT_COPY\", PyInt_FromLong(F2PY_INTENT_COPY));\n PyDict_SetItemString(d, \"F2PY_INTENT_C\", PyInt_FromLong(F2PY_INTENT_C));\n PyDict_SetItemString(d, \"F2PY_OPTIONAL\", PyInt_FromLong(F2PY_OPTIONAL));\n PyDict_SetItemString(d, \"F2PY_INTENT_INPLACE\", PyInt_FromLong(F2PY_INTENT_INPLACE));\n PyDict_SetItemString(d, \"PyArray_BOOL\", PyInt_FromLong(PyArray_BOOL));\n PyDict_SetItemString(d, \"PyArray_BYTE\", PyInt_FromLong(PyArray_BYTE));\n PyDict_SetItemString(d, \"PyArray_UBYTE\", PyInt_FromLong(PyArray_UBYTE));\n PyDict_SetItemString(d, \"PyArray_SHORT\", PyInt_FromLong(PyArray_SHORT));\n PyDict_SetItemString(d, \"PyArray_USHORT\", PyInt_FromLong(PyArray_USHORT));\n PyDict_SetItemString(d, \"PyArray_INT\", PyInt_FromLong(PyArray_INT));\n PyDict_SetItemString(d, \"PyArray_UINT\", PyInt_FromLong(PyArray_UINT));\n PyDict_SetItemString(d, \"PyArray_INTP\", PyInt_FromLong(PyArray_INTP));\n PyDict_SetItemString(d, \"PyArray_UINTP\", PyInt_FromLong(PyArray_UINTP));\n PyDict_SetItemString(d, \"PyArray_LONG\", PyInt_FromLong(PyArray_LONG));\n PyDict_SetItemString(d, \"PyArray_ULONG\", PyInt_FromLong(PyArray_ULONG));\n PyDict_SetItemString(d, \"PyArray_LONGLONG\", PyInt_FromLong(PyArray_LONGLONG));\n PyDict_SetItemString(d, \"PyArray_ULONGLONG\", PyInt_FromLong(PyArray_ULONGLONG));\n PyDict_SetItemString(d, \"PyArray_FLOAT\", PyInt_FromLong(PyArray_FLOAT));\n PyDict_SetItemString(d, \"PyArray_DOUBLE\", PyInt_FromLong(PyArray_DOUBLE));\n PyDict_SetItemString(d, \"PyArray_LONGDOUBLE\", PyInt_FromLong(PyArray_LONGDOUBLE));\n PyDict_SetItemString(d, \"PyArray_CFLOAT\", PyInt_FromLong(PyArray_CFLOAT));\n PyDict_SetItemString(d, \"PyArray_CDOUBLE\", PyInt_FromLong(PyArray_CDOUBLE));\n PyDict_SetItemString(d, \"PyArray_CLONGDOUBLE\", PyInt_FromLong(PyArray_CLONGDOUBLE));\n PyDict_SetItemString(d, \"PyArray_OBJECT\", PyInt_FromLong(PyArray_OBJECT));\n PyDict_SetItemString(d, \"PyArray_STRING\", PyInt_FromLong(PyArray_STRING));\n PyDict_SetItemString(d, \"PyArray_UNICODE\", PyInt_FromLong(PyArray_UNICODE));\n PyDict_SetItemString(d, \"PyArray_VOID\", PyInt_FromLong(PyArray_VOID));\n PyDict_SetItemString(d, \"PyArray_NTYPES\", PyInt_FromLong(PyArray_NTYPES));\n PyDict_SetItemString(d, \"PyArray_NOTYPE\", PyInt_FromLong(PyArray_NOTYPE));\n PyDict_SetItemString(d, \"PyArray_UDERDEF\", PyInt_FromLong(PyArray_USERDEF));\n\n PyDict_SetItemString(d, \"CONTIGUOUS\", PyInt_FromLong(CONTIGUOUS));\n PyDict_SetItemString(d, \"FORTRAN\", PyInt_FromLong(FORTRAN));\n PyDict_SetItemString(d, \"OWNDATA\", PyInt_FromLong(OWNDATA));\n PyDict_SetItemString(d, \"ENSURECOPY\", PyInt_FromLong(ENSURECOPY));\n PyDict_SetItemString(d, \"ENSUREARRAY\", PyInt_FromLong(ENSUREARRAY));\n PyDict_SetItemString(d, \"ALIGNED\", PyInt_FromLong(ALIGNED));\n PyDict_SetItemString(d, \"NOTSWAPPED\", PyInt_FromLong(NOTSWAPPED));\n PyDict_SetItemString(d, \"WRITEABLE\", PyInt_FromLong(WRITEABLE));\n PyDict_SetItemString(d, \"UPDATEIFCOPY\", PyInt_FromLong(UPDATEIFCOPY));\n\n PyDict_SetItemString(d, \"BEHAVED_FLAGS\", PyInt_FromLong(BEHAVED_FLAGS));\n PyDict_SetItemString(d, \"BEHAVED_FLAGS_RO\", PyInt_FromLong(BEHAVED_FLAGS_RO));\n PyDict_SetItemString(d, \"CARRAY_FLAGS\", PyInt_FromLong(CARRAY_FLAGS));\n PyDict_SetItemString(d, \"FARRAY_FLAGS\", PyInt_FromLong(FARRAY_FLAGS));\n PyDict_SetItemString(d, \"DEFAULT_FLAGS\", PyInt_FromLong(DEFAULT_FLAGS));\n PyDict_SetItemString(d, \"UPDATE_ALL_FLAGS\", PyInt_FromLong(UPDATE_ALL_FLAGS));\n\n if (PyErr_Occurred())\n Py_FatalError(\"can't initialize module wrap\");\n\n}\n#ifdef __cplusplus\n}\n#endif\n", "methods": [ { "name": "f2py_rout_wrap_call", "long_name": "f2py_rout_wrap_call( PyObject * capi_self , PyObject * capi_args)", "filename": "wrapmodule.c", "nloc": 25, "complexity": 4, "token_count": 180, "parameters": [ "capi_self", "capi_args" ], "start_line": 35, "end_line": 61, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 1 }, { "name": "f2py_rout_wrap_attrs", "long_name": "f2py_rout_wrap_attrs( PyObject * capi_self , PyObject * capi_args)", "filename": "wrapmodule.c", "nloc": 31, "complexity": 4, "token_count": 234, "parameters": [ "capi_self", "capi_args" ], "start_line": 78, "end_line": 108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 1 }, { "name": "initwrap", "long_name": "initwrap()", "filename": "wrapmodule.c", "nloc": 68, "complexity": 4, "token_count": 711, "parameters": [], "start_line": 117, "end_line": 191, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 1 } ], "methods_before": [ { "name": "f2py_rout_wrap_call", "long_name": "f2py_rout_wrap_call( PyObject * capi_self , PyObject * capi_args)", "filename": "wrapmodule.c", "nloc": 25, "complexity": 4, "token_count": 180, "parameters": [ "capi_self", "capi_args" ], "start_line": 35, "end_line": 61, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 1 }, { "name": "f2py_rout_wrap_attrs", "long_name": "f2py_rout_wrap_attrs( PyObject * capi_self , PyObject * capi_args)", "filename": "wrapmodule.c", "nloc": 31, "complexity": 4, "token_count": 234, "parameters": [ "capi_self", "capi_args" ], "start_line": 78, "end_line": 108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 1 }, { "name": "initwrap", "long_name": "initwrap()", "filename": "wrapmodule.c", "nloc": 67, "complexity": 3, "token_count": 700, "parameters": [], "start_line": 117, "end_line": 187, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 71, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "initwrap", "long_name": "initwrap()", "filename": "wrapmodule.c", "nloc": 68, "complexity": 4, "token_count": 711, "parameters": [], "start_line": 117, "end_line": 191, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 1 } ], "nloc": 161, "complexity": 12, "token_count": 1222, "diff_parsed": { "added": [ "#ifdef F2PY_REPORT_ATEXIT", " on_exit(f2py_report_on_exit,(void*)\"array_from_pyobj.wrap.call\");", "#endif", "" ], "deleted": [] } } ] }, { "hash": "7e2da241b304173af7f87fb6a2c709912730448d", "msg": "Setting __scipy_version__.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2005-10-26T14:06:01+00:00", "author_timezone": 0, "committer_date": "2005-10-26T14:06:01+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "1523841beea21af826131945038ea89e686815b9" ], "project_name": "repo_copy", "project_path": "/tmp/tmpn4cqam_6/repo_copy", "deletions": 0, "insertions": 1, "lines": 1, "files": 1, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "scipy/__init__.py", "new_path": "scipy/__init__.py", "filename": "__init__.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -60,5 +60,6 @@\n \n if show_scipy_config is not None:\n __doc__ += __scipy_doc__\n+ from scipy_version import scipy_version as __scipy_version__\n from _import_tools import import_packages\n import_packages()\n", "added_lines": 1, "deleted_lines": 0, "source_code": "\"\"\"\\\nSciPy Core\n==========\n\nYou can support the development of SciPy by purchasing documentation\nat\n\n http://www.trelgol.com\n\nIt is being distributed for a fee for a limited time to try and raise\nmoney for development.\n\nDocumentation is also available in the docstrings.\n\nAvailable subpackages\n---------------------\n\"\"\"\n\nimport os\nNO_SCIPY_IMPORT = os.environ.get('NO_SCIPY_IMPORT',None)\n\ntry:\n from __core_config__ import show as show_core_config\nexcept ImportError:\n show_core_config = None\n\nif show_core_config is None:\n print 'Running from scipy core source directory.'\nelse:\n from scipy.base import *\n import scipy.basic as basic\n from scipy.basic.fft import fft, ifft\n from scipy.basic.random import rand, randn\n import scipy.basic.fft as fftpack\n import scipy.basic.linalg as linalg\n import scipy.basic.random as random\n from core_version import version as __core_version__\n from scipy.test.testing import ScipyTest\n test = ScipyTest('scipy').test\n\n__scipy_doc__ = \"\"\"\\\nSciPy: A scientific computing package for Python\n================================================\n\nAvailable subpackages\n---------------------\n\"\"\"\n\nif NO_SCIPY_IMPORT is not None:\n print 'Skip importing scipy packages (NO_SCIPY_IMPORT=%s)' % (NO_SCIPY_IMPORT)\n show_scipy_config = None\nelif show_core_config is None:\n show_scipy_config = None\nelse:\n try:\n from __scipy_config__ import show as show_scipy_config\n except ImportError:\n show_scipy_config = None\n\n\nif show_scipy_config is not None:\n __doc__ += __scipy_doc__\n from scipy_version import scipy_version as __scipy_version__\n from _import_tools import import_packages\n import_packages()\n", "source_code_before": "\"\"\"\\\nSciPy Core\n==========\n\nYou can support the development of SciPy by purchasing documentation\nat\n\n http://www.trelgol.com\n\nIt is being distributed for a fee for a limited time to try and raise\nmoney for development.\n\nDocumentation is also available in the docstrings.\n\nAvailable subpackages\n---------------------\n\"\"\"\n\nimport os\nNO_SCIPY_IMPORT = os.environ.get('NO_SCIPY_IMPORT',None)\n\ntry:\n from __core_config__ import show as show_core_config\nexcept ImportError:\n show_core_config = None\n\nif show_core_config is None:\n print 'Running from scipy core source directory.'\nelse:\n from scipy.base import *\n import scipy.basic as basic\n from scipy.basic.fft import fft, ifft\n from scipy.basic.random import rand, randn\n import scipy.basic.fft as fftpack\n import scipy.basic.linalg as linalg\n import scipy.basic.random as random\n from core_version import version as __core_version__\n from scipy.test.testing import ScipyTest\n test = ScipyTest('scipy').test\n\n__scipy_doc__ = \"\"\"\\\nSciPy: A scientific computing package for Python\n================================================\n\nAvailable subpackages\n---------------------\n\"\"\"\n\nif NO_SCIPY_IMPORT is not None:\n print 'Skip importing scipy packages (NO_SCIPY_IMPORT=%s)' % (NO_SCIPY_IMPORT)\n show_scipy_config = None\nelif show_core_config is None:\n show_scipy_config = None\nelse:\n try:\n from __scipy_config__ import show as show_scipy_config\n except ImportError:\n show_scipy_config = None\n\n\nif show_scipy_config is not None:\n __doc__ += __scipy_doc__\n from _import_tools import import_packages\n import_packages()\n", "methods": [], "methods_before": [], "changed_methods": [], "nloc": 58, "complexity": 0, "token_count": 180, "diff_parsed": { "added": [ " from scipy_version import scipy_version as __scipy_version__" ], "deleted": [] } } ] }, { "hash": "4fd834508fd08514f9fd9b326b7363d96a480dd7", "msg": "Fixed intent(in,out) array shape when copy is made.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2005-10-26T18:32:39+00:00", "author_timezone": 0, "committer_date": "2005-10-26T18:32:39+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "7e2da241b304173af7f87fb6a2c709912730448d" ], "project_name": "repo_copy", "project_path": "/tmp/tmpn4cqam_6/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": "scipy/f2py2e/src/fortranobject.c", "new_path": "scipy/f2py2e/src/fortranobject.c", "filename": "fortranobject.c", "extension": "c", "change_type": "MODIFY", "diff": "@@ -583,7 +583,7 @@ PyArrayObject* array_from_pyobj(const int type_num,\n \n {\n PyArrayObject *retarr = (PyArrayObject *) \\\n-\tPyArray_New(&PyArray_Type, rank, dims, type_num,\n+\tPyArray_New(&PyArray_Type, arr->nd, arr->dimensions, type_num,\n \t\t NULL,NULL,0,\n \t\t !(intent&F2PY_INTENT_C),\n \t\t NULL);\n", "added_lines": 1, "deleted_lines": 1, "source_code": "#define FORTRANOBJECT_C\n#include \"fortranobject.h\"\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n/*\n This file implements: FortranObject, array_from_pyobj, copy_ND_array\n\n Author: Pearu Peterson \n $Revision: 1.52 $\n $Date: 2005/07/11 07:44:20 $\n*/\n\n/************************* FortranObject *******************************/\n\ntypedef PyObject *(*fortranfunc)(PyObject *,PyObject *,PyObject *,void *);\n\nPyObject *\nPyFortranObject_New(FortranDataDef* defs, f2py_void_func init) {\n int i;\n PyFortranObject *fp = NULL;\n PyObject *v = NULL;\n if (init!=NULL) /* Initialize F90 module objects */\n (*(init))();\n if ((fp = PyObject_New(PyFortranObject, &PyFortran_Type))==NULL) return NULL;\n if ((fp->dict = PyDict_New())==NULL) return NULL;\n fp->len = 0;\n while (defs[fp->len].name != NULL) fp->len++;\n if (fp->len == 0) goto fail;\n fp->defs = defs;\n for (i=0;ilen;i++)\n if (fp->defs[i].rank == -1) { /* Is Fortran routine */\n v = PyFortranObject_NewAsAttr(&(fp->defs[i]));\n if (v==NULL) return NULL;\n PyDict_SetItemString(fp->dict,fp->defs[i].name,v);\n } else\n if ((fp->defs[i].data)!=NULL) { /* Is Fortran variable or array (not allocatable) */\n\tv = PyArray_New(&PyArray_Type, fp->defs[i].rank, fp->defs[i].dims.d,\n\t\t\tfp->defs[i].type, NULL, fp->defs[i].data, 0, FARRAY_FLAGS,\n\t\t\tNULL);\n\tif (v==NULL) return NULL;\n\tPyDict_SetItemString(fp->dict,fp->defs[i].name,v);\n }\n Py_XDECREF(v);\n return (PyObject *)fp;\n fail:\n Py_XDECREF(v);\n return NULL;\n}\n\nPyObject *\nPyFortranObject_NewAsAttr(FortranDataDef* defs) { /* used for calling F90 module routines */\n PyFortranObject *fp = NULL;\n fp = PyObject_New(PyFortranObject, &PyFortran_Type);\n if (fp == NULL) return NULL;\n if ((fp->dict = PyDict_New())==NULL) return NULL;\n fp->len = 1;\n fp->defs = defs;\n return (PyObject *)fp;\n}\n\n/* Fortran methods */\n\nstatic void\nfortran_dealloc(PyFortranObject *fp) {\n Py_XDECREF(fp->dict);\n PyMem_Del(fp);\n}\n\n\nstatic PyMethodDef fortran_methods[] = {\n\t{NULL,\t\tNULL}\t\t/* sentinel */\n};\n\n\nstatic PyObject *\nfortran_doc (FortranDataDef def) {\n char *p;\n PyObject *s = NULL;\n int i;\n unsigned size=100;\n if (def.doc!=NULL)\n size += strlen(def.doc);\n p = (char*)malloc (size);\n if (sprintf(p,\"%s - \",def.name)==0) goto fail;\n if (def.rank==-1) {\n if (def.doc==NULL) {\n if (sprintf(p,\"%sno docs available\",p)==0)\n\tgoto fail;\n } else {\n if (sprintf(p,\"%s%s\",p,def.doc)==0)\n\tgoto fail;\n }\n } else {\n PyArray_Descr *d = PyArray_DescrFromType(def.type);\n if (sprintf(p,\"%s'%c'-\",p,d->type)==0) goto fail;\n if (def.data==NULL) {\n if (sprintf(p,\"%sarray(%\" INTP_FMT,p,def.dims.d[0])==0) goto fail;\n for(i=1;i0) {\n\tif (sprintf(p,\"%sarray(%\"INTP_FMT,p,def.dims.d[0])==0) goto fail;\n\tfor(i=1;isize) {\n fprintf(stderr,\"fortranobject.c:fortran_doc:len(p)=%zd>%d(size): too long doc string required, increase size\\n\",strlen(p),size);\n goto fail;\n }\n s = PyString_FromString(p);\n fail:\n free(p);\n return s;\n}\n\nstatic FortranDataDef *save_def; /* save pointer of an allocatable array */\nstatic void set_data(char *d,intp *f) { /* callback from Fortran */\n if (*f) /* In fortran f=allocated(d) */\n save_def->data = d;\n else\n save_def->data = NULL;\n /* printf(\"set_data: d=%p,f=%d\\n\",d,*f); */\n}\n\nstatic PyObject *\nfortran_getattr(PyFortranObject *fp, char *name) {\n int i,j,k,flag;\n if (fp->dict != NULL) {\n PyObject *v = PyDict_GetItemString(fp->dict, name);\n if (v != NULL) {\n Py_INCREF(v);\n return v;\n }\n }\n for (i=0,j=1;ilen && (j=strcmp(name,fp->defs[i].name));i++);\n if (j==0)\n if (fp->defs[i].rank!=-1) { /* F90 allocatable array */ \n if (fp->defs[i].func==NULL) return NULL;\n for(k=0;kdefs[i].rank;++k) \n\tfp->defs[i].dims.d[k]=-1;\n save_def = &fp->defs[i];\n (*(fp->defs[i].func))(&fp->defs[i].rank,fp->defs[i].dims.d,set_data,&flag);\n if (flag==2)\n\tk = fp->defs[i].rank + 1;\n else\n\tk = fp->defs[i].rank;\n if (fp->defs[i].data !=NULL) { /* array is allocated */\n\tPyObject *v = PyArray_New(&PyArray_Type, k, fp->defs[i].dims.d,\n\t\t\tfp->defs[i].type, NULL, fp->defs[i].data, 0, FARRAY_FLAGS,\n\t\t\tNULL);\n\tif (v==NULL) return NULL;\n\t/* Py_INCREF(v); */\n\treturn v;\n } else { /* array is not allocated */\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n }\n }\n if (strcmp(name,\"__dict__\")==0) {\n Py_INCREF(fp->dict);\n return fp->dict;\n }\n if (strcmp(name,\"__doc__\")==0) {\n PyObject *s = PyString_FromString(\"\");\n for (i=0;ilen;i++)\n PyString_ConcatAndDel(&s,fortran_doc(fp->defs[i]));\n if (PyDict_SetItemString(fp->dict, name, s))\n return NULL;\n return s;\n }\n if ((strcmp(name,\"_cpointer\")==0) && (fp->len==1)) {\n PyObject *cobj = PyCObject_FromVoidPtr((void *)(fp->defs[0].data),NULL);\n if (PyDict_SetItemString(fp->dict, name, cobj))\n return NULL;\n return cobj;\n }\n return Py_FindMethod(fortran_methods, (PyObject *)fp, name);\n}\n\nstatic int\nfortran_setattr(PyFortranObject *fp, char *name, PyObject *v) {\n int i,j,flag;\n PyArrayObject *arr = NULL;\n for (i=0,j=1;ilen && (j=strcmp(name,fp->defs[i].name));i++);\n if (j==0) {\n if (fp->defs[i].rank==-1) {\n PyErr_SetString(PyExc_AttributeError,\"over-writing fortran routine\");\n return -1;\n }\n if (fp->defs[i].func!=NULL) { /* is allocatable array */\n intp dims[F2PY_MAX_DIMS];\n int k;\n save_def = &fp->defs[i];\n if (v!=Py_None) { /* set new value (reallocate if needed --\n\t\t\t see f2py generated code for more\n\t\t\t details ) */\n\tfor(k=0;kdefs[i].rank;k++) dims[k]=-1;\n\tif ((arr = array_from_pyobj(fp->defs[i].type,dims,fp->defs[i].rank,F2PY_INTENT_IN,v))==NULL)\n\t return -1;\n\t(*(fp->defs[i].func))(&fp->defs[i].rank,arr->dimensions,set_data,&flag);\n } else { /* deallocate */\n\tfor(k=0;kdefs[i].rank;k++) dims[k]=0;\n\t(*(fp->defs[i].func))(&fp->defs[i].rank,dims,set_data,&flag);\n\tfor(k=0;kdefs[i].rank;k++) dims[k]=-1;\n }\n memcpy(fp->defs[i].dims.d,dims,fp->defs[i].rank*sizeof(intp));\n } else { /* not allocatable array */\n if ((arr = array_from_pyobj(fp->defs[i].type,fp->defs[i].dims.d,fp->defs[i].rank,F2PY_INTENT_IN,v))==NULL)\n\treturn -1; \n }\n if (fp->defs[i].data!=NULL) { /* copy Python object to Fortran array */\n intp s = PyArray_MultiplyList(fp->defs[i].dims.d,arr->nd);\n if (s==-1)\n\ts = PyArray_MultiplyList(arr->dimensions,arr->nd);\n if (s<0 ||\n\t (memcpy(fp->defs[i].data,arr->data,s*PyArray_ITEMSIZE(arr)))==NULL) {\n\tif ((PyObject*)arr!=v) {\n\t Py_DECREF(arr);\n\t}\n\treturn -1;\n }\n if ((PyObject*)arr!=v) {\n Py_DECREF(arr);\n }\n } else return (fp->defs[i].func==NULL?-1:0);\n return 0; /* succesful */\n }\n if (fp->dict == NULL) {\n fp->dict = PyDict_New();\n if (fp->dict == NULL)\n return -1;\n }\n if (v == NULL) {\n int rv = PyDict_DelItemString(fp->dict, name);\n if (rv < 0)\n PyErr_SetString(PyExc_AttributeError,\"delete non-existing fortran attribute\");\n return rv;\n }\n else\n return PyDict_SetItemString(fp->dict, name, v);\n}\n\nstatic PyObject*\nfortran_call(PyFortranObject *fp, PyObject *arg, PyObject *kw) {\n int i = 0;\n /* printf(\"fortran call\n name=%s,func=%p,data=%p,%p\\n\",fp->defs[i].name,\n fp->defs[i].func,fp->defs[i].data,&fp->defs[i].data); */\n if (fp->defs[i].rank==-1) {/* is Fortran routine */\n if ((fp->defs[i].func==NULL)) {\n PyErr_Format(PyExc_RuntimeError, \"no function to call\");\n return NULL;\n }\n else if (fp->defs[i].data==NULL)\n /* dummy routine */\n return (*((fortranfunc)(fp->defs[i].func)))((PyObject *)fp,arg,kw,NULL);\n else\n return (*((fortranfunc)(fp->defs[i].func)))((PyObject *)fp,arg,kw,\n\t\t\t\t\t\t (void *)fp->defs[i].data);\n }\n PyErr_Format(PyExc_TypeError, \"this fortran object is not callable\");\n return NULL;\n}\n\n\nPyTypeObject PyFortran_Type = {\n PyObject_HEAD_INIT(0)\n 0,\t\t\t/*ob_size*/\n \"fortran\",\t\t\t/*tp_name*/\n sizeof(PyFortranObject),\t/*tp_basicsize*/\n 0,\t\t\t/*tp_itemsize*/\n /* methods */\n (destructor)fortran_dealloc, /*tp_dealloc*/\n 0,\t\t\t/*tp_print*/\n (getattrfunc)fortran_getattr, /*tp_getattr*/\n (setattrfunc)fortran_setattr, /*tp_setattr*/\n 0,\t\t\t/*tp_compare*/\n 0,\t\t\t/*tp_repr*/\n 0,\t\t\t/*tp_as_number*/\n 0,\t\t\t/*tp_as_sequence*/\n 0,\t\t\t/*tp_as_mapping*/\n 0,\t\t\t/*tp_hash*/\n (ternaryfunc)fortran_call, /*tp_call*/\n};\n\n/************************* f2py_report_atexit *******************************/\n\n#ifdef F2PY_REPORT_ATEXIT\nstatic int passed_time = 0;\nstatic int passed_counter = 0;\nstatic int passed_call_time = 0;\nstatic struct timeb start_time;\nstatic struct timeb stop_time;\nstatic struct timeb start_call_time;\nstatic struct timeb stop_call_time;\nstatic int cb_passed_time = 0;\nstatic int cb_passed_counter = 0;\nstatic int cb_passed_call_time = 0;\nstatic struct timeb cb_start_time;\nstatic struct timeb cb_stop_time;\nstatic struct timeb cb_start_call_time;\nstatic struct timeb cb_stop_call_time;\n\nextern void f2py_start_clock(void) { ftime(&start_time); }\nextern\nvoid f2py_start_call_clock(void) {\n f2py_stop_clock();\n ftime(&start_call_time);\n}\nextern\nvoid f2py_stop_clock(void) {\n ftime(&stop_time);\n passed_time += 1000*(stop_time.time - start_time.time);\n passed_time += stop_time.millitm - start_time.millitm;\n}\nextern\nvoid f2py_stop_call_clock(void) {\n ftime(&stop_call_time);\n passed_call_time += 1000*(stop_call_time.time - start_call_time.time);\n passed_call_time += stop_call_time.millitm - start_call_time.millitm;\n passed_counter += 1;\n f2py_start_clock();\n}\n\nextern void f2py_cb_start_clock(void) { ftime(&cb_start_time); }\nextern\nvoid f2py_cb_start_call_clock(void) {\n f2py_cb_stop_clock();\n ftime(&cb_start_call_time);\n}\nextern\nvoid f2py_cb_stop_clock(void) {\n ftime(&cb_stop_time);\n cb_passed_time += 1000*(cb_stop_time.time - cb_start_time.time);\n cb_passed_time += cb_stop_time.millitm - cb_start_time.millitm;\n}\nextern\nvoid f2py_cb_stop_call_clock(void) {\n ftime(&cb_stop_call_time);\n cb_passed_call_time += 1000*(cb_stop_call_time.time - cb_start_call_time.time);\n cb_passed_call_time += cb_stop_call_time.millitm - cb_start_call_time.millitm;\n cb_passed_counter += 1;\n f2py_cb_start_clock();\n}\n\nstatic int f2py_report_on_exit_been_here = 0;\nextern\nvoid f2py_report_on_exit(int exit_flag,void *name) {\n if (f2py_report_on_exit_been_here) {\n fprintf(stderr,\" %s\\n\",(char*)name);\n return;\n }\n f2py_report_on_exit_been_here = 1;\n fprintf(stderr,\" /-----------------------\\\\\\n\");\n fprintf(stderr,\" < F2PY performance report >\\n\");\n fprintf(stderr,\" \\\\-----------------------/\\n\");\n fprintf(stderr,\"Overall time spent in ...\\n\");\n fprintf(stderr,\"(a) wrapped (Fortran/C) functions : %8d msec\\n\",\n\t passed_call_time);\n fprintf(stderr,\"(b) f2py interface, %6d calls : %8d msec\\n\",\n\t passed_counter,passed_time);\n fprintf(stderr,\"(c) call-back (Python) functions : %8d msec\\n\",\n\t cb_passed_call_time);\n fprintf(stderr,\"(d) f2py call-back interface, %6d calls : %8d msec\\n\",\n\t cb_passed_counter,cb_passed_time);\n \n fprintf(stderr,\"(e) wrapped (Fortran/C) functions (acctual) : %8d msec\\n\\n\",\n\t passed_call_time-cb_passed_call_time-cb_passed_time);\n fprintf(stderr,\"Use -DF2PY_REPORT_ATEXIT_DISABLE to disable this message.\\n\");\n fprintf(stderr,\"Exit status: %d\\n\",exit_flag);\n fprintf(stderr,\"Modules : %s\\n\",(char*)name);\n}\n#endif\n\n/********************** report on array copy ****************************/\n\n#ifdef F2PY_REPORT_ON_ARRAY_COPY\nstatic void f2py_report_on_array_copy(PyArrayObject* arr) {\n const long arr_size = PyArray_Size((PyObject *)arr);\n if (arr_size>F2PY_REPORT_ON_ARRAY_COPY) {\n fprintf(stderr,\"copied an array: size=%ld, elsize=%d\\n\", \n\t arr_size, PyArray_ITEMSIZE(arr));\n }\n}\nstatic void f2py_report_on_array_copy_fromany(void) {\n fprintf(stderr,\"created an array from object\\n\");\n}\n\n#define F2PY_REPORT_ON_ARRAY_COPY_FROMARR f2py_report_on_array_copy((PyArrayObject *)arr)\n#define F2PY_REPORT_ON_ARRAY_COPY_FROMANY f2py_report_on_array_copy_fromany()\n#else\n#define F2PY_REPORT_ON_ARRAY_COPY_FROMARR\n#define F2PY_REPORT_ON_ARRAY_COPY_FROMANY\n#endif\n\n\n/************************* array_from_obj *******************************/\n\n/* \n * File: array_from_pyobj.c \n *\n * Description:\n * ------------ \n * Provides array_from_pyobj function that returns a contigious array\n * object with the given dimensions and required storage order, either\n * in row-major (C) or column-major (Fortran) order. The function\n * array_from_pyobj is very flexible about its Python object argument\n * that can be any number, list, tuple, or array.\n * \n * array_from_pyobj is used in f2py generated Python extension\n * modules.\n *\n * Author: Pearu Peterson \n * Created: 13-16 January 2002\n * $Id: fortranobject.c,v 1.52 2005/07/11 07:44:20 pearu Exp $\n */\n\nstatic int \ncount_nonpos(const int rank,\n\t const intp *dims) {\n int i=0,r=0;\n while (ind;\n intp size = PyArray_Size((PyObject *)arr);\n int i;\n printf(\"\\trank = %d, flags = %d, size = %\" INTP_FMT \"\\n\",\n\t rank,arr->flags,size);\n printf(\"\\tstrides = [\");\n for(i=0;istrides[i]);\n }\n printf(\"]\\n\\t dimensions = [\");\n for(i=0;idimensions[i]);\n }\n printf(\"]\\n\");\n}\n#endif\n\n#define SWAPTYPE(a,b,t) {t c; c = (a); (a) = (b); (b) = c; }\n\nstatic int swap_arrays(PyArrayObject* arr1, PyArrayObject* arr2) {\n SWAPTYPE(arr1->data,arr2->data,char*);\n SWAPTYPE(arr1->nd,arr2->nd,int);\n SWAPTYPE(arr1->dimensions,arr2->dimensions,intp*);\n SWAPTYPE(arr1->strides,arr2->strides,intp*);\n SWAPTYPE(arr1->base,arr2->base,PyObject*);\n SWAPTYPE(arr1->descr,arr2->descr,PyArray_Descr*);\n SWAPTYPE(arr1->flags,arr2->flags,int);\n SWAPTYPE(arr1->itemsize, arr2->itemsize, int);\n /* SWAPTYPE(arr1->weakreflist,arr2->weakreflist,PyObject*); */\n return 0;\n}\n\nextern\nPyArrayObject* array_from_pyobj(const int type_num,\n\t\t\t\tintp *dims,\n\t\t\t\tconst int rank,\n\t\t\t\tconst int intent,\n\t\t\t\tPyObject *obj) {\n /* Note about reference counting\n -----------------------------\n If the caller returns the array to Python, it must be done with\n Py_BuildValue(\"N\",arr).\n Otherwise, if obj!=arr then the caller must call Py_DECREF(arr).\n\n Note on intent(cache,out,..)\n ---------------------\n Don't expect correct data when returning intent(cache) array.\n\n */\n char mess[200];\n PyArrayObject *arr = NULL;\n PyArray_Descr *descr = PyArray_DescrFromType(type_num);\n\n if ((intent & F2PY_INTENT_HIDE)\n || ((intent & F2PY_INTENT_CACHE) && (obj==Py_None))\n || ((intent & F2PY_OPTIONAL) && (obj==Py_None))\n ) {\n /* intent(cache), optional, intent(hide) */\n if (count_nonpos(rank,dims)) {\n int i;\n sprintf(mess,\"failed to create intent(cache|hide)|optional array\"\n\t \"-- must have defined dimensions but got (\");\n for(i=0;i=descr->elsize) {\n\tif (check_and_fix_dimensions((PyArrayObject *)obj,rank,dims))\n\t return NULL; /*XXX: set exception */\n\tif (intent & F2PY_INTENT_OUT)\n\t Py_INCREF(obj);\n\treturn (PyArrayObject *)obj;\n }\n sprintf(mess,\"failed to initialize intent(cache) array\");\n if (!PyArray_ISONESEGMENT(obj))\n\tsprintf(mess+strlen(mess),\" -- input must be in one segment\");\n if (PyArray_ITEMSIZE(arr)elsize)\n\tsprintf(mess+strlen(mess),\" -- expected at least elsize=%d but got %d\",\n\t\tdescr->elsize,PyArray_ITEMSIZE(arr)\n\t\t);\n PyErr_SetString(PyExc_ValueError,mess);\n return NULL;\n }\n\n /* here we have always intent(in) or intent(inout) or intent(inplace) */\n\n if (check_and_fix_dimensions(arr,rank,dims))\n return NULL; /*XXX: set exception */\n\n if ((! (intent & F2PY_INTENT_COPY))\n\t&& PyArray_ITEMSIZE(arr)==descr->elsize\n\t&& PyArray_CanCastSafely(arr->descr->type_num,type_num)\n\t) {\n if ((intent & F2PY_INTENT_C)?PyArray_ISCARRAY(arr):PyArray_ISFARRAY(arr)) {\n\tif ((intent & F2PY_INTENT_OUT)) {\n\t Py_INCREF(arr);\n\t}\n\t/* Returning input array */\n\treturn arr;\n }\n }\n\n if (intent & F2PY_INTENT_INOUT) {\n sprintf(mess,\"failed to initialize intent(inout) array\");\n if ((intent & F2PY_INTENT_C) && !PyArray_ISCARRAY(arr))\n\tsprintf(mess+strlen(mess),\" -- input not contiguous\");\n if (!(intent & F2PY_INTENT_C) && !PyArray_ISFARRAY(arr))\n\tsprintf(mess+strlen(mess),\" -- input not fortran contiguous\");\n if (PyArray_ITEMSIZE(arr)!=descr->elsize)\n\tsprintf(mess+strlen(mess),\" -- expected elsize=%d but got %d\",\n\t\tdescr->elsize,\n\t\tPyArray_ITEMSIZE(arr)\n\t\t);\n if (!(PyArray_CanCastSafely(arr->descr->type_num,type_num)))\n\tsprintf(mess+strlen(mess),\" -- cannot cast safely from '%c' to '%c'\",\n\t\tarr->descr->type,descr->type);\n PyErr_SetString(PyExc_ValueError,mess);\n return NULL;\n }\n\n /* here we have always intent(in) or intent(inplace) */\n\n {\n PyArrayObject *retarr = (PyArrayObject *) \\\n\tPyArray_New(&PyArray_Type, arr->nd, arr->dimensions, type_num,\n\t\t NULL,NULL,0,\n\t\t !(intent&F2PY_INTENT_C),\n\t\t NULL);\n if (retarr==NULL)\n\treturn NULL;\n F2PY_REPORT_ON_ARRAY_COPY_FROMARR;\n if (PyArray_CopyInto(retarr, arr)) {\n\tPy_DECREF(retarr);\n\treturn NULL;\n }\n if (intent & F2PY_INTENT_INPLACE) {\n\tif (swap_arrays(arr,retarr))\n\t return NULL; /* XXX: set exception */\n\tPy_XDECREF(retarr);\n\tif (intent & F2PY_INTENT_OUT)\n\t Py_INCREF(arr);\n } else {\n\tarr = retarr;\n }\n }\n return arr;\n }\n\n if ((intent & F2PY_INTENT_INOUT) \n || (intent & F2PY_INTENT_INPLACE)\n || (intent & F2PY_INTENT_CACHE)) {\n sprintf(mess,\"failed to initialize intent(inout|inplace|cache) array\"\n\t \" -- input must be array but got %s\",\n\t PyString_AsString(PyObject_Str(PyObject_Type(obj)))\n\t );\n PyErr_SetString(PyExc_TypeError,mess);\n return NULL;\n }\n\n {\n PyArray_Typecode typecode = {type_num, 0, 0};\n F2PY_REPORT_ON_ARRAY_COPY_FROMANY;\n arr = (PyArrayObject *) \\\n PyArray_FromAny(obj,&typecode, 0,0,\n\t\t ((intent & F2PY_INTENT_C)?CARRAY_FLAGS:FARRAY_FLAGS));\n if (arr==NULL)\n return NULL;\n if (check_and_fix_dimensions(arr,rank,dims))\n return NULL; /*XXX: set exception */\n return arr;\n }\n\n}\n\n /*****************************************/\n /* Helper functions for array_from_pyobj */\n /*****************************************/\n\nstatic\nint check_and_fix_dimensions(const PyArrayObject* arr,const int rank,intp *dims) {\n /*\n This function fills in blanks (that are -1\\'s) in dims list using\n the dimensions from arr. It also checks that non-blank dims will\n match with the corresponding values in arr dimensions.\n */\n const intp arr_size = (arr->nd)?PyArray_Size((PyObject *)arr):1;\n\n if (rank > arr->nd) { /* [1,2] -> [[1],[2]]; 1 -> [[1]] */\n intp new_size = 1;\n int free_axe = -1;\n int i;\n /* Fill dims where -1 or 0; check dimensions; calc new_size; */\n for(i=0;ind;++i) { \n if (dims[i] >= 0) {\n\tif (dims[i]!=arr->dimensions[i]) {\n\t fprintf(stderr,\"%d-th dimension must be fixed to %\" INTP_FMT\n\t\t \" but got %\" INTP_FMT \"\\n\",\n\t\t i,dims[i], arr->dimensions[i]);\n\t return 1;\n\t}\n\tif (!dims[i]) dims[i] = 1;\n } else {\n\tdims[i] = arr->dimensions[i] ? arr->dimensions[i] : 1;\n }\n new_size *= dims[i];\n }\n for(i=arr->nd;i1) {\n\tfprintf(stderr,\"%d-th dimension must be %\" INTP_FMT\n\t\t\" but got 0 (not defined).\\n\",\n\t\ti,dims[i]);\n\treturn 1;\n } else if (free_axe<0)\n\tfree_axe = i;\n else\n\tdims[i] = 1;\n if (free_axe>=0) {\n dims[free_axe] = arr_size/new_size;\n new_size *= dims[free_axe];\n }\n if (new_size != arr_size) {\n fprintf(stderr,\"confused: new_size=%\" INTP_FMT\n\t \", arr_size=%\" INTP_FMT \" (maybe too many free\"\n\t \" indices)\\n\", new_size,arr_size);\n return 1;\n }\n } else { /* [[1,2]] -> [[1],[2]] */\n int i,j;\n intp d;\n int effrank;\n intp size;\n for (i=0,effrank=0;ind;++i)\n if (arr->dimensions[i]>1) ++effrank;\n if (dims[rank-1]>=0)\n if (effrank>rank) {\n\tfprintf(stderr,\"too many axes: %d (effrank=%d), expected rank=%d\\n\",\n\t\tarr->nd,effrank,rank);\n\treturn 1;\n }\n for (i=0,j=0;ind && arr->dimensions[j]<2) ++j;\n if (j>=arr->nd) d = 1;\n else d = arr->dimensions[j++];\n if (dims[i]>=0) {\n\tif (d>1 && d!=dims[i]) {\n\t fprintf(stderr,\"%d-th dimension must be fixed to %\" INTP_FMT \n\t\t \" but got %\" INTP_FMT \" (real index=%d)\\n\",\n\t\t i,dims[i],d,j-1);\n\t return 1;\t \n\t}\n\tif (!dims[i]) dims[i] = 1;\n } else\n\tdims[i] = d;\n }\n for (i=rank;ind;++i) { /* [[1,2],[3,4]] -> [1,2,3,4] */\n while (jnd && arr->dimensions[j]<2) ++j;\n if (j>=arr->nd) d = 1;\n else d = arr->dimensions[j++];\n dims[rank-1] *= d;\n }\n for (i=0,size=1;ind);\n for (i=0;ind;++i) fprintf(stderr,\" %\" INTP_FMT,arr->dimensions[i]);\n fprintf(stderr,\" ]\\n\");\n return 1;\n }\n }\n return 0;\n}\n\n/* End of file: array_from_pyobj.c */\n\n/************************* copy_ND_array *******************************/\n\nextern\nint copy_ND_array(const PyArrayObject *arr, PyArrayObject *out)\n{\n F2PY_REPORT_ON_ARRAY_COPY_FROMARR;\n return PyArray_CopyInto(out, (PyArrayObject *)arr);\n}\n\n#ifdef __cplusplus\n}\n#endif\n/************************* EOF fortranobject.c *******************************/\n", "source_code_before": "#define FORTRANOBJECT_C\n#include \"fortranobject.h\"\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n/*\n This file implements: FortranObject, array_from_pyobj, copy_ND_array\n\n Author: Pearu Peterson \n $Revision: 1.52 $\n $Date: 2005/07/11 07:44:20 $\n*/\n\n/************************* FortranObject *******************************/\n\ntypedef PyObject *(*fortranfunc)(PyObject *,PyObject *,PyObject *,void *);\n\nPyObject *\nPyFortranObject_New(FortranDataDef* defs, f2py_void_func init) {\n int i;\n PyFortranObject *fp = NULL;\n PyObject *v = NULL;\n if (init!=NULL) /* Initialize F90 module objects */\n (*(init))();\n if ((fp = PyObject_New(PyFortranObject, &PyFortran_Type))==NULL) return NULL;\n if ((fp->dict = PyDict_New())==NULL) return NULL;\n fp->len = 0;\n while (defs[fp->len].name != NULL) fp->len++;\n if (fp->len == 0) goto fail;\n fp->defs = defs;\n for (i=0;ilen;i++)\n if (fp->defs[i].rank == -1) { /* Is Fortran routine */\n v = PyFortranObject_NewAsAttr(&(fp->defs[i]));\n if (v==NULL) return NULL;\n PyDict_SetItemString(fp->dict,fp->defs[i].name,v);\n } else\n if ((fp->defs[i].data)!=NULL) { /* Is Fortran variable or array (not allocatable) */\n\tv = PyArray_New(&PyArray_Type, fp->defs[i].rank, fp->defs[i].dims.d,\n\t\t\tfp->defs[i].type, NULL, fp->defs[i].data, 0, FARRAY_FLAGS,\n\t\t\tNULL);\n\tif (v==NULL) return NULL;\n\tPyDict_SetItemString(fp->dict,fp->defs[i].name,v);\n }\n Py_XDECREF(v);\n return (PyObject *)fp;\n fail:\n Py_XDECREF(v);\n return NULL;\n}\n\nPyObject *\nPyFortranObject_NewAsAttr(FortranDataDef* defs) { /* used for calling F90 module routines */\n PyFortranObject *fp = NULL;\n fp = PyObject_New(PyFortranObject, &PyFortran_Type);\n if (fp == NULL) return NULL;\n if ((fp->dict = PyDict_New())==NULL) return NULL;\n fp->len = 1;\n fp->defs = defs;\n return (PyObject *)fp;\n}\n\n/* Fortran methods */\n\nstatic void\nfortran_dealloc(PyFortranObject *fp) {\n Py_XDECREF(fp->dict);\n PyMem_Del(fp);\n}\n\n\nstatic PyMethodDef fortran_methods[] = {\n\t{NULL,\t\tNULL}\t\t/* sentinel */\n};\n\n\nstatic PyObject *\nfortran_doc (FortranDataDef def) {\n char *p;\n PyObject *s = NULL;\n int i;\n unsigned size=100;\n if (def.doc!=NULL)\n size += strlen(def.doc);\n p = (char*)malloc (size);\n if (sprintf(p,\"%s - \",def.name)==0) goto fail;\n if (def.rank==-1) {\n if (def.doc==NULL) {\n if (sprintf(p,\"%sno docs available\",p)==0)\n\tgoto fail;\n } else {\n if (sprintf(p,\"%s%s\",p,def.doc)==0)\n\tgoto fail;\n }\n } else {\n PyArray_Descr *d = PyArray_DescrFromType(def.type);\n if (sprintf(p,\"%s'%c'-\",p,d->type)==0) goto fail;\n if (def.data==NULL) {\n if (sprintf(p,\"%sarray(%\" INTP_FMT,p,def.dims.d[0])==0) goto fail;\n for(i=1;i0) {\n\tif (sprintf(p,\"%sarray(%\"INTP_FMT,p,def.dims.d[0])==0) goto fail;\n\tfor(i=1;isize) {\n fprintf(stderr,\"fortranobject.c:fortran_doc:len(p)=%zd>%d(size): too long doc string required, increase size\\n\",strlen(p),size);\n goto fail;\n }\n s = PyString_FromString(p);\n fail:\n free(p);\n return s;\n}\n\nstatic FortranDataDef *save_def; /* save pointer of an allocatable array */\nstatic void set_data(char *d,intp *f) { /* callback from Fortran */\n if (*f) /* In fortran f=allocated(d) */\n save_def->data = d;\n else\n save_def->data = NULL;\n /* printf(\"set_data: d=%p,f=%d\\n\",d,*f); */\n}\n\nstatic PyObject *\nfortran_getattr(PyFortranObject *fp, char *name) {\n int i,j,k,flag;\n if (fp->dict != NULL) {\n PyObject *v = PyDict_GetItemString(fp->dict, name);\n if (v != NULL) {\n Py_INCREF(v);\n return v;\n }\n }\n for (i=0,j=1;ilen && (j=strcmp(name,fp->defs[i].name));i++);\n if (j==0)\n if (fp->defs[i].rank!=-1) { /* F90 allocatable array */ \n if (fp->defs[i].func==NULL) return NULL;\n for(k=0;kdefs[i].rank;++k) \n\tfp->defs[i].dims.d[k]=-1;\n save_def = &fp->defs[i];\n (*(fp->defs[i].func))(&fp->defs[i].rank,fp->defs[i].dims.d,set_data,&flag);\n if (flag==2)\n\tk = fp->defs[i].rank + 1;\n else\n\tk = fp->defs[i].rank;\n if (fp->defs[i].data !=NULL) { /* array is allocated */\n\tPyObject *v = PyArray_New(&PyArray_Type, k, fp->defs[i].dims.d,\n\t\t\tfp->defs[i].type, NULL, fp->defs[i].data, 0, FARRAY_FLAGS,\n\t\t\tNULL);\n\tif (v==NULL) return NULL;\n\t/* Py_INCREF(v); */\n\treturn v;\n } else { /* array is not allocated */\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n }\n }\n if (strcmp(name,\"__dict__\")==0) {\n Py_INCREF(fp->dict);\n return fp->dict;\n }\n if (strcmp(name,\"__doc__\")==0) {\n PyObject *s = PyString_FromString(\"\");\n for (i=0;ilen;i++)\n PyString_ConcatAndDel(&s,fortran_doc(fp->defs[i]));\n if (PyDict_SetItemString(fp->dict, name, s))\n return NULL;\n return s;\n }\n if ((strcmp(name,\"_cpointer\")==0) && (fp->len==1)) {\n PyObject *cobj = PyCObject_FromVoidPtr((void *)(fp->defs[0].data),NULL);\n if (PyDict_SetItemString(fp->dict, name, cobj))\n return NULL;\n return cobj;\n }\n return Py_FindMethod(fortran_methods, (PyObject *)fp, name);\n}\n\nstatic int\nfortran_setattr(PyFortranObject *fp, char *name, PyObject *v) {\n int i,j,flag;\n PyArrayObject *arr = NULL;\n for (i=0,j=1;ilen && (j=strcmp(name,fp->defs[i].name));i++);\n if (j==0) {\n if (fp->defs[i].rank==-1) {\n PyErr_SetString(PyExc_AttributeError,\"over-writing fortran routine\");\n return -1;\n }\n if (fp->defs[i].func!=NULL) { /* is allocatable array */\n intp dims[F2PY_MAX_DIMS];\n int k;\n save_def = &fp->defs[i];\n if (v!=Py_None) { /* set new value (reallocate if needed --\n\t\t\t see f2py generated code for more\n\t\t\t details ) */\n\tfor(k=0;kdefs[i].rank;k++) dims[k]=-1;\n\tif ((arr = array_from_pyobj(fp->defs[i].type,dims,fp->defs[i].rank,F2PY_INTENT_IN,v))==NULL)\n\t return -1;\n\t(*(fp->defs[i].func))(&fp->defs[i].rank,arr->dimensions,set_data,&flag);\n } else { /* deallocate */\n\tfor(k=0;kdefs[i].rank;k++) dims[k]=0;\n\t(*(fp->defs[i].func))(&fp->defs[i].rank,dims,set_data,&flag);\n\tfor(k=0;kdefs[i].rank;k++) dims[k]=-1;\n }\n memcpy(fp->defs[i].dims.d,dims,fp->defs[i].rank*sizeof(intp));\n } else { /* not allocatable array */\n if ((arr = array_from_pyobj(fp->defs[i].type,fp->defs[i].dims.d,fp->defs[i].rank,F2PY_INTENT_IN,v))==NULL)\n\treturn -1; \n }\n if (fp->defs[i].data!=NULL) { /* copy Python object to Fortran array */\n intp s = PyArray_MultiplyList(fp->defs[i].dims.d,arr->nd);\n if (s==-1)\n\ts = PyArray_MultiplyList(arr->dimensions,arr->nd);\n if (s<0 ||\n\t (memcpy(fp->defs[i].data,arr->data,s*PyArray_ITEMSIZE(arr)))==NULL) {\n\tif ((PyObject*)arr!=v) {\n\t Py_DECREF(arr);\n\t}\n\treturn -1;\n }\n if ((PyObject*)arr!=v) {\n Py_DECREF(arr);\n }\n } else return (fp->defs[i].func==NULL?-1:0);\n return 0; /* succesful */\n }\n if (fp->dict == NULL) {\n fp->dict = PyDict_New();\n if (fp->dict == NULL)\n return -1;\n }\n if (v == NULL) {\n int rv = PyDict_DelItemString(fp->dict, name);\n if (rv < 0)\n PyErr_SetString(PyExc_AttributeError,\"delete non-existing fortran attribute\");\n return rv;\n }\n else\n return PyDict_SetItemString(fp->dict, name, v);\n}\n\nstatic PyObject*\nfortran_call(PyFortranObject *fp, PyObject *arg, PyObject *kw) {\n int i = 0;\n /* printf(\"fortran call\n name=%s,func=%p,data=%p,%p\\n\",fp->defs[i].name,\n fp->defs[i].func,fp->defs[i].data,&fp->defs[i].data); */\n if (fp->defs[i].rank==-1) {/* is Fortran routine */\n if ((fp->defs[i].func==NULL)) {\n PyErr_Format(PyExc_RuntimeError, \"no function to call\");\n return NULL;\n }\n else if (fp->defs[i].data==NULL)\n /* dummy routine */\n return (*((fortranfunc)(fp->defs[i].func)))((PyObject *)fp,arg,kw,NULL);\n else\n return (*((fortranfunc)(fp->defs[i].func)))((PyObject *)fp,arg,kw,\n\t\t\t\t\t\t (void *)fp->defs[i].data);\n }\n PyErr_Format(PyExc_TypeError, \"this fortran object is not callable\");\n return NULL;\n}\n\n\nPyTypeObject PyFortran_Type = {\n PyObject_HEAD_INIT(0)\n 0,\t\t\t/*ob_size*/\n \"fortran\",\t\t\t/*tp_name*/\n sizeof(PyFortranObject),\t/*tp_basicsize*/\n 0,\t\t\t/*tp_itemsize*/\n /* methods */\n (destructor)fortran_dealloc, /*tp_dealloc*/\n 0,\t\t\t/*tp_print*/\n (getattrfunc)fortran_getattr, /*tp_getattr*/\n (setattrfunc)fortran_setattr, /*tp_setattr*/\n 0,\t\t\t/*tp_compare*/\n 0,\t\t\t/*tp_repr*/\n 0,\t\t\t/*tp_as_number*/\n 0,\t\t\t/*tp_as_sequence*/\n 0,\t\t\t/*tp_as_mapping*/\n 0,\t\t\t/*tp_hash*/\n (ternaryfunc)fortran_call, /*tp_call*/\n};\n\n/************************* f2py_report_atexit *******************************/\n\n#ifdef F2PY_REPORT_ATEXIT\nstatic int passed_time = 0;\nstatic int passed_counter = 0;\nstatic int passed_call_time = 0;\nstatic struct timeb start_time;\nstatic struct timeb stop_time;\nstatic struct timeb start_call_time;\nstatic struct timeb stop_call_time;\nstatic int cb_passed_time = 0;\nstatic int cb_passed_counter = 0;\nstatic int cb_passed_call_time = 0;\nstatic struct timeb cb_start_time;\nstatic struct timeb cb_stop_time;\nstatic struct timeb cb_start_call_time;\nstatic struct timeb cb_stop_call_time;\n\nextern void f2py_start_clock(void) { ftime(&start_time); }\nextern\nvoid f2py_start_call_clock(void) {\n f2py_stop_clock();\n ftime(&start_call_time);\n}\nextern\nvoid f2py_stop_clock(void) {\n ftime(&stop_time);\n passed_time += 1000*(stop_time.time - start_time.time);\n passed_time += stop_time.millitm - start_time.millitm;\n}\nextern\nvoid f2py_stop_call_clock(void) {\n ftime(&stop_call_time);\n passed_call_time += 1000*(stop_call_time.time - start_call_time.time);\n passed_call_time += stop_call_time.millitm - start_call_time.millitm;\n passed_counter += 1;\n f2py_start_clock();\n}\n\nextern void f2py_cb_start_clock(void) { ftime(&cb_start_time); }\nextern\nvoid f2py_cb_start_call_clock(void) {\n f2py_cb_stop_clock();\n ftime(&cb_start_call_time);\n}\nextern\nvoid f2py_cb_stop_clock(void) {\n ftime(&cb_stop_time);\n cb_passed_time += 1000*(cb_stop_time.time - cb_start_time.time);\n cb_passed_time += cb_stop_time.millitm - cb_start_time.millitm;\n}\nextern\nvoid f2py_cb_stop_call_clock(void) {\n ftime(&cb_stop_call_time);\n cb_passed_call_time += 1000*(cb_stop_call_time.time - cb_start_call_time.time);\n cb_passed_call_time += cb_stop_call_time.millitm - cb_start_call_time.millitm;\n cb_passed_counter += 1;\n f2py_cb_start_clock();\n}\n\nstatic int f2py_report_on_exit_been_here = 0;\nextern\nvoid f2py_report_on_exit(int exit_flag,void *name) {\n if (f2py_report_on_exit_been_here) {\n fprintf(stderr,\" %s\\n\",(char*)name);\n return;\n }\n f2py_report_on_exit_been_here = 1;\n fprintf(stderr,\" /-----------------------\\\\\\n\");\n fprintf(stderr,\" < F2PY performance report >\\n\");\n fprintf(stderr,\" \\\\-----------------------/\\n\");\n fprintf(stderr,\"Overall time spent in ...\\n\");\n fprintf(stderr,\"(a) wrapped (Fortran/C) functions : %8d msec\\n\",\n\t passed_call_time);\n fprintf(stderr,\"(b) f2py interface, %6d calls : %8d msec\\n\",\n\t passed_counter,passed_time);\n fprintf(stderr,\"(c) call-back (Python) functions : %8d msec\\n\",\n\t cb_passed_call_time);\n fprintf(stderr,\"(d) f2py call-back interface, %6d calls : %8d msec\\n\",\n\t cb_passed_counter,cb_passed_time);\n \n fprintf(stderr,\"(e) wrapped (Fortran/C) functions (acctual) : %8d msec\\n\\n\",\n\t passed_call_time-cb_passed_call_time-cb_passed_time);\n fprintf(stderr,\"Use -DF2PY_REPORT_ATEXIT_DISABLE to disable this message.\\n\");\n fprintf(stderr,\"Exit status: %d\\n\",exit_flag);\n fprintf(stderr,\"Modules : %s\\n\",(char*)name);\n}\n#endif\n\n/********************** report on array copy ****************************/\n\n#ifdef F2PY_REPORT_ON_ARRAY_COPY\nstatic void f2py_report_on_array_copy(PyArrayObject* arr) {\n const long arr_size = PyArray_Size((PyObject *)arr);\n if (arr_size>F2PY_REPORT_ON_ARRAY_COPY) {\n fprintf(stderr,\"copied an array: size=%ld, elsize=%d\\n\", \n\t arr_size, PyArray_ITEMSIZE(arr));\n }\n}\nstatic void f2py_report_on_array_copy_fromany(void) {\n fprintf(stderr,\"created an array from object\\n\");\n}\n\n#define F2PY_REPORT_ON_ARRAY_COPY_FROMARR f2py_report_on_array_copy((PyArrayObject *)arr)\n#define F2PY_REPORT_ON_ARRAY_COPY_FROMANY f2py_report_on_array_copy_fromany()\n#else\n#define F2PY_REPORT_ON_ARRAY_COPY_FROMARR\n#define F2PY_REPORT_ON_ARRAY_COPY_FROMANY\n#endif\n\n\n/************************* array_from_obj *******************************/\n\n/* \n * File: array_from_pyobj.c \n *\n * Description:\n * ------------ \n * Provides array_from_pyobj function that returns a contigious array\n * object with the given dimensions and required storage order, either\n * in row-major (C) or column-major (Fortran) order. The function\n * array_from_pyobj is very flexible about its Python object argument\n * that can be any number, list, tuple, or array.\n * \n * array_from_pyobj is used in f2py generated Python extension\n * modules.\n *\n * Author: Pearu Peterson \n * Created: 13-16 January 2002\n * $Id: fortranobject.c,v 1.52 2005/07/11 07:44:20 pearu Exp $\n */\n\nstatic int \ncount_nonpos(const int rank,\n\t const intp *dims) {\n int i=0,r=0;\n while (ind;\n intp size = PyArray_Size((PyObject *)arr);\n int i;\n printf(\"\\trank = %d, flags = %d, size = %\" INTP_FMT \"\\n\",\n\t rank,arr->flags,size);\n printf(\"\\tstrides = [\");\n for(i=0;istrides[i]);\n }\n printf(\"]\\n\\t dimensions = [\");\n for(i=0;idimensions[i]);\n }\n printf(\"]\\n\");\n}\n#endif\n\n#define SWAPTYPE(a,b,t) {t c; c = (a); (a) = (b); (b) = c; }\n\nstatic int swap_arrays(PyArrayObject* arr1, PyArrayObject* arr2) {\n SWAPTYPE(arr1->data,arr2->data,char*);\n SWAPTYPE(arr1->nd,arr2->nd,int);\n SWAPTYPE(arr1->dimensions,arr2->dimensions,intp*);\n SWAPTYPE(arr1->strides,arr2->strides,intp*);\n SWAPTYPE(arr1->base,arr2->base,PyObject*);\n SWAPTYPE(arr1->descr,arr2->descr,PyArray_Descr*);\n SWAPTYPE(arr1->flags,arr2->flags,int);\n SWAPTYPE(arr1->itemsize, arr2->itemsize, int);\n /* SWAPTYPE(arr1->weakreflist,arr2->weakreflist,PyObject*); */\n return 0;\n}\n\nextern\nPyArrayObject* array_from_pyobj(const int type_num,\n\t\t\t\tintp *dims,\n\t\t\t\tconst int rank,\n\t\t\t\tconst int intent,\n\t\t\t\tPyObject *obj) {\n /* Note about reference counting\n -----------------------------\n If the caller returns the array to Python, it must be done with\n Py_BuildValue(\"N\",arr).\n Otherwise, if obj!=arr then the caller must call Py_DECREF(arr).\n\n Note on intent(cache,out,..)\n ---------------------\n Don't expect correct data when returning intent(cache) array.\n\n */\n char mess[200];\n PyArrayObject *arr = NULL;\n PyArray_Descr *descr = PyArray_DescrFromType(type_num);\n\n if ((intent & F2PY_INTENT_HIDE)\n || ((intent & F2PY_INTENT_CACHE) && (obj==Py_None))\n || ((intent & F2PY_OPTIONAL) && (obj==Py_None))\n ) {\n /* intent(cache), optional, intent(hide) */\n if (count_nonpos(rank,dims)) {\n int i;\n sprintf(mess,\"failed to create intent(cache|hide)|optional array\"\n\t \"-- must have defined dimensions but got (\");\n for(i=0;i=descr->elsize) {\n\tif (check_and_fix_dimensions((PyArrayObject *)obj,rank,dims))\n\t return NULL; /*XXX: set exception */\n\tif (intent & F2PY_INTENT_OUT)\n\t Py_INCREF(obj);\n\treturn (PyArrayObject *)obj;\n }\n sprintf(mess,\"failed to initialize intent(cache) array\");\n if (!PyArray_ISONESEGMENT(obj))\n\tsprintf(mess+strlen(mess),\" -- input must be in one segment\");\n if (PyArray_ITEMSIZE(arr)elsize)\n\tsprintf(mess+strlen(mess),\" -- expected at least elsize=%d but got %d\",\n\t\tdescr->elsize,PyArray_ITEMSIZE(arr)\n\t\t);\n PyErr_SetString(PyExc_ValueError,mess);\n return NULL;\n }\n\n /* here we have always intent(in) or intent(inout) or intent(inplace) */\n\n if (check_and_fix_dimensions(arr,rank,dims))\n return NULL; /*XXX: set exception */\n\n if ((! (intent & F2PY_INTENT_COPY))\n\t&& PyArray_ITEMSIZE(arr)==descr->elsize\n\t&& PyArray_CanCastSafely(arr->descr->type_num,type_num)\n\t) {\n if ((intent & F2PY_INTENT_C)?PyArray_ISCARRAY(arr):PyArray_ISFARRAY(arr)) {\n\tif ((intent & F2PY_INTENT_OUT)) {\n\t Py_INCREF(arr);\n\t}\n\t/* Returning input array */\n\treturn arr;\n }\n }\n\n if (intent & F2PY_INTENT_INOUT) {\n sprintf(mess,\"failed to initialize intent(inout) array\");\n if ((intent & F2PY_INTENT_C) && !PyArray_ISCARRAY(arr))\n\tsprintf(mess+strlen(mess),\" -- input not contiguous\");\n if (!(intent & F2PY_INTENT_C) && !PyArray_ISFARRAY(arr))\n\tsprintf(mess+strlen(mess),\" -- input not fortran contiguous\");\n if (PyArray_ITEMSIZE(arr)!=descr->elsize)\n\tsprintf(mess+strlen(mess),\" -- expected elsize=%d but got %d\",\n\t\tdescr->elsize,\n\t\tPyArray_ITEMSIZE(arr)\n\t\t);\n if (!(PyArray_CanCastSafely(arr->descr->type_num,type_num)))\n\tsprintf(mess+strlen(mess),\" -- cannot cast safely from '%c' to '%c'\",\n\t\tarr->descr->type,descr->type);\n PyErr_SetString(PyExc_ValueError,mess);\n return NULL;\n }\n\n /* here we have always intent(in) or intent(inplace) */\n\n {\n PyArrayObject *retarr = (PyArrayObject *) \\\n\tPyArray_New(&PyArray_Type, rank, dims, type_num,\n\t\t NULL,NULL,0,\n\t\t !(intent&F2PY_INTENT_C),\n\t\t NULL);\n if (retarr==NULL)\n\treturn NULL;\n F2PY_REPORT_ON_ARRAY_COPY_FROMARR;\n if (PyArray_CopyInto(retarr, arr)) {\n\tPy_DECREF(retarr);\n\treturn NULL;\n }\n if (intent & F2PY_INTENT_INPLACE) {\n\tif (swap_arrays(arr,retarr))\n\t return NULL; /* XXX: set exception */\n\tPy_XDECREF(retarr);\n\tif (intent & F2PY_INTENT_OUT)\n\t Py_INCREF(arr);\n } else {\n\tarr = retarr;\n }\n }\n return arr;\n }\n\n if ((intent & F2PY_INTENT_INOUT) \n || (intent & F2PY_INTENT_INPLACE)\n || (intent & F2PY_INTENT_CACHE)) {\n sprintf(mess,\"failed to initialize intent(inout|inplace|cache) array\"\n\t \" -- input must be array but got %s\",\n\t PyString_AsString(PyObject_Str(PyObject_Type(obj)))\n\t );\n PyErr_SetString(PyExc_TypeError,mess);\n return NULL;\n }\n\n {\n PyArray_Typecode typecode = {type_num, 0, 0};\n F2PY_REPORT_ON_ARRAY_COPY_FROMANY;\n arr = (PyArrayObject *) \\\n PyArray_FromAny(obj,&typecode, 0,0,\n\t\t ((intent & F2PY_INTENT_C)?CARRAY_FLAGS:FARRAY_FLAGS));\n if (arr==NULL)\n return NULL;\n if (check_and_fix_dimensions(arr,rank,dims))\n return NULL; /*XXX: set exception */\n return arr;\n }\n\n}\n\n /*****************************************/\n /* Helper functions for array_from_pyobj */\n /*****************************************/\n\nstatic\nint check_and_fix_dimensions(const PyArrayObject* arr,const int rank,intp *dims) {\n /*\n This function fills in blanks (that are -1\\'s) in dims list using\n the dimensions from arr. It also checks that non-blank dims will\n match with the corresponding values in arr dimensions.\n */\n const intp arr_size = (arr->nd)?PyArray_Size((PyObject *)arr):1;\n\n if (rank > arr->nd) { /* [1,2] -> [[1],[2]]; 1 -> [[1]] */\n intp new_size = 1;\n int free_axe = -1;\n int i;\n /* Fill dims where -1 or 0; check dimensions; calc new_size; */\n for(i=0;ind;++i) { \n if (dims[i] >= 0) {\n\tif (dims[i]!=arr->dimensions[i]) {\n\t fprintf(stderr,\"%d-th dimension must be fixed to %\" INTP_FMT\n\t\t \" but got %\" INTP_FMT \"\\n\",\n\t\t i,dims[i], arr->dimensions[i]);\n\t return 1;\n\t}\n\tif (!dims[i]) dims[i] = 1;\n } else {\n\tdims[i] = arr->dimensions[i] ? arr->dimensions[i] : 1;\n }\n new_size *= dims[i];\n }\n for(i=arr->nd;i1) {\n\tfprintf(stderr,\"%d-th dimension must be %\" INTP_FMT\n\t\t\" but got 0 (not defined).\\n\",\n\t\ti,dims[i]);\n\treturn 1;\n } else if (free_axe<0)\n\tfree_axe = i;\n else\n\tdims[i] = 1;\n if (free_axe>=0) {\n dims[free_axe] = arr_size/new_size;\n new_size *= dims[free_axe];\n }\n if (new_size != arr_size) {\n fprintf(stderr,\"confused: new_size=%\" INTP_FMT\n\t \", arr_size=%\" INTP_FMT \" (maybe too many free\"\n\t \" indices)\\n\", new_size,arr_size);\n return 1;\n }\n } else { /* [[1,2]] -> [[1],[2]] */\n int i,j;\n intp d;\n int effrank;\n intp size;\n for (i=0,effrank=0;ind;++i)\n if (arr->dimensions[i]>1) ++effrank;\n if (dims[rank-1]>=0)\n if (effrank>rank) {\n\tfprintf(stderr,\"too many axes: %d (effrank=%d), expected rank=%d\\n\",\n\t\tarr->nd,effrank,rank);\n\treturn 1;\n }\n for (i=0,j=0;ind && arr->dimensions[j]<2) ++j;\n if (j>=arr->nd) d = 1;\n else d = arr->dimensions[j++];\n if (dims[i]>=0) {\n\tif (d>1 && d!=dims[i]) {\n\t fprintf(stderr,\"%d-th dimension must be fixed to %\" INTP_FMT \n\t\t \" but got %\" INTP_FMT \" (real index=%d)\\n\",\n\t\t i,dims[i],d,j-1);\n\t return 1;\t \n\t}\n\tif (!dims[i]) dims[i] = 1;\n } else\n\tdims[i] = d;\n }\n for (i=rank;ind;++i) { /* [[1,2],[3,4]] -> [1,2,3,4] */\n while (jnd && arr->dimensions[j]<2) ++j;\n if (j>=arr->nd) d = 1;\n else d = arr->dimensions[j++];\n dims[rank-1] *= d;\n }\n for (i=0,size=1;ind);\n for (i=0;ind;++i) fprintf(stderr,\" %\" INTP_FMT,arr->dimensions[i]);\n fprintf(stderr,\" ]\\n\");\n return 1;\n }\n }\n return 0;\n}\n\n/* End of file: array_from_pyobj.c */\n\n/************************* copy_ND_array *******************************/\n\nextern\nint copy_ND_array(const PyArrayObject *arr, PyArrayObject *out)\n{\n F2PY_REPORT_ON_ARRAY_COPY_FROMARR;\n return PyArray_CopyInto(out, (PyArrayObject *)arr);\n}\n\n#ifdef __cplusplus\n}\n#endif\n/************************* EOF fortranobject.c *******************************/\n", "methods": [ { "name": "PyFortranObject_New", "long_name": "PyFortranObject_New( FortranDataDef * defs , f2py_void_func init)", "filename": "fortranobject.c", "nloc": 31, "complexity": 11, "token_count": 312, "parameters": [ "defs", "init" ], "start_line": 20, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 1 }, { "name": "PyFortranObject_NewAsAttr", "long_name": "PyFortranObject_NewAsAttr( FortranDataDef * defs)", "filename": "fortranobject.c", "nloc": 9, "complexity": 3, "token_count": 69, "parameters": [ "defs" ], "start_line": 53, "end_line": 61, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "fortran_dealloc", "long_name": "fortran_dealloc( PyFortranObject * fp)", "filename": "fortranobject.c", "nloc": 4, "complexity": 1, "token_count": 20, "parameters": [ "fp" ], "start_line": 66, "end_line": 69, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "fortran_doc", "long_name": "fortran_doc( FortranDataDef def)", "filename": "fortranobject.c", "nloc": 46, "complexity": 21, "token_count": 434, "parameters": [ "def" ], "start_line": 78, "end_line": 123, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 46, "top_nesting_level": 1 }, { "name": "set_data", "long_name": "set_data( char * d , intp * f)", "filename": "fortranobject.c", "nloc": 6, "complexity": 2, "token_count": 30, "parameters": [ "d", "f" ], "start_line": 126, "end_line": 132, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "fortran_getattr", "long_name": "fortran_getattr( PyFortranObject * fp , char * name)", "filename": "fortranobject.c", "nloc": 52, "complexity": 18, "token_count": 519, "parameters": [ "fp", "name" ], "start_line": 135, "end_line": 187, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "top_nesting_level": 1 }, { "name": "fortran_setattr", "long_name": "fortran_setattr( PyFortranObject * fp , char * name , PyObject * v)", "filename": "fortranobject.c", "nloc": 59, "complexity": 22, "token_count": 647, "parameters": [ "fp", "name", "v" ], "start_line": 190, "end_line": 250, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 61, "top_nesting_level": 1 }, { "name": "fortran_call", "long_name": "fortran_call( PyFortranObject * fp , PyObject * arg , PyObject * kw)", "filename": "fortranobject.c", "nloc": 16, "complexity": 4, "token_count": 166, "parameters": [ "fp", "arg", "kw" ], "start_line": 253, "end_line": 272, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "f2py_start_clock", "long_name": "f2py_start_clock()", "filename": "fortranobject.c", "nloc": 1, "complexity": 1, "token_count": 12, "parameters": [], "start_line": 313, "end_line": 313, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "f2py_start_call_clock", "long_name": "f2py_start_call_clock()", "filename": "fortranobject.c", "nloc": 4, "complexity": 1, "token_count": 16, "parameters": [], "start_line": 315, "end_line": 318, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "f2py_stop_clock", "long_name": "f2py_stop_clock()", "filename": "fortranobject.c", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [], "start_line": 320, "end_line": 324, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "f2py_stop_call_clock", "long_name": "f2py_stop_call_clock()", "filename": "fortranobject.c", "nloc": 7, "complexity": 1, "token_count": 44, "parameters": [], "start_line": 326, "end_line": 332, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "f2py_cb_start_clock", "long_name": "f2py_cb_start_clock()", "filename": "fortranobject.c", "nloc": 1, "complexity": 1, "token_count": 12, "parameters": [], "start_line": 334, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "f2py_cb_start_call_clock", "long_name": "f2py_cb_start_call_clock()", "filename": "fortranobject.c", "nloc": 4, "complexity": 1, "token_count": 16, "parameters": [], "start_line": 336, "end_line": 339, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "f2py_cb_stop_clock", "long_name": "f2py_cb_stop_clock()", "filename": "fortranobject.c", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [], "start_line": 341, "end_line": 345, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "f2py_cb_stop_call_clock", "long_name": "f2py_cb_stop_call_clock()", "filename": "fortranobject.c", "nloc": 7, "complexity": 1, "token_count": 44, "parameters": [], "start_line": 347, "end_line": 353, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "f2py_report_on_exit", "long_name": "f2py_report_on_exit( int exit_flag , * name)", "filename": "fortranobject.c", "nloc": 24, "complexity": 2, "token_count": 146, "parameters": [ "exit_flag", "name" ], "start_line": 357, "end_line": 381, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "f2py_report_on_array_copy", "long_name": "f2py_report_on_array_copy( PyArrayObject * arr)", "filename": "fortranobject.c", "nloc": 7, "complexity": 2, "token_count": 43, "parameters": [ "arr" ], "start_line": 387, "end_line": 393, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "f2py_report_on_array_copy_fromany", "long_name": "f2py_report_on_array_copy_fromany()", "filename": "fortranobject.c", "nloc": 3, "complexity": 1, "token_count": 13, "parameters": [], "start_line": 394, "end_line": 396, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "count_nonpos", "long_name": "count_nonpos( const int rank , const intp * dims)", "filename": "fortranobject.c", "nloc": 9, "complexity": 3, "token_count": 48, "parameters": [ "rank", "dims" ], "start_line": 428, "end_line": 436, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "dump_attrs", "long_name": "dump_attrs( const PyArrayObject * arr)", "filename": "fortranobject.c", "nloc": 16, "complexity": 3, "token_count": 117, "parameters": [ "arr" ], "start_line": 443, "end_line": 458, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "swap_arrays", "long_name": "swap_arrays( PyArrayObject * arr1 , PyArrayObject * arr2)", "filename": "fortranobject.c", "nloc": 11, "complexity": 1, "token_count": 124, "parameters": [ "arr1", "arr2" ], "start_line": 463, "end_line": 474, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "array_from_pyobj", "long_name": "array_from_pyobj( const int type_num , intp * dims , const int rank , const int intent , PyObject * obj)", "filename": "fortranobject.c", "nloc": 130, "complexity": 42, "token_count": 837, "parameters": [ "type_num", "dims", "rank", "intent", "obj" ], "start_line": 477, "end_line": 634, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 158, "top_nesting_level": 1 }, { "name": "check_and_fix_dimensions", "long_name": "check_and_fix_dimensions( const PyArrayObject * arr , const int rank , intp * dims)", "filename": "fortranobject.c", "nloc": 88, "complexity": 33, "token_count": 724, "parameters": [ "arr", "rank", "dims" ], "start_line": 641, "end_line": 735, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 95, "top_nesting_level": 1 }, { "name": "copy_ND_array", "long_name": "copy_ND_array( const PyArrayObject * arr , PyArrayObject * out)", "filename": "fortranobject.c", "nloc": 5, "complexity": 1, "token_count": 27, "parameters": [ "arr", "out" ], "start_line": 742, "end_line": 746, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 } ], "methods_before": [ { "name": "PyFortranObject_New", "long_name": "PyFortranObject_New( FortranDataDef * defs , f2py_void_func init)", "filename": "fortranobject.c", "nloc": 31, "complexity": 11, "token_count": 312, "parameters": [ "defs", "init" ], "start_line": 20, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 1 }, { "name": "PyFortranObject_NewAsAttr", "long_name": "PyFortranObject_NewAsAttr( FortranDataDef * defs)", "filename": "fortranobject.c", "nloc": 9, "complexity": 3, "token_count": 69, "parameters": [ "defs" ], "start_line": 53, "end_line": 61, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "fortran_dealloc", "long_name": "fortran_dealloc( PyFortranObject * fp)", "filename": "fortranobject.c", "nloc": 4, "complexity": 1, "token_count": 20, "parameters": [ "fp" ], "start_line": 66, "end_line": 69, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "fortran_doc", "long_name": "fortran_doc( FortranDataDef def)", "filename": "fortranobject.c", "nloc": 46, "complexity": 21, "token_count": 434, "parameters": [ "def" ], "start_line": 78, "end_line": 123, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 46, "top_nesting_level": 1 }, { "name": "set_data", "long_name": "set_data( char * d , intp * f)", "filename": "fortranobject.c", "nloc": 6, "complexity": 2, "token_count": 30, "parameters": [ "d", "f" ], "start_line": 126, "end_line": 132, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "fortran_getattr", "long_name": "fortran_getattr( PyFortranObject * fp , char * name)", "filename": "fortranobject.c", "nloc": 52, "complexity": 18, "token_count": 519, "parameters": [ "fp", "name" ], "start_line": 135, "end_line": 187, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "top_nesting_level": 1 }, { "name": "fortran_setattr", "long_name": "fortran_setattr( PyFortranObject * fp , char * name , PyObject * v)", "filename": "fortranobject.c", "nloc": 59, "complexity": 22, "token_count": 647, "parameters": [ "fp", "name", "v" ], "start_line": 190, "end_line": 250, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 61, "top_nesting_level": 1 }, { "name": "fortran_call", "long_name": "fortran_call( PyFortranObject * fp , PyObject * arg , PyObject * kw)", "filename": "fortranobject.c", "nloc": 16, "complexity": 4, "token_count": 166, "parameters": [ "fp", "arg", "kw" ], "start_line": 253, "end_line": 272, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "f2py_start_clock", "long_name": "f2py_start_clock()", "filename": "fortranobject.c", "nloc": 1, "complexity": 1, "token_count": 12, "parameters": [], "start_line": 313, "end_line": 313, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "f2py_start_call_clock", "long_name": "f2py_start_call_clock()", "filename": "fortranobject.c", "nloc": 4, "complexity": 1, "token_count": 16, "parameters": [], "start_line": 315, "end_line": 318, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "f2py_stop_clock", "long_name": "f2py_stop_clock()", "filename": "fortranobject.c", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [], "start_line": 320, "end_line": 324, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "f2py_stop_call_clock", "long_name": "f2py_stop_call_clock()", "filename": "fortranobject.c", "nloc": 7, "complexity": 1, "token_count": 44, "parameters": [], "start_line": 326, "end_line": 332, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "f2py_cb_start_clock", "long_name": "f2py_cb_start_clock()", "filename": "fortranobject.c", "nloc": 1, "complexity": 1, "token_count": 12, "parameters": [], "start_line": 334, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "f2py_cb_start_call_clock", "long_name": "f2py_cb_start_call_clock()", "filename": "fortranobject.c", "nloc": 4, "complexity": 1, "token_count": 16, "parameters": [], "start_line": 336, "end_line": 339, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "f2py_cb_stop_clock", "long_name": "f2py_cb_stop_clock()", "filename": "fortranobject.c", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [], "start_line": 341, "end_line": 345, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "f2py_cb_stop_call_clock", "long_name": "f2py_cb_stop_call_clock()", "filename": "fortranobject.c", "nloc": 7, "complexity": 1, "token_count": 44, "parameters": [], "start_line": 347, "end_line": 353, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "f2py_report_on_exit", "long_name": "f2py_report_on_exit( int exit_flag , * name)", "filename": "fortranobject.c", "nloc": 24, "complexity": 2, "token_count": 146, "parameters": [ "exit_flag", "name" ], "start_line": 357, "end_line": 381, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "f2py_report_on_array_copy", "long_name": "f2py_report_on_array_copy( PyArrayObject * arr)", "filename": "fortranobject.c", "nloc": 7, "complexity": 2, "token_count": 43, "parameters": [ "arr" ], "start_line": 387, "end_line": 393, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "f2py_report_on_array_copy_fromany", "long_name": "f2py_report_on_array_copy_fromany()", "filename": "fortranobject.c", "nloc": 3, "complexity": 1, "token_count": 13, "parameters": [], "start_line": 394, "end_line": 396, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "count_nonpos", "long_name": "count_nonpos( const int rank , const intp * dims)", "filename": "fortranobject.c", "nloc": 9, "complexity": 3, "token_count": 48, "parameters": [ "rank", "dims" ], "start_line": 428, "end_line": 436, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "dump_attrs", "long_name": "dump_attrs( const PyArrayObject * arr)", "filename": "fortranobject.c", "nloc": 16, "complexity": 3, "token_count": 117, "parameters": [ "arr" ], "start_line": 443, "end_line": 458, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "swap_arrays", "long_name": "swap_arrays( PyArrayObject * arr1 , PyArrayObject * arr2)", "filename": "fortranobject.c", "nloc": 11, "complexity": 1, "token_count": 124, "parameters": [ "arr1", "arr2" ], "start_line": 463, "end_line": 474, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "array_from_pyobj", "long_name": "array_from_pyobj( const int type_num , intp * dims , const int rank , const int intent , PyObject * obj)", "filename": "fortranobject.c", "nloc": 130, "complexity": 42, "token_count": 833, "parameters": [ "type_num", "dims", "rank", "intent", "obj" ], "start_line": 477, "end_line": 634, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 158, "top_nesting_level": 1 }, { "name": "check_and_fix_dimensions", "long_name": "check_and_fix_dimensions( const PyArrayObject * arr , const int rank , intp * dims)", "filename": "fortranobject.c", "nloc": 88, "complexity": 33, "token_count": 724, "parameters": [ "arr", "rank", "dims" ], "start_line": 641, "end_line": 735, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 95, "top_nesting_level": 1 }, { "name": "copy_ND_array", "long_name": "copy_ND_array( const PyArrayObject * arr , PyArrayObject * out)", "filename": "fortranobject.c", "nloc": 5, "complexity": 1, "token_count": 27, "parameters": [ "arr", "out" ], "start_line": 742, "end_line": 746, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "array_from_pyobj", "long_name": "array_from_pyobj( const int type_num , intp * dims , const int rank , const int intent , PyObject * obj)", "filename": "fortranobject.c", "nloc": 130, "complexity": 42, "token_count": 837, "parameters": [ "type_num", "dims", "rank", "intent", "obj" ], "start_line": 477, "end_line": 634, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 158, "top_nesting_level": 1 } ], "nloc": 612, "complexity": 178, "token_count": 4746, "diff_parsed": { "added": [ "\tPyArray_New(&PyArray_Type, arr->nd, arr->dimensions, type_num," ], "deleted": [ "\tPyArray_New(&PyArray_Type, rank, dims, type_num," ] } } ] }, { "hash": "4e917206d27330ce59e19098385477a285b85062", "msg": "Fixed tests on opteron", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2005-10-26T21:00:54+00:00", "author_timezone": 0, "committer_date": "2005-10-26T21:00:54+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "4fd834508fd08514f9fd9b326b7363d96a480dd7" ], "project_name": "repo_copy", "project_path": "/tmp/tmpn4cqam_6/repo_copy", "deletions": 2, "insertions": 2, "lines": 4, "files": 1, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "scipy/f2py2e/tests/array_from_pyobj/tests/test_array_from_pyobj.py", "new_path": "scipy/f2py2e/tests/array_from_pyobj/tests/test_array_from_pyobj.py", "filename": "test_array_from_pyobj.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -72,8 +72,8 @@ class Type(object):\n _cast_dict['LONG'] = _cast_dict['INT'] + ['LONG']\n _cast_dict['ULONG'] = _cast_dict['UINT'] + ['ULONG']\n \n- _cast_dict['LONGLONG'] = _cast_dict['LONG'] + ['ULONG','LONGLONG']\n- _cast_dict['ULONGLONG'] = _cast_dict['ULONG'] + ['LONG','ULONGLONG']\n+ _cast_dict['LONGLONG'] = _cast_dict['LONG'] + ['LONGLONG']\n+ _cast_dict['ULONGLONG'] = _cast_dict['ULONG'] + ['ULONGLONG']\n \n _cast_dict['FLOAT'] = _cast_dict['SHORT'] + ['USHORT','FLOAT']\n _cast_dict['DOUBLE'] = _cast_dict['INT'] + ['UINT','FLOAT','DOUBLE']\n", "added_lines": 2, "deleted_lines": 2, "source_code": "import unittest\nimport sys\nimport copy\n\nfrom scipy.test.testing import *\nfrom scipy.base import array, typeinfo, alltrue, ndarray, asarray, can_cast,zeros\nset_package_path()\nfrom array_from_pyobj import wrap\ndel sys.path[0]\n\ndef flags_info(arr):\n flags = wrap.array_attrs(arr)[6]\n return flags2names(flags)\n\ndef flags2names(flags):\n info = []\n for flagname in ['CONTIGUOUS','FORTRAN','OWNDATA','ENSURECOPY',\n 'ENSUREARRAY','ALIGNED','NOTSWAPPED','WRITEABLE',\n 'UPDATEIFCOPY','BEHAVED_FLAGS','BEHAVED_FLAGS_RO',\n 'CARRAY_FLAGS','FARRAY_FLAGS'\n ]:\n if abs(flags) & getattr(wrap,flagname):\n info.append(flagname)\n return info\n\nclass Intent:\n def __init__(self,intent_list=[]):\n self.intent_list = intent_list[:]\n flags = 0\n for i in intent_list:\n if i=='optional':\n flags |= wrap.F2PY_OPTIONAL\n else:\n flags |= getattr(wrap,'F2PY_INTENT_'+i.upper())\n self.flags = flags\n def __getattr__(self,name):\n name = name.lower()\n if name=='in_': name='in'\n return self.__class__(self.intent_list+[name])\n def __str__(self):\n return 'intent(%s)' % (','.join(self.intent_list))\n def __repr__(self):\n return 'Intent(%r)' % (self.intent_list)\n def is_intent(self,*names):\n for name in names:\n if name not in self.intent_list:\n return False\n return True\n def is_intent_exact(self,*names):\n return len(self.intent_list)==len(names) and self.is_intent(*names)\n\nintent = Intent()\n\nclass Type(object):\n\n _type_names = ['BOOL','BYTE','UBYTE','SHORT','USHORT','INT','UINT',\n 'LONG','ULONG','LONGLONG','ULONGLONG',\n 'FLOAT','DOUBLE','LONGDOUBLE','CFLOAT','CDOUBLE',\n 'CLONGDOUBLE']\n _type_cache = {}\n\n _cast_dict = {'BOOL':['BOOL']}\n _cast_dict['BYTE'] = _cast_dict['BOOL'] + ['BYTE']\n _cast_dict['UBYTE'] = _cast_dict['BOOL'] + ['UBYTE']\n _cast_dict['BYTE'] = ['BYTE']\n _cast_dict['UBYTE'] = ['UBYTE']\n _cast_dict['SHORT'] = _cast_dict['BYTE'] + ['UBYTE','SHORT']\n _cast_dict['USHORT'] = _cast_dict['UBYTE'] + ['BYTE','USHORT']\n _cast_dict['INT'] = _cast_dict['SHORT'] + ['USHORT','INT']\n _cast_dict['UINT'] = _cast_dict['USHORT'] + ['SHORT','UINT']\n\n _cast_dict['LONG'] = _cast_dict['INT'] + ['LONG']\n _cast_dict['ULONG'] = _cast_dict['UINT'] + ['ULONG']\n\n _cast_dict['LONGLONG'] = _cast_dict['LONG'] + ['LONGLONG']\n _cast_dict['ULONGLONG'] = _cast_dict['ULONG'] + ['ULONGLONG']\n\n _cast_dict['FLOAT'] = _cast_dict['SHORT'] + ['USHORT','FLOAT']\n _cast_dict['DOUBLE'] = _cast_dict['INT'] + ['UINT','FLOAT','DOUBLE']\n _cast_dict['LONGDOUBLE'] = _cast_dict['LONG'] + ['ULONG','FLOAT','DOUBLE','LONGDOUBLE']\n\n _cast_dict['CFLOAT'] = _cast_dict['FLOAT'] + ['CFLOAT']\n _cast_dict['CDOUBLE'] = _cast_dict['DOUBLE'] + ['CFLOAT','CDOUBLE']\n _cast_dict['CLONGDOUBLE'] = _cast_dict['LONGDOUBLE'] + ['CFLOAT','CDOUBLE','CLONGDOUBLE']\n \n \n def __new__(cls,name):\n if isinstance(name,type):\n dtype = name\n name = None\n for n,i in typeinfo.items():\n if isinstance(i,tuple) and dtype is i[-1]:\n name = n\n break\n obj = cls._type_cache.get(name.upper(),None)\n if obj is not None:\n return obj\n obj = object.__new__(cls)\n obj._init(name)\n cls._type_cache[name.upper()] = obj\n return obj\n \n def _init(self,name):\n self.NAME = name.upper()\n self.type_num = getattr(wrap,'PyArray_'+self.NAME)\n assert_equal(self.type_num,typeinfo[self.NAME][1])\n self.dtype = typeinfo[self.NAME][-1]\n self.elsize = typeinfo[self.NAME][2] / 8\n self.dtypechar = typeinfo[self.NAME][0]\n\n def cast_types(self):\n return map(self.__class__,self._cast_dict[self.NAME])\n\n def all_types(self):\n return map(self.__class__,self._type_names)\n\n def smaller_types(self):\n bits = typeinfo[self.NAME][3]\n types = []\n for name in self._type_names:\n if typeinfo[name][3]bits:\n types.append(Type(name))\n return types\n\nclass Array:\n def __init__(self,typ,dims,intent,obj):\n self.type = typ\n self.dims = dims\n self.intent = intent\n self.obj_copy = copy.deepcopy(obj)\n self.obj = obj\n\n # arr.dtypechar may be different from typ.dtypechar\n self.arr = wrap.call(typ.type_num,dims,intent.flags,obj)\n\n self.arr_attr = wrap.array_attrs(self.arr)\n\n if len(dims)>1:\n if self.intent.is_intent('c'):\n assert intent.flags & wrap.F2PY_INTENT_C\n assert not self.arr.flags['FORTRAN'],`self.arr.flags,obj.flags`\n assert self.arr.flags['CONTIGUOUS']\n assert not self.arr_attr[6] & wrap.FORTRAN\n else:\n assert not intent.flags & wrap.F2PY_INTENT_C\n assert self.arr.flags['FORTRAN']\n assert not self.arr.flags['CONTIGUOUS']\n assert self.arr_attr[6] & wrap.FORTRAN\n\n if obj is None:\n self.pyarr = None\n self.pyarr_attr = None\n return\n\n if intent.is_intent('cache'):\n assert isinstance(obj,ndarray),`type(obj)`\n self.pyarr = array(obj).reshape(*dims)\n \n else:\n self.pyarr = array(array(obj,\n dtype = typ.dtypechar).reshape(*dims),\n fortran=not self.intent.is_intent('c'))\n assert self.pyarr.dtypechar==typ.dtypechar,\\\n `self.pyarr.dtypechar,typ.dtypechar`\n assert self.pyarr.flags['OWNDATA']\n self.pyarr_attr = wrap.array_attrs(self.pyarr)\n\n if len(dims)>1:\n if self.intent.is_intent('c'):\n assert not self.pyarr.flags['FORTRAN']\n assert self.pyarr.flags['CONTIGUOUS']\n assert not self.pyarr_attr[6] & wrap.FORTRAN\n else:\n assert self.pyarr.flags['FORTRAN']\n assert not self.pyarr.flags['CONTIGUOUS']\n assert self.pyarr_attr[6] & wrap.FORTRAN\n\n\n assert self.arr_attr[1]==self.pyarr_attr[1] # nd\n assert self.arr_attr[2]==self.pyarr_attr[2] # dimensions\n if self.arr_attr[1]<=1:\n assert self.arr_attr[3]==self.pyarr_attr[3],\\\n `self.arr_attr[3],self.pyarr_attr[3],self.arr.tostring(),self.pyarr.tostring()` # strides\n assert self.arr_attr[5][-2:]==self.pyarr_attr[5][-2:],\\\n `self.arr_attr[5],self.pyarr_attr[5]` # descr\n assert self.arr_attr[6]==self.pyarr_attr[6],\\\n `self.arr_attr[6],self.pyarr_attr[6],flags2names(0*self.arr_attr[6]-self.pyarr_attr[6]),flags2names(self.arr_attr[6]),intent` # flags\n\n if intent.is_intent('cache'):\n assert self.arr_attr[5][3]>=self.type.elsize,\\\n `self.arr_attr[5][3],self.type.elsize`\n else:\n assert self.arr_attr[5][3]==self.type.elsize,\\\n `self.arr_attr[5][3],self.type.elsize`\n assert self.arr_equal(self.pyarr,self.arr)\n \n if isinstance(self.obj,ndarray):\n if typ.elsize==Type(obj.dtype).elsize:\n if not intent.is_intent('copy') and self.arr_attr[1]<=1:\n assert self.has_shared_memory()\n\n def arr_equal(self,arr1,arr2):\n if arr1.shape != arr2.shape:\n return False\n return alltrue(arr1==arr2)\n\n def __str__(self):\n return str(self.arr)\n\n def has_shared_memory(self):\n \"\"\"Check that created array shares data with input array.\n \"\"\"\n if self.obj is self.arr:\n return True\n if not isinstance(self.obj,ndarray):\n return False\n obj_attr = wrap.array_attrs(self.obj)\n return obj_attr[0]==self.arr_attr[0]\n\n##################################################\n\nclass test_intent(unittest.TestCase):\n def check_in_out(self):\n assert_equal(str(intent.in_.out),'intent(in,out)')\n assert intent.in_.c.is_intent('c')\n assert not intent.in_.c.is_intent_exact('c')\n assert intent.in_.c.is_intent_exact('c','in')\n assert intent.in_.c.is_intent_exact('in','c')\n assert not intent.in_.is_intent('c')\n\nclass _test_shared_memory:\n num2seq = [1,2]\n num23seq = [[1,2,3],[4,5,6]]\n def check_in_from_2seq(self):\n a = self.array([2],intent.in_,self.num2seq)\n assert not a.has_shared_memory()\n\n def check_in_from_2casttype(self):\n for t in self.type.cast_types():\n obj = array(self.num2seq,dtype=t.dtype)\n a = self.array([len(self.num2seq)],intent.in_,obj)\n if t.elsize==self.type.elsize:\n assert a.has_shared_memory(),`self.type.dtype,t.dtype`\n else:\n assert not a.has_shared_memory(),`t.dtype`\n\n def check_inout_2seq(self):\n obj = array(self.num2seq,dtype=self.type.dtype)\n a = self.array([len(self.num2seq)],intent.inout,obj)\n assert a.has_shared_memory()\n\n try:\n a = self.array([2],intent.in_.inout,self.num2seq)\n except TypeError,msg:\n if not str(msg).startswith('failed to initialize intent(inout|inplace|cache) array'):\n raise\n else:\n raise SystemError,'intent(inout) should have failed on sequence'\n\n def check_f_inout_23seq(self):\n obj = array(self.num23seq,dtype=self.type.dtype,fortran=1)\n shape = (len(self.num23seq),len(self.num23seq[0]))\n a = self.array(shape,intent.in_.inout,obj)\n assert a.has_shared_memory()\n\n obj = array(self.num23seq,dtype=self.type.dtype,fortran=0)\n shape = (len(self.num23seq),len(self.num23seq[0]))\n try:\n a = self.array(shape,intent.in_.inout,obj)\n except ValueError,msg:\n if not str(msg).startswith('failed to initialize intent(inout) array'):\n raise\n else:\n raise SystemError,'intent(inout) should have failed on improper array'\n\n def check_c_inout_23seq(self):\n obj = array(self.num23seq,dtype=self.type.dtype)\n shape = (len(self.num23seq),len(self.num23seq[0]))\n a = self.array(shape,intent.in_.c.inout,obj)\n assert a.has_shared_memory()\n\n def check_in_copy_from_2casttype(self):\n for t in self.type.cast_types():\n obj = array(self.num2seq,dtype=t.dtype)\n a = self.array([len(self.num2seq)],intent.in_.copy,obj)\n assert not a.has_shared_memory(),`t.dtype`\n\n def check_c_in_from_23seq(self):\n a = self.array([len(self.num23seq),len(self.num23seq[0])],\n intent.in_,self.num23seq)\n assert not a.has_shared_memory()\n\n def check_in_from_23casttype(self):\n for t in self.type.cast_types():\n obj = array(self.num23seq,dtype=t.dtype)\n a = self.array([len(self.num23seq),len(self.num23seq[0])],\n intent.in_,obj)\n assert not a.has_shared_memory(),`t.dtype`\n\n def check_f_in_from_23casttype(self):\n for t in self.type.cast_types():\n obj = array(self.num23seq,dtype=t.dtype,fortran=1)\n a = self.array([len(self.num23seq),len(self.num23seq[0])],\n intent.in_,obj)\n if t.elsize==self.type.elsize:\n assert a.has_shared_memory(),`t.dtype`\n else:\n assert not a.has_shared_memory(),`t.dtype`\n\n def check_c_in_from_23casttype(self):\n for t in self.type.cast_types():\n obj = array(self.num23seq,dtype=t.dtype)\n a = self.array([len(self.num23seq),len(self.num23seq[0])],\n intent.in_.c,obj)\n if t.elsize==self.type.elsize:\n assert a.has_shared_memory(),`t.dtype`\n else:\n assert not a.has_shared_memory(),`t.dtype`\n\n def check_f_copy_in_from_23casttype(self):\n for t in self.type.cast_types():\n obj = array(self.num23seq,dtype=t.dtype,fortran=1)\n a = self.array([len(self.num23seq),len(self.num23seq[0])],\n intent.in_.copy,obj)\n assert not a.has_shared_memory(),`t.dtype`\n\n def check_c_copy_in_from_23casttype(self):\n for t in self.type.cast_types():\n obj = array(self.num23seq,dtype=t.dtype)\n a = self.array([len(self.num23seq),len(self.num23seq[0])],\n intent.in_.c.copy,obj)\n assert not a.has_shared_memory(),`t.dtype`\n\n def check_in_cache_from_2casttype(self):\n for t in self.type.all_types():\n if t.elsize != self.type.elsize:\n continue\n obj = array(self.num2seq,dtype=t.dtype)\n shape = (len(self.num2seq),)\n a = self.array(shape,intent.in_.c.cache,obj) \n assert a.has_shared_memory(),`t.dtype`\n\n a = self.array(shape,intent.in_.cache,obj) \n assert a.has_shared_memory(),`t.dtype`\n \n obj = array(self.num2seq,dtype=t.dtype,fortran=1)\n a = self.array(shape,intent.in_.c.cache,obj) \n assert a.has_shared_memory(),`t.dtype`\n\n a = self.array(shape,intent.in_.cache,obj)\n assert a.has_shared_memory(),`t.dtype`\n\n try:\n a = self.array(shape,intent.in_.cache,obj[::-1])\n except ValueError,msg:\n if not str(msg).startswith('failed to initialize intent(cache) array'):\n raise\n else:\n raise SystemError,'intent(cache) should have failed on multisegmented array'\n def check_in_cache_from_2casttype_failure(self):\n for t in self.type.all_types():\n if t.elsize >= self.type.elsize:\n continue\n obj = array(self.num2seq,dtype=t.dtype)\n shape = (len(self.num2seq),)\n try:\n a = self.array(shape,intent.in_.cache,obj)\n except ValueError,msg:\n if not str(msg).startswith('failed to initialize intent(cache) array'):\n raise\n else:\n raise SystemError,'intent(cache) should have failed on smaller array'\n\n def check_cache_hidden(self):\n shape = (2,)\n a = self.array(shape,intent.cache.hide,None)\n assert a.arr.shape==shape\n\n shape = (2,3)\n a = self.array(shape,intent.cache.hide,None)\n assert a.arr.shape==shape\n\n shape = (-1,3)\n try:\n a = self.array(shape,intent.cache.hide,None)\n except ValueError,msg:\n if not str(msg).startswith('failed to create intent(cache|hide)|optional array'):\n raise\n else:\n raise SystemError,'intent(cache) should have failed on undefined dimensions'\n\n def check_hidden(self):\n shape = (2,)\n a = self.array(shape,intent.hide,None)\n assert a.arr.shape==shape\n assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))\n\n shape = (2,3)\n a = self.array(shape,intent.hide,None)\n assert a.arr.shape==shape\n assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))\n assert a.arr.flags['FORTRAN'] and not a.arr.flags['CONTIGUOUS']\n\n shape = (2,3)\n a = self.array(shape,intent.c.hide,None)\n assert a.arr.shape==shape\n assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))\n assert not a.arr.flags['FORTRAN'] and a.arr.flags['CONTIGUOUS']\n\n shape = (-1,3)\n try:\n a = self.array(shape,intent.hide,None)\n except ValueError,msg:\n if not str(msg).startswith('failed to create intent(cache|hide)|optional array'):\n raise\n else:\n raise SystemError,'intent(hide) should have failed on undefined dimensions'\n\n def check_optional_none(self):\n shape = (2,)\n a = self.array(shape,intent.optional,None)\n assert a.arr.shape==shape\n assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))\n\n shape = (2,3)\n a = self.array(shape,intent.optional,None)\n assert a.arr.shape==shape\n assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))\n assert a.arr.flags['FORTRAN'] and not a.arr.flags['CONTIGUOUS']\n\n shape = (2,3)\n a = self.array(shape,intent.c.optional,None)\n assert a.arr.shape==shape\n assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))\n assert not a.arr.flags['FORTRAN'] and a.arr.flags['CONTIGUOUS']\n\n def check_optional_from_2seq(self):\n obj = self.num2seq\n shape = (len(obj),)\n a = self.array(shape,intent.optional,obj)\n assert a.arr.shape==shape\n assert not a.has_shared_memory()\n\n def check_optional_from_23seq(self):\n obj = self.num23seq\n shape = (len(obj),len(obj[0]))\n a = self.array(shape,intent.optional,obj)\n assert a.arr.shape==shape\n assert not a.has_shared_memory()\n\n a = self.array(shape,intent.optional.c,obj)\n assert a.arr.shape==shape\n assert not a.has_shared_memory()\n\n def check_inplace(self):\n obj = array(self.num23seq,dtype=self.type.dtype)\n assert not obj.flags['FORTRAN'] and obj.flags['CONTIGUOUS']\n shape = obj.shape\n a = self.array(shape,intent.inplace,obj)\n assert obj[1][2]==a.arr[1][2],`obj,a.arr`\n a.arr[1][2]=54\n assert obj[1][2]==a.arr[1][2]==array(54,dtype=self.type.dtype),`obj,a.arr`\n assert a.arr is obj\n assert obj.flags['FORTRAN'] # obj attributes are changed inplace!\n assert not obj.flags['CONTIGUOUS']\n\n def check_inplace_from_casttype(self):\n for t in self.type.cast_types():\n if t is self.type:\n continue\n obj = array(self.num23seq,dtype=t.dtype)\n assert obj.dtype==t.dtype\n assert obj.dtype is not self.type.dtype\n assert not obj.flags['FORTRAN'] and obj.flags['CONTIGUOUS']\n shape = obj.shape\n a = self.array(shape,intent.inplace,obj)\n assert obj[1][2]==a.arr[1][2],`obj,a.arr`\n a.arr[1][2]=54\n assert obj[1][2]==a.arr[1][2]==array(54,dtype=self.type.dtype),`obj,a.arr`\n assert a.arr is obj\n assert obj.flags['FORTRAN'] # obj attributes are changed inplace!\n assert not obj.flags['CONTIGUOUS']\n assert obj.dtype is self.type.dtype # obj type is changed inplace!\n\nfor t in Type._type_names:\n exec '''\\\nclass test_%s_gen(unittest.TestCase,\n _test_shared_memory\n ):\n type = Type(%r)\n array = lambda self,dims,intent,obj: Array(Type(%r),dims,intent,obj)\n''' % (t,t,t)\n\nif __name__ == \"__main__\":\n ScipyTest().run()\n", "source_code_before": "import unittest\nimport sys\nimport copy\n\nfrom scipy.test.testing import *\nfrom scipy.base import array, typeinfo, alltrue, ndarray, asarray, can_cast,zeros\nset_package_path()\nfrom array_from_pyobj import wrap\ndel sys.path[0]\n\ndef flags_info(arr):\n flags = wrap.array_attrs(arr)[6]\n return flags2names(flags)\n\ndef flags2names(flags):\n info = []\n for flagname in ['CONTIGUOUS','FORTRAN','OWNDATA','ENSURECOPY',\n 'ENSUREARRAY','ALIGNED','NOTSWAPPED','WRITEABLE',\n 'UPDATEIFCOPY','BEHAVED_FLAGS','BEHAVED_FLAGS_RO',\n 'CARRAY_FLAGS','FARRAY_FLAGS'\n ]:\n if abs(flags) & getattr(wrap,flagname):\n info.append(flagname)\n return info\n\nclass Intent:\n def __init__(self,intent_list=[]):\n self.intent_list = intent_list[:]\n flags = 0\n for i in intent_list:\n if i=='optional':\n flags |= wrap.F2PY_OPTIONAL\n else:\n flags |= getattr(wrap,'F2PY_INTENT_'+i.upper())\n self.flags = flags\n def __getattr__(self,name):\n name = name.lower()\n if name=='in_': name='in'\n return self.__class__(self.intent_list+[name])\n def __str__(self):\n return 'intent(%s)' % (','.join(self.intent_list))\n def __repr__(self):\n return 'Intent(%r)' % (self.intent_list)\n def is_intent(self,*names):\n for name in names:\n if name not in self.intent_list:\n return False\n return True\n def is_intent_exact(self,*names):\n return len(self.intent_list)==len(names) and self.is_intent(*names)\n\nintent = Intent()\n\nclass Type(object):\n\n _type_names = ['BOOL','BYTE','UBYTE','SHORT','USHORT','INT','UINT',\n 'LONG','ULONG','LONGLONG','ULONGLONG',\n 'FLOAT','DOUBLE','LONGDOUBLE','CFLOAT','CDOUBLE',\n 'CLONGDOUBLE']\n _type_cache = {}\n\n _cast_dict = {'BOOL':['BOOL']}\n _cast_dict['BYTE'] = _cast_dict['BOOL'] + ['BYTE']\n _cast_dict['UBYTE'] = _cast_dict['BOOL'] + ['UBYTE']\n _cast_dict['BYTE'] = ['BYTE']\n _cast_dict['UBYTE'] = ['UBYTE']\n _cast_dict['SHORT'] = _cast_dict['BYTE'] + ['UBYTE','SHORT']\n _cast_dict['USHORT'] = _cast_dict['UBYTE'] + ['BYTE','USHORT']\n _cast_dict['INT'] = _cast_dict['SHORT'] + ['USHORT','INT']\n _cast_dict['UINT'] = _cast_dict['USHORT'] + ['SHORT','UINT']\n\n _cast_dict['LONG'] = _cast_dict['INT'] + ['LONG']\n _cast_dict['ULONG'] = _cast_dict['UINT'] + ['ULONG']\n\n _cast_dict['LONGLONG'] = _cast_dict['LONG'] + ['ULONG','LONGLONG']\n _cast_dict['ULONGLONG'] = _cast_dict['ULONG'] + ['LONG','ULONGLONG']\n\n _cast_dict['FLOAT'] = _cast_dict['SHORT'] + ['USHORT','FLOAT']\n _cast_dict['DOUBLE'] = _cast_dict['INT'] + ['UINT','FLOAT','DOUBLE']\n _cast_dict['LONGDOUBLE'] = _cast_dict['LONG'] + ['ULONG','FLOAT','DOUBLE','LONGDOUBLE']\n\n _cast_dict['CFLOAT'] = _cast_dict['FLOAT'] + ['CFLOAT']\n _cast_dict['CDOUBLE'] = _cast_dict['DOUBLE'] + ['CFLOAT','CDOUBLE']\n _cast_dict['CLONGDOUBLE'] = _cast_dict['LONGDOUBLE'] + ['CFLOAT','CDOUBLE','CLONGDOUBLE']\n \n \n def __new__(cls,name):\n if isinstance(name,type):\n dtype = name\n name = None\n for n,i in typeinfo.items():\n if isinstance(i,tuple) and dtype is i[-1]:\n name = n\n break\n obj = cls._type_cache.get(name.upper(),None)\n if obj is not None:\n return obj\n obj = object.__new__(cls)\n obj._init(name)\n cls._type_cache[name.upper()] = obj\n return obj\n \n def _init(self,name):\n self.NAME = name.upper()\n self.type_num = getattr(wrap,'PyArray_'+self.NAME)\n assert_equal(self.type_num,typeinfo[self.NAME][1])\n self.dtype = typeinfo[self.NAME][-1]\n self.elsize = typeinfo[self.NAME][2] / 8\n self.dtypechar = typeinfo[self.NAME][0]\n\n def cast_types(self):\n return map(self.__class__,self._cast_dict[self.NAME])\n\n def all_types(self):\n return map(self.__class__,self._type_names)\n\n def smaller_types(self):\n bits = typeinfo[self.NAME][3]\n types = []\n for name in self._type_names:\n if typeinfo[name][3]bits:\n types.append(Type(name))\n return types\n\nclass Array:\n def __init__(self,typ,dims,intent,obj):\n self.type = typ\n self.dims = dims\n self.intent = intent\n self.obj_copy = copy.deepcopy(obj)\n self.obj = obj\n\n # arr.dtypechar may be different from typ.dtypechar\n self.arr = wrap.call(typ.type_num,dims,intent.flags,obj)\n\n self.arr_attr = wrap.array_attrs(self.arr)\n\n if len(dims)>1:\n if self.intent.is_intent('c'):\n assert intent.flags & wrap.F2PY_INTENT_C\n assert not self.arr.flags['FORTRAN'],`self.arr.flags,obj.flags`\n assert self.arr.flags['CONTIGUOUS']\n assert not self.arr_attr[6] & wrap.FORTRAN\n else:\n assert not intent.flags & wrap.F2PY_INTENT_C\n assert self.arr.flags['FORTRAN']\n assert not self.arr.flags['CONTIGUOUS']\n assert self.arr_attr[6] & wrap.FORTRAN\n\n if obj is None:\n self.pyarr = None\n self.pyarr_attr = None\n return\n\n if intent.is_intent('cache'):\n assert isinstance(obj,ndarray),`type(obj)`\n self.pyarr = array(obj).reshape(*dims)\n \n else:\n self.pyarr = array(array(obj,\n dtype = typ.dtypechar).reshape(*dims),\n fortran=not self.intent.is_intent('c'))\n assert self.pyarr.dtypechar==typ.dtypechar,\\\n `self.pyarr.dtypechar,typ.dtypechar`\n assert self.pyarr.flags['OWNDATA']\n self.pyarr_attr = wrap.array_attrs(self.pyarr)\n\n if len(dims)>1:\n if self.intent.is_intent('c'):\n assert not self.pyarr.flags['FORTRAN']\n assert self.pyarr.flags['CONTIGUOUS']\n assert not self.pyarr_attr[6] & wrap.FORTRAN\n else:\n assert self.pyarr.flags['FORTRAN']\n assert not self.pyarr.flags['CONTIGUOUS']\n assert self.pyarr_attr[6] & wrap.FORTRAN\n\n\n assert self.arr_attr[1]==self.pyarr_attr[1] # nd\n assert self.arr_attr[2]==self.pyarr_attr[2] # dimensions\n if self.arr_attr[1]<=1:\n assert self.arr_attr[3]==self.pyarr_attr[3],\\\n `self.arr_attr[3],self.pyarr_attr[3],self.arr.tostring(),self.pyarr.tostring()` # strides\n assert self.arr_attr[5][-2:]==self.pyarr_attr[5][-2:],\\\n `self.arr_attr[5],self.pyarr_attr[5]` # descr\n assert self.arr_attr[6]==self.pyarr_attr[6],\\\n `self.arr_attr[6],self.pyarr_attr[6],flags2names(0*self.arr_attr[6]-self.pyarr_attr[6]),flags2names(self.arr_attr[6]),intent` # flags\n\n if intent.is_intent('cache'):\n assert self.arr_attr[5][3]>=self.type.elsize,\\\n `self.arr_attr[5][3],self.type.elsize`\n else:\n assert self.arr_attr[5][3]==self.type.elsize,\\\n `self.arr_attr[5][3],self.type.elsize`\n assert self.arr_equal(self.pyarr,self.arr)\n \n if isinstance(self.obj,ndarray):\n if typ.elsize==Type(obj.dtype).elsize:\n if not intent.is_intent('copy') and self.arr_attr[1]<=1:\n assert self.has_shared_memory()\n\n def arr_equal(self,arr1,arr2):\n if arr1.shape != arr2.shape:\n return False\n return alltrue(arr1==arr2)\n\n def __str__(self):\n return str(self.arr)\n\n def has_shared_memory(self):\n \"\"\"Check that created array shares data with input array.\n \"\"\"\n if self.obj is self.arr:\n return True\n if not isinstance(self.obj,ndarray):\n return False\n obj_attr = wrap.array_attrs(self.obj)\n return obj_attr[0]==self.arr_attr[0]\n\n##################################################\n\nclass test_intent(unittest.TestCase):\n def check_in_out(self):\n assert_equal(str(intent.in_.out),'intent(in,out)')\n assert intent.in_.c.is_intent('c')\n assert not intent.in_.c.is_intent_exact('c')\n assert intent.in_.c.is_intent_exact('c','in')\n assert intent.in_.c.is_intent_exact('in','c')\n assert not intent.in_.is_intent('c')\n\nclass _test_shared_memory:\n num2seq = [1,2]\n num23seq = [[1,2,3],[4,5,6]]\n def check_in_from_2seq(self):\n a = self.array([2],intent.in_,self.num2seq)\n assert not a.has_shared_memory()\n\n def check_in_from_2casttype(self):\n for t in self.type.cast_types():\n obj = array(self.num2seq,dtype=t.dtype)\n a = self.array([len(self.num2seq)],intent.in_,obj)\n if t.elsize==self.type.elsize:\n assert a.has_shared_memory(),`self.type.dtype,t.dtype`\n else:\n assert not a.has_shared_memory(),`t.dtype`\n\n def check_inout_2seq(self):\n obj = array(self.num2seq,dtype=self.type.dtype)\n a = self.array([len(self.num2seq)],intent.inout,obj)\n assert a.has_shared_memory()\n\n try:\n a = self.array([2],intent.in_.inout,self.num2seq)\n except TypeError,msg:\n if not str(msg).startswith('failed to initialize intent(inout|inplace|cache) array'):\n raise\n else:\n raise SystemError,'intent(inout) should have failed on sequence'\n\n def check_f_inout_23seq(self):\n obj = array(self.num23seq,dtype=self.type.dtype,fortran=1)\n shape = (len(self.num23seq),len(self.num23seq[0]))\n a = self.array(shape,intent.in_.inout,obj)\n assert a.has_shared_memory()\n\n obj = array(self.num23seq,dtype=self.type.dtype,fortran=0)\n shape = (len(self.num23seq),len(self.num23seq[0]))\n try:\n a = self.array(shape,intent.in_.inout,obj)\n except ValueError,msg:\n if not str(msg).startswith('failed to initialize intent(inout) array'):\n raise\n else:\n raise SystemError,'intent(inout) should have failed on improper array'\n\n def check_c_inout_23seq(self):\n obj = array(self.num23seq,dtype=self.type.dtype)\n shape = (len(self.num23seq),len(self.num23seq[0]))\n a = self.array(shape,intent.in_.c.inout,obj)\n assert a.has_shared_memory()\n\n def check_in_copy_from_2casttype(self):\n for t in self.type.cast_types():\n obj = array(self.num2seq,dtype=t.dtype)\n a = self.array([len(self.num2seq)],intent.in_.copy,obj)\n assert not a.has_shared_memory(),`t.dtype`\n\n def check_c_in_from_23seq(self):\n a = self.array([len(self.num23seq),len(self.num23seq[0])],\n intent.in_,self.num23seq)\n assert not a.has_shared_memory()\n\n def check_in_from_23casttype(self):\n for t in self.type.cast_types():\n obj = array(self.num23seq,dtype=t.dtype)\n a = self.array([len(self.num23seq),len(self.num23seq[0])],\n intent.in_,obj)\n assert not a.has_shared_memory(),`t.dtype`\n\n def check_f_in_from_23casttype(self):\n for t in self.type.cast_types():\n obj = array(self.num23seq,dtype=t.dtype,fortran=1)\n a = self.array([len(self.num23seq),len(self.num23seq[0])],\n intent.in_,obj)\n if t.elsize==self.type.elsize:\n assert a.has_shared_memory(),`t.dtype`\n else:\n assert not a.has_shared_memory(),`t.dtype`\n\n def check_c_in_from_23casttype(self):\n for t in self.type.cast_types():\n obj = array(self.num23seq,dtype=t.dtype)\n a = self.array([len(self.num23seq),len(self.num23seq[0])],\n intent.in_.c,obj)\n if t.elsize==self.type.elsize:\n assert a.has_shared_memory(),`t.dtype`\n else:\n assert not a.has_shared_memory(),`t.dtype`\n\n def check_f_copy_in_from_23casttype(self):\n for t in self.type.cast_types():\n obj = array(self.num23seq,dtype=t.dtype,fortran=1)\n a = self.array([len(self.num23seq),len(self.num23seq[0])],\n intent.in_.copy,obj)\n assert not a.has_shared_memory(),`t.dtype`\n\n def check_c_copy_in_from_23casttype(self):\n for t in self.type.cast_types():\n obj = array(self.num23seq,dtype=t.dtype)\n a = self.array([len(self.num23seq),len(self.num23seq[0])],\n intent.in_.c.copy,obj)\n assert not a.has_shared_memory(),`t.dtype`\n\n def check_in_cache_from_2casttype(self):\n for t in self.type.all_types():\n if t.elsize != self.type.elsize:\n continue\n obj = array(self.num2seq,dtype=t.dtype)\n shape = (len(self.num2seq),)\n a = self.array(shape,intent.in_.c.cache,obj) \n assert a.has_shared_memory(),`t.dtype`\n\n a = self.array(shape,intent.in_.cache,obj) \n assert a.has_shared_memory(),`t.dtype`\n \n obj = array(self.num2seq,dtype=t.dtype,fortran=1)\n a = self.array(shape,intent.in_.c.cache,obj) \n assert a.has_shared_memory(),`t.dtype`\n\n a = self.array(shape,intent.in_.cache,obj)\n assert a.has_shared_memory(),`t.dtype`\n\n try:\n a = self.array(shape,intent.in_.cache,obj[::-1])\n except ValueError,msg:\n if not str(msg).startswith('failed to initialize intent(cache) array'):\n raise\n else:\n raise SystemError,'intent(cache) should have failed on multisegmented array'\n def check_in_cache_from_2casttype_failure(self):\n for t in self.type.all_types():\n if t.elsize >= self.type.elsize:\n continue\n obj = array(self.num2seq,dtype=t.dtype)\n shape = (len(self.num2seq),)\n try:\n a = self.array(shape,intent.in_.cache,obj)\n except ValueError,msg:\n if not str(msg).startswith('failed to initialize intent(cache) array'):\n raise\n else:\n raise SystemError,'intent(cache) should have failed on smaller array'\n\n def check_cache_hidden(self):\n shape = (2,)\n a = self.array(shape,intent.cache.hide,None)\n assert a.arr.shape==shape\n\n shape = (2,3)\n a = self.array(shape,intent.cache.hide,None)\n assert a.arr.shape==shape\n\n shape = (-1,3)\n try:\n a = self.array(shape,intent.cache.hide,None)\n except ValueError,msg:\n if not str(msg).startswith('failed to create intent(cache|hide)|optional array'):\n raise\n else:\n raise SystemError,'intent(cache) should have failed on undefined dimensions'\n\n def check_hidden(self):\n shape = (2,)\n a = self.array(shape,intent.hide,None)\n assert a.arr.shape==shape\n assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))\n\n shape = (2,3)\n a = self.array(shape,intent.hide,None)\n assert a.arr.shape==shape\n assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))\n assert a.arr.flags['FORTRAN'] and not a.arr.flags['CONTIGUOUS']\n\n shape = (2,3)\n a = self.array(shape,intent.c.hide,None)\n assert a.arr.shape==shape\n assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))\n assert not a.arr.flags['FORTRAN'] and a.arr.flags['CONTIGUOUS']\n\n shape = (-1,3)\n try:\n a = self.array(shape,intent.hide,None)\n except ValueError,msg:\n if not str(msg).startswith('failed to create intent(cache|hide)|optional array'):\n raise\n else:\n raise SystemError,'intent(hide) should have failed on undefined dimensions'\n\n def check_optional_none(self):\n shape = (2,)\n a = self.array(shape,intent.optional,None)\n assert a.arr.shape==shape\n assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))\n\n shape = (2,3)\n a = self.array(shape,intent.optional,None)\n assert a.arr.shape==shape\n assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))\n assert a.arr.flags['FORTRAN'] and not a.arr.flags['CONTIGUOUS']\n\n shape = (2,3)\n a = self.array(shape,intent.c.optional,None)\n assert a.arr.shape==shape\n assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))\n assert not a.arr.flags['FORTRAN'] and a.arr.flags['CONTIGUOUS']\n\n def check_optional_from_2seq(self):\n obj = self.num2seq\n shape = (len(obj),)\n a = self.array(shape,intent.optional,obj)\n assert a.arr.shape==shape\n assert not a.has_shared_memory()\n\n def check_optional_from_23seq(self):\n obj = self.num23seq\n shape = (len(obj),len(obj[0]))\n a = self.array(shape,intent.optional,obj)\n assert a.arr.shape==shape\n assert not a.has_shared_memory()\n\n a = self.array(shape,intent.optional.c,obj)\n assert a.arr.shape==shape\n assert not a.has_shared_memory()\n\n def check_inplace(self):\n obj = array(self.num23seq,dtype=self.type.dtype)\n assert not obj.flags['FORTRAN'] and obj.flags['CONTIGUOUS']\n shape = obj.shape\n a = self.array(shape,intent.inplace,obj)\n assert obj[1][2]==a.arr[1][2],`obj,a.arr`\n a.arr[1][2]=54\n assert obj[1][2]==a.arr[1][2]==array(54,dtype=self.type.dtype),`obj,a.arr`\n assert a.arr is obj\n assert obj.flags['FORTRAN'] # obj attributes are changed inplace!\n assert not obj.flags['CONTIGUOUS']\n\n def check_inplace_from_casttype(self):\n for t in self.type.cast_types():\n if t is self.type:\n continue\n obj = array(self.num23seq,dtype=t.dtype)\n assert obj.dtype==t.dtype\n assert obj.dtype is not self.type.dtype\n assert not obj.flags['FORTRAN'] and obj.flags['CONTIGUOUS']\n shape = obj.shape\n a = self.array(shape,intent.inplace,obj)\n assert obj[1][2]==a.arr[1][2],`obj,a.arr`\n a.arr[1][2]=54\n assert obj[1][2]==a.arr[1][2]==array(54,dtype=self.type.dtype),`obj,a.arr`\n assert a.arr is obj\n assert obj.flags['FORTRAN'] # obj attributes are changed inplace!\n assert not obj.flags['CONTIGUOUS']\n assert obj.dtype is self.type.dtype # obj type is changed inplace!\n\nfor t in Type._type_names:\n exec '''\\\nclass test_%s_gen(unittest.TestCase,\n _test_shared_memory\n ):\n type = Type(%r)\n array = lambda self,dims,intent,obj: Array(Type(%r),dims,intent,obj)\n''' % (t,t,t)\n\nif __name__ == \"__main__\":\n ScipyTest().run()\n", "methods": [ { "name": "flags_info", "long_name": "flags_info( arr )", "filename": "test_array_from_pyobj.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "arr" ], "start_line": 11, "end_line": 13, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "flags2names", "long_name": "flags2names( flags )", "filename": "test_array_from_pyobj.py", "nloc": 10, "complexity": 3, "token_count": 61, "parameters": [ "flags" ], "start_line": 15, "end_line": 24, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , intent_list = [ ] )", "filename": "test_array_from_pyobj.py", "nloc": 9, "complexity": 3, "token_count": 57, "parameters": [ "self", "intent_list" ], "start_line": 27, "end_line": 35, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "test_array_from_pyobj.py", "nloc": 4, "complexity": 2, "token_count": 35, "parameters": [ "self", "name" ], "start_line": 36, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "test_array_from_pyobj.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 40, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "test_array_from_pyobj.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 42, "end_line": 43, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "is_intent", "long_name": "is_intent( self , * names )", "filename": "test_array_from_pyobj.py", "nloc": 5, "complexity": 3, "token_count": 25, "parameters": [ "self", "names" ], "start_line": 44, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "is_intent_exact", "long_name": "is_intent_exact( self , * names )", "filename": "test_array_from_pyobj.py", "nloc": 2, "complexity": 2, "token_count": 28, "parameters": [ "self", "names" ], "start_line": 49, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__new__", "long_name": "__new__( cls , name )", "filename": "test_array_from_pyobj.py", "nloc": 15, "complexity": 6, "token_count": 104, "parameters": [ "cls", "name" ], "start_line": 87, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "_init", "long_name": "_init( self , name )", "filename": "test_array_from_pyobj.py", "nloc": 7, "complexity": 1, "token_count": 88, "parameters": [ "self", "name" ], "start_line": 103, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "cast_types", "long_name": "cast_types( self )", "filename": "test_array_from_pyobj.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 111, "end_line": 112, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "all_types", "long_name": "all_types( self )", "filename": "test_array_from_pyobj.py", "nloc": 2, "complexity": 1, "token_count": 16, "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": "smaller_types", "long_name": "smaller_types( self )", "filename": "test_array_from_pyobj.py", "nloc": 7, "complexity": 3, "token_count": 49, "parameters": [ "self" ], "start_line": 117, "end_line": 123, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "equal_types", "long_name": "equal_types( self )", "filename": "test_array_from_pyobj.py", "nloc": 8, "complexity": 4, "token_count": 57, "parameters": [ "self" ], "start_line": 125, "end_line": 132, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "larger_types", "long_name": "larger_types( self )", "filename": "test_array_from_pyobj.py", "nloc": 7, "complexity": 3, "token_count": 49, "parameters": [ "self" ], "start_line": 134, "end_line": 140, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , typ , dims , intent , obj )", "filename": "test_array_from_pyobj.py", "nloc": 63, "complexity": 13, "token_count": 728, "parameters": [ "self", "typ", "dims", "intent", "obj" ], "start_line": 143, "end_line": 217, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 1 }, { "name": "arr_equal", "long_name": "arr_equal( self , arr1 , arr2 )", "filename": "test_array_from_pyobj.py", "nloc": 4, "complexity": 2, "token_count": 27, "parameters": [ "self", "arr1", "arr2" ], "start_line": 219, "end_line": 222, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "test_array_from_pyobj.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 224, "end_line": 225, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "has_shared_memory", "long_name": "has_shared_memory( self )", "filename": "test_array_from_pyobj.py", "nloc": 7, "complexity": 3, "token_count": 52, "parameters": [ "self" ], "start_line": 227, "end_line": 235, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_in_out", "long_name": "check_in_out( self )", "filename": "test_array_from_pyobj.py", "nloc": 7, "complexity": 1, "token_count": 77, "parameters": [ "self" ], "start_line": 240, "end_line": 246, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_in_from_2seq", "long_name": "check_in_from_2seq( self )", "filename": "test_array_from_pyobj.py", "nloc": 3, "complexity": 1, "token_count": 30, "parameters": [ "self" ], "start_line": 251, "end_line": 253, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_in_from_2casttype", "long_name": "check_in_from_2casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 8, "complexity": 3, "token_count": 95, "parameters": [ "self" ], "start_line": 255, "end_line": 262, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_inout_2seq", "long_name": "check_inout_2seq( self )", "filename": "test_array_from_pyobj.py", "nloc": 11, "complexity": 3, "token_count": 94, "parameters": [ "self" ], "start_line": 264, "end_line": 275, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "check_f_inout_23seq", "long_name": "check_f_inout_23seq( self )", "filename": "test_array_from_pyobj.py", "nloc": 14, "complexity": 3, "token_count": 149, "parameters": [ "self" ], "start_line": 277, "end_line": 291, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "check_c_inout_23seq", "long_name": "check_c_inout_23seq( self )", "filename": "test_array_from_pyobj.py", "nloc": 5, "complexity": 1, "token_count": 65, "parameters": [ "self" ], "start_line": 293, "end_line": 297, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_in_copy_from_2casttype", "long_name": "check_in_copy_from_2casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 5, "complexity": 2, "token_count": 66, "parameters": [ "self" ], "start_line": 299, "end_line": 303, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_c_in_from_23seq", "long_name": "check_c_in_from_23seq( self )", "filename": "test_array_from_pyobj.py", "nloc": 4, "complexity": 1, "token_count": 45, "parameters": [ "self" ], "start_line": 305, "end_line": 308, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_in_from_23casttype", "long_name": "check_in_from_23casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 6, "complexity": 2, "token_count": 74, "parameters": [ "self" ], "start_line": 310, "end_line": 315, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_f_in_from_23casttype", "long_name": "check_f_in_from_23casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 9, "complexity": 3, "token_count": 103, "parameters": [ "self" ], "start_line": 317, "end_line": 325, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_c_in_from_23casttype", "long_name": "check_c_in_from_23casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 9, "complexity": 3, "token_count": 101, "parameters": [ "self" ], "start_line": 327, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_f_copy_in_from_23casttype", "long_name": "check_f_copy_in_from_23casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 6, "complexity": 2, "token_count": 80, "parameters": [ "self" ], "start_line": 337, "end_line": 342, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_c_copy_in_from_23casttype", "long_name": "check_c_copy_in_from_23casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 6, "complexity": 2, "token_count": 78, "parameters": [ "self" ], "start_line": 344, "end_line": 349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_in_cache_from_2casttype", "long_name": "check_in_cache_from_2casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 22, "complexity": 5, "token_count": 234, "parameters": [ "self" ], "start_line": 351, "end_line": 376, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "check_in_cache_from_2casttype_failure", "long_name": "check_in_cache_from_2casttype_failure( self )", "filename": "test_array_from_pyobj.py", "nloc": 13, "complexity": 5, "token_count": 95, "parameters": [ "self" ], "start_line": 377, "end_line": 389, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "check_cache_hidden", "long_name": "check_cache_hidden( self )", "filename": "test_array_from_pyobj.py", "nloc": 15, "complexity": 3, "token_count": 116, "parameters": [ "self" ], "start_line": 391, "end_line": 407, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "check_hidden", "long_name": "check_hidden( self )", "filename": "test_array_from_pyobj.py", "nloc": 23, "complexity": 5, "token_count": 245, "parameters": [ "self" ], "start_line": 409, "end_line": 434, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "check_optional_none", "long_name": "check_optional_none( self )", "filename": "test_array_from_pyobj.py", "nloc": 15, "complexity": 3, "token_count": 197, "parameters": [ "self" ], "start_line": 436, "end_line": 452, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "check_optional_from_2seq", "long_name": "check_optional_from_2seq( self )", "filename": "test_array_from_pyobj.py", "nloc": 6, "complexity": 1, "token_count": 48, "parameters": [ "self" ], "start_line": 454, "end_line": 459, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_optional_from_23seq", "long_name": "check_optional_from_23seq( self )", "filename": "test_array_from_pyobj.py", "nloc": 9, "complexity": 1, "token_count": 86, "parameters": [ "self" ], "start_line": 461, "end_line": 470, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "check_inplace", "long_name": "check_inplace( self )", "filename": "test_array_from_pyobj.py", "nloc": 11, "complexity": 2, "token_count": 152, "parameters": [ "self" ], "start_line": 472, "end_line": 482, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "check_inplace_from_casttype", "long_name": "check_inplace_from_casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 17, "complexity": 4, "token_count": 198, "parameters": [ "self" ], "start_line": 484, "end_line": 500, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 } ], "methods_before": [ { "name": "flags_info", "long_name": "flags_info( arr )", "filename": "test_array_from_pyobj.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "arr" ], "start_line": 11, "end_line": 13, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "flags2names", "long_name": "flags2names( flags )", "filename": "test_array_from_pyobj.py", "nloc": 10, "complexity": 3, "token_count": 61, "parameters": [ "flags" ], "start_line": 15, "end_line": 24, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , intent_list = [ ] )", "filename": "test_array_from_pyobj.py", "nloc": 9, "complexity": 3, "token_count": 57, "parameters": [ "self", "intent_list" ], "start_line": 27, "end_line": 35, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "test_array_from_pyobj.py", "nloc": 4, "complexity": 2, "token_count": 35, "parameters": [ "self", "name" ], "start_line": 36, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "test_array_from_pyobj.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 40, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "test_array_from_pyobj.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 42, "end_line": 43, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "is_intent", "long_name": "is_intent( self , * names )", "filename": "test_array_from_pyobj.py", "nloc": 5, "complexity": 3, "token_count": 25, "parameters": [ "self", "names" ], "start_line": 44, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "is_intent_exact", "long_name": "is_intent_exact( self , * names )", "filename": "test_array_from_pyobj.py", "nloc": 2, "complexity": 2, "token_count": 28, "parameters": [ "self", "names" ], "start_line": 49, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__new__", "long_name": "__new__( cls , name )", "filename": "test_array_from_pyobj.py", "nloc": 15, "complexity": 6, "token_count": 104, "parameters": [ "cls", "name" ], "start_line": 87, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "_init", "long_name": "_init( self , name )", "filename": "test_array_from_pyobj.py", "nloc": 7, "complexity": 1, "token_count": 88, "parameters": [ "self", "name" ], "start_line": 103, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "cast_types", "long_name": "cast_types( self )", "filename": "test_array_from_pyobj.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 111, "end_line": 112, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "all_types", "long_name": "all_types( self )", "filename": "test_array_from_pyobj.py", "nloc": 2, "complexity": 1, "token_count": 16, "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": "smaller_types", "long_name": "smaller_types( self )", "filename": "test_array_from_pyobj.py", "nloc": 7, "complexity": 3, "token_count": 49, "parameters": [ "self" ], "start_line": 117, "end_line": 123, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "equal_types", "long_name": "equal_types( self )", "filename": "test_array_from_pyobj.py", "nloc": 8, "complexity": 4, "token_count": 57, "parameters": [ "self" ], "start_line": 125, "end_line": 132, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "larger_types", "long_name": "larger_types( self )", "filename": "test_array_from_pyobj.py", "nloc": 7, "complexity": 3, "token_count": 49, "parameters": [ "self" ], "start_line": 134, "end_line": 140, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , typ , dims , intent , obj )", "filename": "test_array_from_pyobj.py", "nloc": 63, "complexity": 13, "token_count": 728, "parameters": [ "self", "typ", "dims", "intent", "obj" ], "start_line": 143, "end_line": 217, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 1 }, { "name": "arr_equal", "long_name": "arr_equal( self , arr1 , arr2 )", "filename": "test_array_from_pyobj.py", "nloc": 4, "complexity": 2, "token_count": 27, "parameters": [ "self", "arr1", "arr2" ], "start_line": 219, "end_line": 222, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "test_array_from_pyobj.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 224, "end_line": 225, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "has_shared_memory", "long_name": "has_shared_memory( self )", "filename": "test_array_from_pyobj.py", "nloc": 7, "complexity": 3, "token_count": 52, "parameters": [ "self" ], "start_line": 227, "end_line": 235, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_in_out", "long_name": "check_in_out( self )", "filename": "test_array_from_pyobj.py", "nloc": 7, "complexity": 1, "token_count": 77, "parameters": [ "self" ], "start_line": 240, "end_line": 246, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_in_from_2seq", "long_name": "check_in_from_2seq( self )", "filename": "test_array_from_pyobj.py", "nloc": 3, "complexity": 1, "token_count": 30, "parameters": [ "self" ], "start_line": 251, "end_line": 253, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_in_from_2casttype", "long_name": "check_in_from_2casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 8, "complexity": 3, "token_count": 95, "parameters": [ "self" ], "start_line": 255, "end_line": 262, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_inout_2seq", "long_name": "check_inout_2seq( self )", "filename": "test_array_from_pyobj.py", "nloc": 11, "complexity": 3, "token_count": 94, "parameters": [ "self" ], "start_line": 264, "end_line": 275, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "check_f_inout_23seq", "long_name": "check_f_inout_23seq( self )", "filename": "test_array_from_pyobj.py", "nloc": 14, "complexity": 3, "token_count": 149, "parameters": [ "self" ], "start_line": 277, "end_line": 291, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "check_c_inout_23seq", "long_name": "check_c_inout_23seq( self )", "filename": "test_array_from_pyobj.py", "nloc": 5, "complexity": 1, "token_count": 65, "parameters": [ "self" ], "start_line": 293, "end_line": 297, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_in_copy_from_2casttype", "long_name": "check_in_copy_from_2casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 5, "complexity": 2, "token_count": 66, "parameters": [ "self" ], "start_line": 299, "end_line": 303, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_c_in_from_23seq", "long_name": "check_c_in_from_23seq( self )", "filename": "test_array_from_pyobj.py", "nloc": 4, "complexity": 1, "token_count": 45, "parameters": [ "self" ], "start_line": 305, "end_line": 308, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_in_from_23casttype", "long_name": "check_in_from_23casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 6, "complexity": 2, "token_count": 74, "parameters": [ "self" ], "start_line": 310, "end_line": 315, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_f_in_from_23casttype", "long_name": "check_f_in_from_23casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 9, "complexity": 3, "token_count": 103, "parameters": [ "self" ], "start_line": 317, "end_line": 325, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_c_in_from_23casttype", "long_name": "check_c_in_from_23casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 9, "complexity": 3, "token_count": 101, "parameters": [ "self" ], "start_line": 327, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_f_copy_in_from_23casttype", "long_name": "check_f_copy_in_from_23casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 6, "complexity": 2, "token_count": 80, "parameters": [ "self" ], "start_line": 337, "end_line": 342, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_c_copy_in_from_23casttype", "long_name": "check_c_copy_in_from_23casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 6, "complexity": 2, "token_count": 78, "parameters": [ "self" ], "start_line": 344, "end_line": 349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_in_cache_from_2casttype", "long_name": "check_in_cache_from_2casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 22, "complexity": 5, "token_count": 234, "parameters": [ "self" ], "start_line": 351, "end_line": 376, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "check_in_cache_from_2casttype_failure", "long_name": "check_in_cache_from_2casttype_failure( self )", "filename": "test_array_from_pyobj.py", "nloc": 13, "complexity": 5, "token_count": 95, "parameters": [ "self" ], "start_line": 377, "end_line": 389, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "check_cache_hidden", "long_name": "check_cache_hidden( self )", "filename": "test_array_from_pyobj.py", "nloc": 15, "complexity": 3, "token_count": 116, "parameters": [ "self" ], "start_line": 391, "end_line": 407, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "check_hidden", "long_name": "check_hidden( self )", "filename": "test_array_from_pyobj.py", "nloc": 23, "complexity": 5, "token_count": 245, "parameters": [ "self" ], "start_line": 409, "end_line": 434, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "check_optional_none", "long_name": "check_optional_none( self )", "filename": "test_array_from_pyobj.py", "nloc": 15, "complexity": 3, "token_count": 197, "parameters": [ "self" ], "start_line": 436, "end_line": 452, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "check_optional_from_2seq", "long_name": "check_optional_from_2seq( self )", "filename": "test_array_from_pyobj.py", "nloc": 6, "complexity": 1, "token_count": 48, "parameters": [ "self" ], "start_line": 454, "end_line": 459, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_optional_from_23seq", "long_name": "check_optional_from_23seq( self )", "filename": "test_array_from_pyobj.py", "nloc": 9, "complexity": 1, "token_count": 86, "parameters": [ "self" ], "start_line": 461, "end_line": 470, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "check_inplace", "long_name": "check_inplace( self )", "filename": "test_array_from_pyobj.py", "nloc": 11, "complexity": 2, "token_count": 152, "parameters": [ "self" ], "start_line": 472, "end_line": 482, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "check_inplace_from_casttype", "long_name": "check_inplace_from_casttype( self )", "filename": "test_array_from_pyobj.py", "nloc": 17, "complexity": 4, "token_count": 198, "parameters": [ "self" ], "start_line": 484, "end_line": 500, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 } ], "changed_methods": [], "nloc": 435, "complexity": 110, "token_count": 4359, "diff_parsed": { "added": [ " _cast_dict['LONGLONG'] = _cast_dict['LONG'] + ['LONGLONG']", " _cast_dict['ULONGLONG'] = _cast_dict['ULONG'] + ['ULONGLONG']" ], "deleted": [ " _cast_dict['LONGLONG'] = _cast_dict['LONG'] + ['ULONG','LONGLONG']", " _cast_dict['ULONGLONG'] = _cast_dict['ULONG'] + ['LONG','ULONGLONG']" ] } } ] }, { "hash": "4fb4bd40b51e41aca4495a2c79dfad5b4cd9279f", "msg": "Bug fixes.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2005-10-26T22:08:31+00:00", "author_timezone": 0, "committer_date": "2005-10-26T22:08:31+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "4e917206d27330ce59e19098385477a285b85062" ], "project_name": "repo_copy", "project_path": "/tmp/tmpn4cqam_6/repo_copy", "deletions": 5, "insertions": 5, "lines": 10, "files": 1, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "scipy/base/scimath.py", "new_path": "scipy/base/scimath.py", "filename": "scimath.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -11,7 +11,7 @@\n import numeric as _nx\n from numeric import *\n \n-from type_check import isreal\n+from type_check import isreal, asscalar\n \n __all__.extend([key for key in dir(_nx.umath) \\\n if key[0]!='_' and key not in __all__])\n@@ -38,15 +38,15 @@ def _fix_real_abs_gt_1(x):\n \n def sqrt(x):\n x = _fix_real_lt_zero(x)\n- return sqrt(x)\n+ return _nx.sqrt(x)\n \n def log(x):\n x = _fix_real_lt_zero(x)\n- return log(x)\n+ return _nx.log(x)\n \n def log10(x):\n x = _fix_real_lt_zero(x)\n- return log10(x) \n+ return _nx.log10(x)\n \n def logn(n,x):\n \"\"\" Take log base n of x.\n@@ -63,7 +63,7 @@ def log2(x):\n \n def power(x, p):\n x = _fix_real_lt_zero(x)\n- return power(x, p)\n+ return _nx.power(x, p)\n \n \n def arccos(x):\n", "added_lines": 5, "deleted_lines": 5, "source_code": "## Automatically adapted for scipy Sep 19, 2005 by convertcode.py\n\n\"\"\"\nWrapper functions to more user-friendly calling of certain math functions\nwhose output is different than the input in certain domains of the input.\n\"\"\"\n\n__all__ = ['sqrt', 'log', 'log2','logn','log10', 'power', 'arccos',\n 'arcsin', 'arctanh']\n\nimport numeric as _nx\nfrom numeric import *\n\nfrom type_check import isreal, asscalar\n\n__all__.extend([key for key in dir(_nx.umath) \\\n if key[0]!='_' and key not in __all__])\n\n_ln2 = log(2.0)\n\ndef _tocomplex(arr):\n if arr.dtypechar in ['f', 'h', 'B', 'b','H']:\n return arr.astype('F')\n else:\n return arr.astype('D')\n\ndef _fix_real_lt_zero(x):\n x = asarray(x)\n if any(isreal(x) & (x<0)):\n x = _tocomplex(x)\n return asscalar(x)\n\ndef _fix_real_abs_gt_1(x):\n x = asarray(x)\n if any(isreal(x) & (abs(x)>1)):\n x = _tocomplex(x)\n return x\n \ndef sqrt(x):\n x = _fix_real_lt_zero(x)\n return _nx.sqrt(x)\n\ndef log(x):\n x = _fix_real_lt_zero(x)\n return _nx.log(x)\n\ndef log10(x):\n x = _fix_real_lt_zero(x)\n return _nx.log10(x)\n\ndef logn(n,x):\n \"\"\" Take log base n of x.\n \"\"\"\n x = _fix_real_lt_zero(x)\n n = _fix_real_lt_zero(n)\n return log(x)/log(n)\n\ndef log2(x):\n \"\"\" Take log base 2 of x.\n \"\"\"\n x = _fix_real_lt_zero(x)\n return log(x)/_ln2\n\ndef power(x, p):\n x = _fix_real_lt_zero(x)\n return _nx.power(x, p)\n\n\ndef arccos(x):\n x = _fix_real_abs_gt_1(x)\n return arccos(x)\n\ndef arcsin(x):\n x = _fix_real_abs_gt_1(x)\n return arcsin(x)\n\ndef arctanh(x):\n x = _fix_real_abs_gt_1(x)\n return arctanh(x)\n", "source_code_before": "## Automatically adapted for scipy Sep 19, 2005 by convertcode.py\n\n\"\"\"\nWrapper functions to more user-friendly calling of certain math functions\nwhose output is different than the input in certain domains of the input.\n\"\"\"\n\n__all__ = ['sqrt', 'log', 'log2','logn','log10', 'power', 'arccos',\n 'arcsin', 'arctanh']\n\nimport numeric as _nx\nfrom numeric import *\n\nfrom type_check import isreal\n\n__all__.extend([key for key in dir(_nx.umath) \\\n if key[0]!='_' and key not in __all__])\n\n_ln2 = log(2.0)\n\ndef _tocomplex(arr):\n if arr.dtypechar in ['f', 'h', 'B', 'b','H']:\n return arr.astype('F')\n else:\n return arr.astype('D')\n\ndef _fix_real_lt_zero(x):\n x = asarray(x)\n if any(isreal(x) & (x<0)):\n x = _tocomplex(x)\n return asscalar(x)\n\ndef _fix_real_abs_gt_1(x):\n x = asarray(x)\n if any(isreal(x) & (abs(x)>1)):\n x = _tocomplex(x)\n return x\n \ndef sqrt(x):\n x = _fix_real_lt_zero(x)\n return sqrt(x)\n\ndef log(x):\n x = _fix_real_lt_zero(x)\n return log(x)\n\ndef log10(x):\n x = _fix_real_lt_zero(x)\n return log10(x) \n\ndef logn(n,x):\n \"\"\" Take log base n of x.\n \"\"\"\n x = _fix_real_lt_zero(x)\n n = _fix_real_lt_zero(n)\n return log(x)/log(n)\n\ndef log2(x):\n \"\"\" Take log base 2 of x.\n \"\"\"\n x = _fix_real_lt_zero(x)\n return log(x)/_ln2\n\ndef power(x, p):\n x = _fix_real_lt_zero(x)\n return power(x, p)\n\n\ndef arccos(x):\n x = _fix_real_abs_gt_1(x)\n return arccos(x)\n\ndef arcsin(x):\n x = _fix_real_abs_gt_1(x)\n return arcsin(x)\n\ndef arctanh(x):\n x = _fix_real_abs_gt_1(x)\n return arctanh(x)\n", "methods": [ { "name": "_tocomplex", "long_name": "_tocomplex( arr )", "filename": "scimath.py", "nloc": 5, "complexity": 2, "token_count": 38, "parameters": [ "arr" ], "start_line": 21, "end_line": 25, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "_fix_real_lt_zero", "long_name": "_fix_real_lt_zero( x )", "filename": "scimath.py", "nloc": 5, "complexity": 2, "token_count": 37, "parameters": [ "x" ], "start_line": 27, "end_line": 31, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "_fix_real_abs_gt_1", "long_name": "_fix_real_abs_gt_1( x )", "filename": "scimath.py", "nloc": 5, "complexity": 2, "token_count": 37, "parameters": [ "x" ], "start_line": 33, "end_line": 37, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "sqrt", "long_name": "sqrt( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "x" ], "start_line": 39, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "log", "long_name": "log( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "x" ], "start_line": 43, "end_line": 45, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "log10", "long_name": "log10( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "x" ], "start_line": 47, "end_line": 49, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "logn", "long_name": "logn( n , x )", "filename": "scimath.py", "nloc": 4, "complexity": 1, "token_count": 30, "parameters": [ "n", "x" ], "start_line": 51, "end_line": 56, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "log2", "long_name": "log2( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 19, "parameters": [ "x" ], "start_line": 58, "end_line": 62, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "power", "long_name": "power( x , p )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "x", "p" ], "start_line": 64, "end_line": 66, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "arccos", "long_name": "arccos( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 16, "parameters": [ "x" ], "start_line": 69, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "arcsin", "long_name": "arcsin( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 16, "parameters": [ "x" ], "start_line": 73, "end_line": 75, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "arctanh", "long_name": "arctanh( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 16, "parameters": [ "x" ], "start_line": 77, "end_line": 79, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "_tocomplex", "long_name": "_tocomplex( arr )", "filename": "scimath.py", "nloc": 5, "complexity": 2, "token_count": 38, "parameters": [ "arr" ], "start_line": 21, "end_line": 25, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "_fix_real_lt_zero", "long_name": "_fix_real_lt_zero( x )", "filename": "scimath.py", "nloc": 5, "complexity": 2, "token_count": 37, "parameters": [ "x" ], "start_line": 27, "end_line": 31, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "_fix_real_abs_gt_1", "long_name": "_fix_real_abs_gt_1( x )", "filename": "scimath.py", "nloc": 5, "complexity": 2, "token_count": 37, "parameters": [ "x" ], "start_line": 33, "end_line": 37, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "sqrt", "long_name": "sqrt( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 16, "parameters": [ "x" ], "start_line": 39, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "log", "long_name": "log( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 16, "parameters": [ "x" ], "start_line": 43, "end_line": 45, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "log10", "long_name": "log10( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 16, "parameters": [ "x" ], "start_line": 47, "end_line": 49, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "logn", "long_name": "logn( n , x )", "filename": "scimath.py", "nloc": 4, "complexity": 1, "token_count": 30, "parameters": [ "n", "x" ], "start_line": 51, "end_line": 56, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "log2", "long_name": "log2( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 19, "parameters": [ "x" ], "start_line": 58, "end_line": 62, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "power", "long_name": "power( x , p )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "x", "p" ], "start_line": 64, "end_line": 66, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "arccos", "long_name": "arccos( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 16, "parameters": [ "x" ], "start_line": 69, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "arcsin", "long_name": "arcsin( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 16, "parameters": [ "x" ], "start_line": 73, "end_line": 75, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "arctanh", "long_name": "arctanh( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 16, "parameters": [ "x" ], "start_line": 77, "end_line": 79, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "power", "long_name": "power( x , p )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "x", "p" ], "start_line": 64, "end_line": 66, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "log10", "long_name": "log10( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "x" ], "start_line": 47, "end_line": 49, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "log", "long_name": "log( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "x" ], "start_line": 43, "end_line": 45, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "sqrt", "long_name": "sqrt( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "x" ], "start_line": 39, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "nloc": 55, "complexity": 15, "token_count": 371, "diff_parsed": { "added": [ "from type_check import isreal, asscalar", " return _nx.sqrt(x)", " return _nx.log(x)", " return _nx.log10(x)", " return _nx.power(x, p)" ], "deleted": [ "from type_check import isreal", " return sqrt(x)", " return log(x)", " return log10(x)", " return power(x, p)" ] } } ] }, { "hash": "64ee901f909f7fb5d8e572be318fd5ed5674fe30", "msg": "Fixed problem with temporary allocation in PyArray_Transpose.", "author": { "name": "Travis Oliphant", "email": "oliphant@enthought.com" }, "committer": { "name": "Travis Oliphant", "email": "oliphant@enthought.com" }, "author_date": "2005-10-26T22:42:43+00:00", "author_timezone": 0, "committer_date": "2005-10-26T22:42:43+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "4fb4bd40b51e41aca4495a2c79dfad5b4cd9279f" ], "project_name": "repo_copy", "project_path": "/tmp/tmpn4cqam_6/repo_copy", "deletions": 5, "insertions": 5, "lines": 10, "files": 1, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "scipy/base/src/multiarraymodule.c", "new_path": "scipy/base/src/multiarraymodule.c", "filename": "multiarraymodule.c", "extension": "c", "change_type": "MODIFY", "diff": "@@ -1174,9 +1174,9 @@ PyArray_Transpose(PyArrayObject *ap, PyObject *op) {\n \tintp *permutation = NULL;\n \tPyArrayObject *ret = NULL;\n \t\n-\tif (op == Py_None || op == NULL) {\n+\tif (op == NULL || op == Py_None) {\n \t\tn = ap->nd;\n-\t\tpermutation = (intp *)malloc(n*sizeof(int));\n+\t\tpermutation = (intp *)malloc(n*sizeof(intp));\n \t\tfor(i=0; i\n#include \n*/\n\n#define _MULTIARRAYMODULE\n#include \"scipy/arrayobject.h\"\n\n#define PyAO PyArrayObject\n\nstatic PyObject *typeDict=NULL; /* Must be explicitly loaded */\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\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\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\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\nstatic int \nPyArray_CompareLists(intp *l1, intp *l2, int n) \n{\n int i;\n for(i=0;itype_num;\n\t}\n\n\tnew = PyArray_New(self->ob_type,\n\t\t\t self->nd, self->dimensions,\n\t\t\t self->descr->type_num,\n\t\t\t self->strides,\n\t\t\t self->data,\n\t\t\t self->itemsize,\n\t\t\t self->flags, (PyObject *)self);\n\n\tif (new==NULL) return NULL;\n\t\n Py_INCREF(self);\n PyArray_BASE(new) = (PyObject *)self;\n if ((type_num != PyArray_NOTYPE) && \\\n (type_num != self->descr->type_num)) {\n if (!PyTypeNum_ISFLEXIBLE(type_num)) {\n v = PyArray_TypeObjectFromType(type_num);\n }\n else {\n PyArray_Descr *descr;\n int itemsize = type->itemsize;\n descr = PyArray_DescrFromType(type_num);\n if (type_num == PyArray_UNICODE) \n itemsize /= sizeof(Py_UNICODE);\n /* construct a string representation */\n v = PyString_FromFormat(\"%c%d\", descr->type, \n itemsize);\n }\n if (v == NULL) goto fail;\n /* set attribute new.dtype = newtype */\n if (PyObject_SetAttrString(new, \"dtype\", v) < 0) goto fail;\n Py_DECREF(v);\n }\n\treturn new;\t\n\n fail:\n Py_XDECREF(v);\n Py_XDECREF(new);\n return NULL;\n}\n\nstatic PyObject *\nPyArray_Ravel(PyArrayObject *a, int fortran)\n{\n\tPyArray_Dims newdim = {NULL,1};\n\tintp val[1] = {-1};\n\n if (a->nd == 1) {\n Py_INCREF(a);\n return (PyObject *)a;\n }\n\tnewdim.ptr = val;\n\tif (!fortran && PyArray_ISCONTIGUOUS(a)) \n\t\treturn PyArray_Newshape(a, &newdim);\n\telse\n\t return PyArray_Flatten(a, fortran);\n}\n\nstatic PyObject *\nPyArray_Flatten(PyArrayObject *a, int fortran)\n{\n\tPyObject *ret, *new;\n\tintp size;\n\n\tsize = PyArray_SIZE(a);\n\tret = PyArray_New(a->ob_type,\n\t\t\t 1, &size,\n\t\t\t a->descr->type_num,\n\t\t\t NULL,\n NULL,\n\t\t\t a->itemsize,\n\t\t\t 0, (PyObject *)a);\n\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\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\tgoto fail;\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\tgoto fail;\n\t\t\t}\n\t\t}\n\t}\n \n\tret = (PyAO *)PyArray_New(self->ob_type,\n\t\t\t\t n, dimensions,\n\t\t\t\t self->descr->type_num,\n\t\t\t\t strides,\n\t\t\t\t self->data,\n\t\t\t\t self->itemsize,\n\t\t\t\t self->flags, (PyObject *)self);\n\t\n\tif (ret== NULL)\n goto fail;\n\t\n Py_INCREF(self);\n ret->base = (PyObject *)self;\n\tPyArray_UpdateFlags(ret, CONTIGUOUS | FORTRAN);\n\t\n return (PyObject *)ret;\n\t\n fail:\n return NULL;\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\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\tret = PyArray_New(self->ob_type, newnd, dimensions, \n\t\t\t self->descr->type_num, strides,\n\t\t\t self->data, self->itemsize, self->flags,\n\t\t\t (PyObject *)self);\n\tself->flags &= ~OWN_DATA;\n\tself->base = (PyObject *)self;\n\tPy_INCREF(self);\n\treturn (PyObject *)ret;\n}\n\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\nstatic PyObject *\nPyArray_Std(PyArrayObject *self, int axis, int rtype)\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\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->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->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\tPyTuple_SET_ITEM(ret, j, item);\n\t\t\tif (item == NULL) goto fail;\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->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\treturn ret;\n\n fail:\n\tPy_XDECREF(ret);\n\tPy_XDECREF(it);\n\treturn NULL;\n \n}\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)) goto fail;\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) goto fail;\n\tret = PyArray_Choose((PyAO *)selector, newtup);\n\tPy_DECREF(selector);\n\tPy_DECREF(newtup);\n\treturn ret;\n\n fail:\n\tPy_XDECREF(res1);\n\tPy_XDECREF(res2);\n\tPy_XDECREF(two);\n\tPy_XDECREF(selector);\n\treturn NULL;\n}\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_Copy(self);\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\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\nstatic PyObject *\nPyArray_Diagonal(PyArrayObject *self, int offset, int axis1, int axis2)\n{\n\tint n = self->nd;\n\tPyObject *new;\n\tPyObject *newaxes;\n\tint i, pos;\t\n\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 = PyTuple_New(n);\n\tif (newaxes==NULL) return NULL;\n\t/* insert at the end */\n\tPyTuple_SET_ITEM(newaxes, n-2, PyInt_FromLong((long)axis1));\n\tPyTuple_SET_ITEM(newaxes, n-1, PyInt_FromLong((long)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->type_num;\n\t\ttypecode.itemsize = self->itemsize;\n\t\ttypecode.fortran = 0;\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\treturn -1;\n\t}\n\tif ((ap = (PyArrayObject*)PyArray_FromAny(*op, &typecode, nd, nd,\n\t\t\t\t\t\t CARRAY_FLAGS)) == NULL)\n\t\treturn -1;\n\tswitch(nd) {\n\tcase 1:\n\t\t*((char **)ptr) = ap->data;\n\t\tbreak;\n\tcase 2:\n\t\tn = ap->dimensions[0];\n\t\tptr2 = (char **)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 ***)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\nstatic int \nPyArray_As1D(PyObject **op, char **ptr, int *d1, int typecode) \n{\n\tintp newd1;\n\t\n\tif (PyArray_AsCArray(op, (void *)ptr, &newd1, 1, typecode) == -1)\n\t\treturn -1;\t\n\t*d1 = (int) newd1;\n\treturn 0;\n}\n\n\nstatic int \nPyArray_As2D(PyObject **op, char ***ptr, int *d1, int *d2, int typecode) \n{\n\tintp newdims[2];\n\n\tif (PyArray_AsCArray(op, (void *)ptr, newdims, 2, typecode) == -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\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\tfree(ptr);\n }\n Py_DECREF(ap);\n return 0;\n}\n\n\nstatic PyObject *\n_swap_and_concat(PyObject *op, int axis, int n)\n{\n\tPyObject *newtup=NULL;\n\tPyObject *otmp, *arr;\n\tint i;\n\n\tnewtup = PyTuple_New(n);\n\tif (newtup==NULL) return NULL;\n\tfor (i=0; i= MAX_DIMS) {\n\t\t\totmp = PyArray_Ravel(mps[i],0);\n\t\t\tPy_DECREF(mps[i]);\n\t\t\tmps[i] = (PyArrayObject *)otmp;\n\t\t}\n\t\tprior2 = PyArray_GetPriority((PyObject *)(mps[i]), 0.0);\n\t\tif (prior2 > prior1) {\n\t\t\tprior1 = prior2;\n\t\t\tsubtype = mps[i]->ob_type;\n\t\t\tret = mps[i];\n\t\t}\n\t}\n\t\n\tnew_dim = 0;\n\tfor(i=0; ind;\n\t\telse {\n\t\t\tif (nd != mps[i]->nd) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"arrays must have same \"\\\n\t\t\t\t\t\t\"number of dimensions\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CompareLists(mps[0]->dimensions+1, \n\t\t\t\t\t\t mps[i]->dimensions+1, \n\t\t\t\t\t\t nd-1)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"array dimensions must \"\\\n\t\t\t\t\t\t\"agree except for d_0\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t}\n\t\tif (nd == 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"0-d arrays can't be concatenated\");\n\t\t\tgoto fail;\n\t\t}\n\t\tnew_dim += mps[i]->dimensions[0];\n\t}\n\t\n\ttmp = mps[0]->dimensions[0];\n\tmps[0]->dimensions[0] = new_dim;\n\tret = (PyArrayObject *)PyArray_New(subtype, nd,\n\t\t\t\t\t mps[0]->dimensions, \n\t\t\t\t\t type_num, NULL, NULL, 0, 0,\n (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 = PyTuple_New(n);\n\tfor (i=0; ind;\n\t\tpermutation = (intp *)malloc(n*sizeof(intp));\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\tgoto fail;\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\tret = (PyArrayObject *)PyArray_New(ap->ob_type, n, permutation, \n\t\t\t\t\t ap->descr->type_num, NULL,\n\t\t\t\t\t ap->data, ap->itemsize, ap->flags,\n\t\t\t\t\t (PyObject *)ap);\n\tif (ret == NULL) goto fail;\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);\n\t\n\tif (op && (op != Py_None))\n\t\tPyArray_Free(op, (char *)axes);\n\tfree(permutation);\n\treturn (PyObject *)ret;\n\t\n fail:\n\tPy_XDECREF(ret);\n\tif (permutation) free(permutation);\n\tif (op && (op != Py_None))\n\t\tPyArray_Free(op, (char *)axes);\n\treturn NULL;\n}\n\nstatic PyObject *\nPyArray_Repeat(PyArrayObject *aop, PyObject *op, int axis) {\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\tret = (PyArrayObject *)PyArray_New(aop->ob_type, aop->nd,\n\t\t\t\t\t aop->dimensions, \n\t\t\t\t\t aop->descr->type_num,\n\t\t\t\t\t NULL, NULL, aop->itemsize, 0,\n\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->itemsize;\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\t/* why not ??? \n\tif (PyTypeNum_ISFLEXIBLE(type_num)) {\n\t\tPyErr_SetString(PyExc_NotImplementedError, \n\t\t\t\t\"not implemented for flexible sizes\");\n\t\treturn NULL;\n\t}\n\t*/\n\tret = (PyArrayObject *)PyArray_New(ap->ob_type, ap->nd,\n\t\t\t\t\t ap->dimensions, type_num,\n\t\t\t\t\t NULL, NULL, 0, 0, (PyObject *)ap);\n\tif (ret == NULL) goto fail;\n\t\n\telsize = ret->itemsize;\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->compare(a,b,global_obj);\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#define SWAPBACK(op, ap) { \\\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\nstatic PyObject *\nPyArray_Sort(PyArrayObject *op, int axis) \n{\n\tPyArrayObject *ap=NULL, *store_arr=NULL;\n\tchar *ip;\n\tint i, n, m, elsize, orign;\n\n\tif ((ap = (PyAO*) _check_axis(op, &axis, 0))==NULL) return NULL;\n\n\tSWAPAXES(op, ap);\n\n\tap = (PyArrayObject *)PyArray_CopyFromObject((PyObject *)op, \n\t\t\t\t\t\t PyArray_NOTYPE,\n\t\t\t\t\t\t 1, 0);\n\tPy_DECREF(op);\n\n\tif (ap == NULL) return NULL;\n\n\tif (ap->descr->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"compare not supported for type\");\n\t\tPy_DECREF(ap);\n\t\treturn NULL;\n\t}\n\t\n\telsize = ap->itemsize;\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; iitemsize;\n\tconst intp *ipa = ip1;\n\tconst intp *ipb = ip2;\t\n\treturn global_obj->descr->compare(global_data + (isize * *ipa),\n global_data + (isize * *ipb), \n\t\t\t\t\t global_obj);\n}\n\nstatic PyObject *\nPyArray_ArgSort(PyArrayObject *op, int axis) \n{\n\tPyArrayObject *ap, *ret, *store;\n\tintp *ip;\n\tintp i, j, n, m, orign;\n\tint argsort_elsize;\n\tchar *store_ptr;\n\n\tif ((ap = (PyAO *)_check_axis(op, &axis, 0))==NULL) return NULL;\n\n\tSWAPAXES(op, ap);\n\n\tap = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)op, \n\t\t\t\t\t\t\t PyArray_NOTYPE,\n\t\t\t\t\t\t\t 1, 0);\n\tPy_DECREF(op);\n\n\tif (ap == NULL) return NULL;\n\t\n\tret = (PyArrayObject *)PyArray_New(ap->ob_type, ap->nd,\n\t\t\t\t\t ap->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, (PyObject *)ap);\n\tif (ret == NULL) goto fail;\n\t\n\tif (ap->descr->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\tip = (intp *)ret->data;\n\targsort_elsize = ap->itemsize;\n\tm = ap->dimensions[ap->nd-1];\n\tif (m == 0) goto finish;\n\n\tn = PyArray_SIZE(ap)/m;\n\tstore_ptr = global_data;\n\tglobal_data = ap->data;\n\tstore = global_obj;\n\tglobal_obj = ap;\n\tfor (i=0; idescr->compare;\n\tintp min_i, max_i, i, j;\n\tint location, elsize = ap1->itemsize;\n\tintp elements = ap1->dimensions[ap1->nd-1];\n\tintp n = PyArray_Size((PyObject *)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\nstatic PyObject *\nPyArray_SearchSorted(PyArrayObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1, *ap2, *ret;\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->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"compare not supported for type\");\n\t\tgoto fail;\n\t}\n\t\n\tlocal_where(ap1, ap2, ret); \n\t\n\tPy_DECREF(ap1);\n\tPy_DECREF(ap2);\n\treturn (PyObject *)ret;\n\t\n fail:\n\tPy_XDECREF(ap1);\n\tPy_XDECREF(ap2);\n\tPy_XDECREF(ret);\n\treturn NULL;\n}\n\n\n\n/* Could perhaps be redone to not make contiguous arrays \n */\n\nstatic PyObject *\nPyArray_InnerProduct(PyObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1, *ap2, *ret;\n\tintp i, j, l, i1, i2, n1, n2;\n\tint typenum;\n\tintp is1, is2, os;\n\tchar *ip1, *ip2, *op;\n\tintp dimensions[MAX_DIMS], nd;\n\tPyArray_DotFunc *dot;\n\tPyTypeObject *subtype;\n double prior1, prior2;\n\t\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\n\t\t\n\tret = NULL;\n\tap1 = (PyArrayObject *)PyArray_ContiguousFromAny(op1, typenum, \n\t\t\t\t\t\t\t 0, 0);\n\tif (ap1 == NULL) return NULL;\n\tap2 = (PyArrayObject *)PyArray_ContiguousFromAny(op2, typenum, \n\t\t\t\t\t\t\t 0, 0);\n\tif (ap2 == NULL) goto fail;\n\t\n\tif (ap1->nd == 0 || ap2->nd == 0) {\n\t\tret = (ap1->nd == 0 ? ap1 : ap2);\n\t\tret = (PyArrayObject *)ret->ob_type->tp_as_number->\\\n\t\t\tnb_multiply((PyObject *)ap1, (PyObject *)ap2);\n\t\tPy_DECREF(ap1);\n\t\tPy_DECREF(ap2);\n\t\treturn (PyObject *)ret;\n\t}\n\t\n\tl = ap1->dimensions[ap1->nd-1];\n\t\n\tif (ap2->dimensions[ap2->nd-1] != l) {\n\t\tPyErr_SetString(PyExc_ValueError, \"matrices are not aligned\");\n\t\tgoto fail;\n\t}\n\t\n\tif (l == 0) n1 = n2 = 0;\n\telse {\n\t\tn1 = PyArray_SIZE(ap1)/l;\n\t\tn2 = PyArray_SIZE(ap2)/l;\n\t}\n\n\tnd = ap1->nd+ap2->nd-2;\n\tj = 0;\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap1->dimensions[i];\n\t}\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap2->dimensions[i];\n\t}\n\n\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n prior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n prior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n subtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n\n\tret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions, \n\t\t\t\t\t typenum, NULL, NULL, 0, 0, \n (PyObject *)\n\t\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n\tif (ret == NULL) goto fail;\n\n\tdot = (ret->descr->dotfunc);\n\t\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"dot not available for this type\");\n\t\tgoto fail;\n\t}\n\n\t\n\tis1 = ap1->strides[ap1->nd-1]; \n\tis2 = ap2->strides[ap2->nd-1];\n\top = ret->data; os = ret->itemsize;\n\t\n\tip1 = ap1->data;\n\tfor(i1=0; i1data;\n\t\tfor(i2=0; i2nd == 0 || ap2->nd == 0) {\n\t\tret = (ap1->nd == 0 ? ap1 : ap2);\n\t\tret = (PyArrayObject *)ret->ob_type->tp_as_number->\\\n\t\t\tnb_multiply((PyObject *)ap1, (PyObject *)ap2);\n\t\tPy_DECREF(ap1);\n\t\tPy_DECREF(ap2);\n\t\treturn (PyObject *)ret;\n\t}\n\t\n\tl = ap1->dimensions[ap1->nd-1];\n\tif (ap2->nd > 1) {\n\t\tmatchDim = ap2->nd - 2;\n\t\totherDim = ap2->nd - 1;\n\t}\n\telse {\n\t\tmatchDim = 0;\n\t\totherDim = 0;\n\t}\n\n\tif (ap2->dimensions[matchDim] != l) {\n\t\tPyErr_SetString(PyExc_ValueError, \"objects are not aligned\");\n\t\tgoto fail;\n\t}\n\t\n\tif (l == 0) n1 = n2 = 0;\n\telse {\n\t\tn1 = PyArray_SIZE(ap1)/l;\n\t\tn2 = PyArray_SIZE(ap2)/l;\n\t}\n\n\tnd = ap1->nd+ap2->nd-2;\n\tj = 0;\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap1->dimensions[i];\n\t}\n\tfor(i=0; ind-2; i++) {\n\t\tdimensions[j++] = ap2->dimensions[i];\n\t}\n\tif(ap2->nd > 1) {\n\t\tdimensions[j++] = ap2->dimensions[ap2->nd-1];\n\t}\n\t/*\n\tfprintf(stderr, \"nd=%d dimensions=\", nd);\n\t for(i=0; i prior1 ? ap2->ob_type : ap1->ob_type);\n\n\tret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions, \n\t\t\t\t\t typenum, NULL, NULL, 0, 0, \n (PyObject *)\n\t\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n\tif (ret == NULL) goto fail;\n\n\tdot = ret->descr->dotfunc;\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"dot not available for this type\");\n\t\tgoto fail;\n\t}\n\t\t\n\tis1 = ap1->strides[ap1->nd-1]; is2 = ap2->strides[matchDim];\n\tif(ap1->nd > 1)\n\t\tis1r = ap1->strides[ap1->nd-2];\n\telse\n\t\tis1r = ap1->strides[ap1->nd-1];\n\tis2r = ap2->strides[otherDim];\n\n\top = ret->data; os = ret->itemsize;\n\n\tip1 = ap1->data;\n\tfor(i1=0; i1data;\n\t\tfor(i2=0; i2ob_type, 2, dims, PyArray_TYPE(arr),\n\t\t\t NULL, NULL, elsize, 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[ap1->nd-1];\n\tn2 = ap2->dimensions[ap2->nd-1];\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 = (int)(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\t\n\tret = (PyArrayObject *)PyArray_New(ap1->ob_type, 1,\n\t\t\t\t\t &length, typenum, \n\t\t\t\t\t NULL, NULL, 0, 0, \n (PyObject *)ap1);\n\tif (ret == NULL) goto fail;\n\n\t\n\tdot = ret->descr->dotfunc;\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"function not available for this type\");\n\t\tgoto fail;\n\t}\n\t\n\tis1 = ap1->strides[ap1->nd-1]; is2 = ap2->strides[ap2->nd-1];\n\top = ret->data; os = ret->itemsize;\n\t\n\tip1 = ap1->data; ip2 = ap2->data+n_left*is2;\n\tn = n-n_left;\n\tfor(i=0; idescr->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->itemsize;\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 ret = (PyArrayObject *)PyArray_New(self->ob_type, nd, shape, \n\t\t\t\t\t self->descr->type_num,\n\t\t\t\t\t NULL, NULL, 0, 0, \n (PyObject *)self);\n\t\n if (ret == NULL) goto fail;\n\t\n max_item = self->dimensions[axis];\n chunk = chunk * ret->itemsize;\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\nstatic PyObject *\nPyArray_Put(PyArrayObject *self, PyObject *indices0, PyObject* values0) \n{\n PyArrayObject *indices, *values;\n int i, chunk, ni, max_item, nv, tmp; \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->itemsize;\n\n indices = (PyArrayObject *)PyArray_ContiguousFromAny(indices0, PyArray_INTP, 0, 0);\n if (indices == NULL) goto fail;\n ni = PyArray_SIZE(indices);\n\n values = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny(values0, self->descr->type_num, \n\t\t\t\t\t 0, 0);\n if (values == NULL) goto fail;\n nv = PyArray_SIZE(values);\n if (nv > 0) { /* nv == 0 for a null array */\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 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\nstatic PyObject *\nPyArray_PutMask(PyArrayObject *self, PyObject *mask0, PyObject* values0) \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->itemsize;\n\n mask = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny(mask0, PyArray_BOOL, 0, 0);\n if (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\t\tfor(i=0; idata + chunk * (i % nv);\n\t\t\ttmp = ((Bool *)(mask->data))[i];\n\t\t\tif (tmp) {\n\t\t\t\tmemmove(dest + i * chunk, src, chunk);\n\t\t\t\tif (thistype == PyArray_OBJECT)\n\t\t\t\t\tPy_INCREF(*((PyObject **)src));\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 \nstatic int \nPyArray_Converter(PyObject *object, PyObject **address) \n{\n if (PyArray_Check(object)) {\n *address = object;\n\t\tPy_INCREF(object);\n return PY_SUCCEED;\n }\n else {\n\t\t*address = PyArray_FromAny(object, NULL, 0, 0, CARRAY_FLAGS);\n\t\tif (*address == NULL) return PY_FAIL;\n\t\treturn PY_SUCCEED;\n }\n}\n\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\nstatic int\nPyArray_TypestrConvert(int itemsize, int gentype)\n{\n\tregister int newtype = gentype;\n\t\n\tif (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\nstatic int\nPyArray_BufferConverter(PyObject *obj, PyArray_Chunk *buf)\n{\n int buflen;\n\n buf->ptr = NULL;\n buf->flags = WRITEABLE;\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\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) goto fail;\n return PY_SUCCEED;\n\n fail:\n\tPyDimMem_FREE(seq->ptr);\n\treturn PY_FAIL;\n}\n\n/* This function takes a Python object representing a type and converts it \n to a C type_num and an itemsize (elements of PyArray_Typecode structure)\n \n Many objects can be used to represent a type.\n */\n\nstatic int\nPyArray_TypecodeConverter(PyObject *obj, PyArray_Typecode *at)\n{\n char *type;\n PyArray_Descr *descr;\n int check_num=PyArray_NOTYPE+10;\n\tint len;\n\tPyObject *item, *attr=NULL;\n\n\tat->itemsize = 0;\n if (obj == Py_None) {\n at->type_num = PyArray_NOTYPE;\n return PY_SUCCEED;\n }\n\n if (PyType_Check(obj) && PyType_IsSubtype((PyTypeObject *)obj, \n &PyGenericArrType_Type)) {\n PyArray_TypecodeFromTypeObject(obj, at);\n return PY_SUCCEED;\n }\n\n\n\t/* type object could be an array */\n\tif (PyArray_Check(obj)) {\n\t\tat->type_num = PyArray_TYPE(obj);\n\t\tat->itemsize = PyArray_ITEMSIZE(obj);\n\t\treturn PY_SUCCEED;\n\t}\n\n\t/* or an array scalar */\n if (PyArray_IsScalar(obj, Generic)) {\n PyArray_TypecodeFromScalar(obj, at);\n return PY_SUCCEED;\n }\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);\t\t\n\t\tif (len > 0) {\n\t\t\tcheck_num = (int) type[0];\n\t\t}\n\t\tif (len > 1) {\n\t\t\tat->itemsize = atoi(type+1);\n\t\t\t/* When specifying length of UNICODE\n\t\t\t the number of characters is given to match \n\t\t\t the STRING interface. Each character can be\n\t\t\t more than one byte and itemsize must be\n\t\t\t the number of bytes.\n\t\t\t*/\n\t\t\tif (check_num == PyArray_UNICODELTR ||\t\\\n\t\t\t check_num == PyArray_UNICODE) \n\t\t\t at->itemsize *= sizeof(Py_UNICODE);\n\n\t\t\t/* Support for generic processing */\n\t\t\telse if ((check_num != PyArray_STRINGLTR) &&\n\t\t\t\t (check_num != PyArray_VOIDLTR) &&\n\t\t\t\t (check_num != PyArray_STRING) &&\n\t\t\t\t (check_num != PyArray_VOID)) {\n\t\t\t\tcheck_num = \\\n\t\t\t\t\tPyArray_TypestrConvert(at->itemsize,\n\t\t\t\t\t\t\t check_num);\n\t\t\t at->itemsize = 0;\n\t\t\t\tif (check_num == PyArray_NOTYPE) goto fail;\n\t\t\t}\n\t\t}\n\t}\n\t/* Arbitray object with dtypechar and itemsize attributes. */\n\telse if (PyObject_HasAttrString(obj, \"dtypechar\") && \n\t\t PyObject_HasAttrString(obj, \"itemsize\")) {\n\t\tattr = PyObject_GetAttrString(obj, \"dtypechar\");\n\t\tif (attr && PyString_GET_SIZE(attr) > 0) {\n\t\t\ttype = PyString_AsString(attr);\n\t\t\tcheck_num = (int) type[0];\n\t\t}\n\t\tPy_XDECREF(attr);\n\t\tif (!PyErr_Occurred()) {\n\t\t\tattr = PyObject_GetAttrString(obj, \"itemsize\");\n\t\t\tat->itemsize = PyInt_AsLong(attr);\n\t\t\tPy_XDECREF(attr);\n\t\t}\t\t\t\n\t}\t\t\n\telse if (PyType_Check(obj)) {\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 *)(&PyBool_Type))\n\t\t\tcheck_num = PyArray_BOOL;\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 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}\t\n else { /* Default -- try integer conversion */\n\t\t/* Don't allow integer conversion */\n /* check_num = PyInt_AsLong(obj); */\n\t\t/* fprintf(stderr, \"****\\n\\ntype=%s\\n\\n****\\n\", \n\t\t\tobj->ob_type->tp_name);\n\t\t*/\n\t\tgoto fail;\n\t}\n\n\tif (PyErr_Occurred()) goto fail;\n\n\t/*\n\tif (check_num == PyArray_NOTYPE) return PY_FAIL;\n\t*/\n\tif (check_num == PyArray_NOTYPE) {\n\t\tat->type_num = PyArray_NOTYPE;\n\t\tat->itemsize = 0;\n\t\treturn PY_SUCCEED;\n\t}\n\n if ((descr = PyArray_DescrFromType(check_num))==NULL) {\n\t\t/* Now check to see if the object is registered\n\t\t in typeDict */\n\t\tif (typeDict != NULL) {\n\t\t\titem = PyDict_GetItem(typeDict, obj);\n\t\t\tif (item) {\n\t\t\t\tPyArray_TypecodeFromTypeObject(obj, at);\n\t\t\t\tPyErr_Clear();\n\t\t\t\treturn PY_SUCCEED;\n\t\t\t}\n\t\t}\n return PY_FAIL;\n\t}\n\t\n at->type_num = descr->type_num;\n\tif (at->itemsize == 0) at->itemsize = descr->elsize;\n\t\n return PY_SUCCEED;\n\n fail:\n\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\"data type not understood\");\n\treturn PY_FAIL;\n}\t\n\n\n/* This function returns true if the two typecodes are \n equivalent (same basic kind and same itemsize).\n*/\n\nstatic Bool\nPyArray_EquivalentTypes(PyArray_Typecode *typ1, PyArray_Typecode *typ2)\n{\n\tregister int typenum1=typ1->type_num;\n\tregister int typenum2=typ2->type_num;\n\tregister int size1=typ1->itemsize;\n\tregister int size2=typ2->itemsize;\n\n\tif (size1 != size2) return FALSE;\n\tif (typenum1==typenum2) return TRUE;\n\n\t/* If we are here then size1 == size2 */\n\tif (typenum1 < PyArray_FLOAT) {\n\t\tif (PyTypeNum_ISBOOL(typenum1))\n\t\t\treturn (Bool)(PyTypeNum_ISBOOL(typenum2));\n\t\telse if (PyTypeNum_ISUNSIGNED(typenum1))\n\t\t\treturn (Bool)(PyTypeNum_ISUNSIGNED(typenum2));\n\t\telse \n\t\t\treturn (Bool)(PyTypeNum_ISSIGNED(typenum2));\n\t}\n\telse {\n\t\tif (PyTypeNum_ISFLOAT(typenum1))\n\t\t\treturn (Bool)(PyTypeNum_ISFLOAT(typenum2));\n\t\telse if (PyTypeNum_ISCOMPLEX(typenum1))\n\t\t\treturn (Bool)(PyTypeNum_ISCOMPLEX(typenum2));\n\t}\n\t/* Default size1 != size2 and typenum1 != typenum2 */\n\treturn FALSE;\t\n}\n\nstatic Bool \nPyArray_EquivArrTypes(PyArrayObject *a1, PyArrayObject *a2)\n{\n PyArray_Typecode type1={0,0,0};\n PyArray_Typecode type2={0,0,0};\n\n\ttype1.type_num = PyArray_TYPE(a1);\n\ttype2.type_num = PyArray_TYPE(a2);\n\ttype1.itemsize = PyArray_ITEMSIZE(a1);\n\ttype2.itemsize = PyArray_ITEMSIZE(a2);\n\t\t\t\n return PyArray_EquivalentTypes(&type1, &type2);\n}\n\n/* All flexible types of the same typenum seen as equivalent */\nstatic Bool\nPyArray_EquivalentTypenums(int typenum1, int typenum2)\n{\n\tPyArray_Typecode type1={0,0,0};\n\tPyArray_Typecode type2={0,0,0};\n\t\n\ttype1.type_num = typenum1;\n\ttype2.type_num = typenum2;\n\ttype1.itemsize = PyArray_DescrFromType(typenum1)->elsize;\n\ttype2.itemsize = PyArray_DescrFromType(typenum2)->elsize;\n\t\n\treturn PyArray_EquivalentTypes(&type1, &type2);\n}\n\n\n/*** END C-API FUNCTIONS **/\n\n\n#define _ARET(x) PyArray_Return((PyArrayObject *)(x))\n\nstatic char doc_fromobject[] = \"array(object, dtype=None, copy=1, fortran=0, \"\\\n \"subok=0)\\n\"\\\n \"will return a new array formed from the given object type given.\\n\"\\\n \"Object can anything with an __array__ method, or any object\\n\"\\\n \"exposing the array interface, or any (nested) sequence.\\n\"\\\n \"If no type is given, then the type will be determined as the\\n\"\\\n \"minimum type required to hold the objects in the sequence.\\n\"\\\n \"If copy is zero and sequence is already an array with the right \\n\"\\\n \"type, a reference will be returned. If the sequence is an array,\\n\"\\\n \"type can be used only to upcast the array. For downcasting \\n\"\\\n \"use .astype(t) method. If subok is true, then subclasses of the\\n\"\\\n \"array may be returned. Otherwise, a base-class ndarray is returned\";\n\nstatic PyObject *\n_array_fromobject(PyObject *ignored, PyObject *args, PyObject *kws)\n{\n\tPyObject *op, *ret=NULL;\n\tstatic char *kwd[]= {\"object\", \"dtype\", \"copy\", \"fortran\", \"subok\", \n NULL};\n Bool subok=FALSE;\n\tBool copy=TRUE;\n\tPyArray_Typecode type = {PyArray_NOTYPE, 0, 0};\n\tPyArray_Typecode oldtype = {PyArray_NOTYPE, 0, 0};\n\tint type_num;\n\tBool fortran=FALSE;\n\tint flags=0;\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kws, \"O|O&O&O&O&\", kwd, &op, \n\t\t\t\t\tPyArray_TypecodeConverter,\n &type, \n\t\t\t\t\tPyArray_BoolConverter, ©, \n\t\t\t\t\tPyArray_BoolConverter, &fortran,\n PyArray_BoolConverter, &subok)) \n\t\treturn NULL;\n\ttype_num = type.type_num;\n\n\t/* fast exit if simple call */\n\tif ((PyArray_CheckExact(op) && PyBigArray_CheckExact(op)) && \\\n (copy==0) && \\\n\t (fortran == PyArray_CHKFLAGS(op, FORTRAN))) {\n\t\tif (type_num == PyArray_NOTYPE) {\n\t\t\tPy_INCREF(op);\n\t\t\treturn op;\n\t\t}\n\t\t/* One more chance */\n\t\toldtype.type_num = PyArray_TYPE(op);\n\t\toldtype.itemsize = PyArray_ITEMSIZE(op);\n\t\tif (PyArray_EquivalentTypes(&oldtype, &type)) {\n\t\t\tPy_INCREF(op);\n\t\t\treturn op;\n\t\t}\n\t}\n\n\ttype.fortran = fortran; \n\tif (copy) {\n\t\tflags = ENSURECOPY;\n\t}\n if (!subok) {\n flags |= ENSUREARRAY;\n }\n\n\tif ((ret = PyArray_FromAny(op, &type, 0, 0, flags)) == NULL) \n\t\treturn NULL;\n\n\treturn ret;\n}\n\nstatic PyObject *\nPyArray_Empty(int nd, intp *dims, PyArray_Typecode *type)\n{\n\tPyArrayObject *ret;\n\tintp n;\n \n\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, nd, dims, \n\t\t\t\t\t type->type_num,\n\t\t\t\t\t NULL, NULL, type->itemsize, \n\t\t\t\t\t type->fortran, NULL);\n\tif (ret == NULL) return NULL;\n \n\tn = PyArray_SIZE(ret);\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=intp,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_Typecode typecode = {PyArray_NOTYPE, 0, 0};\n PyArray_Dims shape;\n\tBool fortran = FALSE;\t\n PyObject *ret;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &shape, \n PyArray_TypecodeConverter,\n\t\t\t\t\t &typecode, \n\t\t\t\t\t PyArray_BoolConverter, &fortran)) \n\t\treturn NULL;\n\t\n\ttypecode.fortran = fortran;\n if (typecode.type_num ==PyArray_NOTYPE) \n\t\ttypecode.type_num = PyArray_INTP;\n \n\tret = PyArray_Empty(shape.len, shape.ptr, &typecode); \n PyDimMem_FREE(shape.ptr);\n return ret;\n}\n\nstatic char doc_scalar[] = \"scalar(dtypestr,obj) will return a new scalar array of the given type initialized with obj. Mainly for pickle support. typestr must be a valid data typestr (complete with < > or |). If dtypestr is object, 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[] = {\"dtypestr\",\"obj\", NULL};\n\tPyArray_Typecode typecode;\n\tPyObject *obj=NULL;\n\tchar *typestr;\n\tint typestrlen;\n\tint swap, alloc=0;\n\tvoid *dptr;\n\tPyObject *ret;\n\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"z#|O\",\n\t\t\t\t\t kwlist, &typestr, &typestrlen,\n\t\t\t\t\t &obj)) \n\t\treturn NULL;\n\t\n\tif (_array_typecode_fromstr(typestr, &swap, &typecode) < 0) \n\t\treturn NULL;\n\t\n\tif (typecode.itemsize == 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\tswap = 0;\n\t}\n\telse {\n\t\tif (obj == NULL) {\n\t\t\tdptr = malloc(typecode.itemsize);\n\t\t\tif (dptr == NULL) {\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tmemset(dptr, '\\0', typecode.itemsize);\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.itemsize) {\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.type_num,\n\t\t\t typecode.itemsize, swap); \n\n\t/* free dptr which contains zeros */\n\tif (alloc) free(dptr);\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_Zeros(int nd, intp *dims, PyArray_Typecode *type)\n{\n\tPyArrayObject *ret;\n\tintp n;\n\n\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, nd, dims, \n\t\t\t\t\t type->type_num,\n\t\t\t\t\t NULL, NULL, type->itemsize, \n\t\t\t\t\t type->fortran, NULL);\n\tif (ret == NULL) return NULL;\n \n\tn = PyArray_SIZE(ret);\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 {\t\t\n\t\tmemset(ret->data, 0, n*(ret->itemsize));\n\t}\n\treturn (PyObject *)ret;\n\n}\n\nstatic char doc_zeros[] = \"zeros((d1,...,dn),dtype=intp,fortran=0) will return a new array of shape (d1,...,dn) and type typecode with all it's entries initialized to zero.\";\n\n\nstatic PyObject *\narray_zeros(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {\"shape\",\"dtype\",\"fortran\",NULL};\n\tPyArray_Typecode typecode = {PyArray_NOTYPE, 0, 0};\n PyArray_Dims shape;\n\tBool fortran = FALSE;\t\n PyObject *ret;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &shape, \n PyArray_TypecodeConverter,\n\t\t\t\t\t &typecode, \n\t\t\t\t\t PyArray_BoolConverter,\n\t\t\t\t\t &fortran)) \n\t\treturn NULL;\n\t\n\ttypecode.fortran = fortran;\n if (typecode.type_num ==PyArray_NOTYPE) \n\t\ttypecode.type_num = PyArray_INTP;\n \n\tret = PyArray_Zeros(shape.len, shape.ptr, &typecode); \n PyDimMem_FREE(shape.ptr);\n return 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 char doc_fromString[] = \"fromstring(string, dtype=intp, count=-1, swap=False) 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\tPyArrayObject *ret; \n\tchar *data;\n\tlonglong nin=-1;\n\tintp s, n;\n\tstatic char *kwlist[] = {\"string\", \"dtype\", \"count\", \"swap\",NULL};\n\tPyArray_Typecode type = {PyArray_INTP, sizeof(intp), 0};\n\tint itemsize;\n\tint swapped=FALSE;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"s#|O&LO&\", kwlist, \n\t\t\t\t\t &data, &s, \n\t\t\t\t\t PyArray_TypecodeConverter, &type,\n\t\t\t\t\t &nin, \n\t\t\t\t\t PyArray_BoolConverter,\n\t\t\t\t\t &swapped)) {\n\t\treturn NULL;\n\t}\n\t\n\tn = (intp) nin;\n\n\titemsize = type.itemsize;\n\tif (itemsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \"zero-valued itemsize\");\n\t\treturn NULL;\n\t}\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\"string size must be a multiple\"\\\n\t\t\t\t\t\" of element size\");\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\"string is smaller than requested\"\\\n\t\t\t\t\t\" size\");\n\t\t\treturn NULL;\n\t\t}\n\t}\n\n\tif ((ret = (PyArrayObject *)PyArray_New(&PyArray_Type, 1, &n, \n\t\t\t\t\t\ttype.type_num, NULL, \n\t\t\t\t\t\tNULL, itemsize, 0,\n\t\t\t\t\t\tNULL)) == NULL)\n\t\treturn NULL;\n\t\t\n\tmemcpy(ret->data, data, n*ret->itemsize);\n\tif (swapped) ret->flags &= ~NOTSWAPPED;\n\tPyArray_INCREF(ret);\n\treturn (PyObject *)ret;\n}\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\nstatic int\n_fill_in_itemsize(PyArray_Typecode *typecode)\n{\n\tPyArray_Descr *descr;\n\tdescr = PyArray_DescrFromType(typecode->type_num);\n\tif (descr==NULL) return -1;\n\ttypecode->itemsize = descr->elsize;\n\treturn 0;\n}\n\n\nstatic PyObject *\nPyArray_FromFile(FILE *fp, PyArray_Typecode *typecode, intp num, char *sep)\n{\n\tPyArrayObject *r;\n\tsize_t nread = 0;\n\tPyArray_ScanFunc *scan;\n\n\tif (typecode->itemsize == 0) {\n\t\tif (_fill_in_itemsize(typecode) < 0) \n\t\t\treturn NULL;\n\t}\n\n\tif (num == -1 && sep == NULL) { /* 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\tfseek(fp, (long) start, SEEK_SET);\n\t\tif (numbytes == -1) {\n\t\t\tPyErr_SetString(PyExc_IOError, \"could not seek in file\");\n\t\t\treturn NULL;\n\t\t}\n\t\tif (typecode->itemsize == 0) {\n\t\t\ttypecode->itemsize = numbytes;\n\t\t\tnum = 1;\n\t\t}\n\t\telse {\n\t\t\tnum = numbytes / typecode->itemsize;\n\t\t}\n\t}\n\t\n\tif (sep==NULL) { /* binary data */\n\t\tr = (PyArrayObject *)PyArray_New(&PyArray_Type, 1, &num, \n\t\t\t\t\t\t typecode->type_num,\n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t typecode->itemsize, 0, NULL);\n\t\tif (r==NULL) return NULL;\n\t\tnread = fread(r->data, typecode->itemsize, 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 = PyArray_DescrFromType(typecode->type_num)->scanfunc;\n\t\tif (scan == NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"don't know how to read \"\t\\\n\t\t\t\t\t\"character files with that \"\t\\\n\t\t\t\t\t\"array type\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (num != -1) { /* number to read is known */\n\t\t\tr = (PyArrayObject *)PyArray_New(&PyArray_Type, 1, \n\t\t\t\t\t\t\t &num, \n\t\t\t\t\t\t\t typecode->type_num,\n\t\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t\t typecode->itemsize, \n\t\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, r->itemsize, sep, NULL);\n\t\t\t\tif (done < -2) break;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += r->itemsize;\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 *)PyArray_New(&PyArray_Type, 1, \n\t\t\t\t\t\t\t &size, \n\t\t\t\t\t\t\t typecode->type_num,\n\t\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t\t typecode->itemsize, \n\t\t\t\t\t\t\t 0, NULL);\n\t\t\tif (r==NULL) return NULL;\n\t\t\ttotalbytes = bytes = size * typecode->itemsize;\n\t\t\tdptr = r->data;\n\t\t\twhile (!done) {\n\t\t\t\tdone = scan(fp, dptr, r->itemsize, 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->itemsize;\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->itemsize);\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->itemsize);\n\t\tPyArray_DIM(r,0) = nread;\n\t}\n\treturn (PyObject *)r;\n}\n\nstatic char doc_fromfile[] = \\\n\t\"fromfile(file=, dtype=intp, count=-1, sep='')\\n\"\\\n\t\"\\n\"\\\n\t\" Return an array of the given data type from a \\n\"\\\n\t\" (text or binary) file. The file argument can be an open file\\n\"\\\n\t\" or a string with the name of a file to read from. If\\n\"\\\n\t\" count==-1, then the entire file is read, otherwise count is\\n\"\\\n\t\" the number of items of the given type read in. If sep is ''\\n\"\\\n\t\" then read a binary file, otherwise it gives the separator\\n\"\\\n\t\" between elements in a text file.\\n\"\\\n\t\"\\n\"\\\n\t\" WARNING: This function should be used sparingly, as it is not\\n\"\\\n\t\" a robust method of persistence. But it can be useful to\\n\"\\\n\t\" read in simply-formatted or binary data quickly.\";\n\nstatic PyObject *\narray_fromfile(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tPyObject *file=NULL, *ret;\n\tFILE *fp;\n\tchar *sep=\"\";\n\tchar *mode=NULL;\n\tlonglong nin=-1;\n\tstatic char *kwlist[] = {\"file\", \"dtype\", \"count\", \"sep\", NULL};\n\tPyArray_Typecode type = {PyArray_INTP, sizeof(intp), 0};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"O|O&Ls\", kwlist, \n\t\t\t\t\t &file,\n\t\t\t\t\t PyArray_TypecodeConverter, &type,\n\t\t\t\t\t &nin, &sep)) {\n\t\treturn NULL;\n\t}\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, \"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\nstatic PyObject *\nPyArray_FromBuffer(PyObject *buf, PyArray_Typecode *type, \n\t\t intp count, int swapped) \n{\n\tPyArrayObject *ret;\n\tchar *data;\n\tint ts;\n\tintp s, n;\n\tint itemsize;\n\tint write=1;\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\treturn NULL;\n\t}\n\tif (type->itemsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"itemsize cannot be zero in type\");\n\t\treturn NULL;\n\t}\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\treturn NULL;\n\t\t}\n\t}\n\ts = (intp)ts;\t\n\tn = (intp)count;\n\titemsize = type->itemsize;\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\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\treturn NULL;\n\t\t}\n\t}\n\t\n\tif ((ret = (PyArrayObject *)PyArray_New(&PyArray_Type, 1, &n, \n\t\t\t\t\t\ttype->type_num, NULL, \n\t\t\t\t\t\tdata, itemsize, DEFAULT_FLAGS,\n\t\t\t\t\t\tNULL)) == NULL)\n\t\treturn NULL;\n\t\n\tif (!write) ret->flags &= ~WRITEABLE;\n\tif (swapped) ret->flags &= ~NOTSWAPPED;\n\tPy_INCREF(buf);\n\t/* Store a reference for decref on deallocation */\n\tret->base = buf;\n\tPyArray_UpdateFlags(ret, ALIGNED);\n\treturn (PyObject *)ret; \t\n}\n\nstatic char doc_frombuffer[] = \\\n\t\"frombuffer(buffer=, dtype=intp, count=-1, swap=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 the buffer has data that is out\\n\" \\\n\t\" not in machine byte-order, than set swap=1. 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;\n\tstatic char *kwlist[] = {\"buffer\", \"dtype\", \"count\", \n\t\t\t\t \"swap\", NULL};\n\tPyArray_Typecode type = {PyArray_INTP, sizeof(intp), 0};\n\tint swapped=0;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"O|O&Li\", kwlist, \n\t\t\t\t\t &obj,\n\t\t\t\t\t PyArray_TypecodeConverter, &type,\n\t\t\t\t\t &nin, &swapped)) {\n\t\treturn NULL;\n\t}\n\n\treturn PyArray_FromBuffer(obj, &type, (intp)nin, swapped);\n}\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\nstatic PyObject *\nPyArray_Arange(double start, double stop, double step, int type_num)\n{\n\tintp length, i;\n\tPyObject *range;\n\tchar *rptr;\n\tint elsize, type;\n\tdouble value;\n\tPyArray_Descr *dbl_descr;\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\tdbl_descr = PyArray_DescrFromType(PyArray_DOUBLE);\n \n\trptr = ((PyArrayObject *)range)->data;\n\telsize = ((PyArrayObject *)range)->itemsize;\n\ttype = ((PyArrayObject *)range)->descr->type_num;\n\tfor (i=0; i < length; i++) {\n\t\tvalue = start + i*step;\n\t\tdbl_descr->cast[type]((char*)&value, rptr, 1, NULL, \n\t\t\t\t (PyArrayObject *)range);\n\t\trptr += elsize;\n\t}\n \n\treturn range;\n}\n\n\nstatic char doc_arange[] = \"arange(start, stop=None, step=1, dtype=intp)\\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=Py_None, *o_step=NULL;\n\tstatic char *kwd[]= {\"start\", \"stop\", \"step\", \"dtype\", NULL};\n\tdouble start, stop, step;\n\tPyArray_Typecode typecode = {PyArray_NOTYPE, 0};\n\tint type_num;\n\tint deftype = PyArray_INTP;\n\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_TypecodeConverter, \n\t\t\t\t\t&typecode)) \n\t\treturn NULL;\n\n\tdeftype = PyArray_ObjectType(o_start, deftype);\n\tif (o_stop != Py_None) {\n\t\tdeftype = PyArray_ObjectType(o_stop, deftype);\n\t}\n\tif (o_step != NULL) {\n\t\tdeftype = PyArray_ObjectType(o_step, deftype);\n\t}\n\n\ttype_num = typecode.type_num;\n\tif (type_num == PyArray_NOTYPE) {\n\t\ttype_num = deftype;\n\t}\n\n\tstart = PyFloat_AsDouble(o_start);\n\tif error_converting(start) return NULL;\n\n\tif (o_step == NULL) {\n\t\tstep = 1;\n\t}\n\telse {\n\t\tstep = PyFloat_AsDouble(o_step);\n\t\tif error_converting(step) return NULL;\n\t}\n\n\tif (o_stop == Py_None) {\n\t\tstop = start;\n\t\tstart = 0;\n\t}\n\telse {\n\t\tstop = PyFloat_AsDouble(o_stop);\n\t\tif error_converting(stop) return NULL;\n\t}\n\n\treturn PyArray_Arange(start, stop, step, type_num);\n}\n\n#undef _ARET\n\n/*****\n static char doc_arrayMap[] = \"arrayMap(func, [a1,...,an])\";\n\n static PyObject *array_arrayMap(PyObject *dummy, PyObject *args) {\n PyObject *shape, *a0;\n \n if (PyArg_ParseTuple(args, \"OO\", &a0, &shape) == NULL) return NULL;\n\t\n return PyArray_Map(a0, shape);\n }\n*****/\n\nstatic char \ndoc_set_string_function[] = \"set_string_function(f, repr=1) sets the python function f to be the function used to obtain a pretty printable string version of a array whenever a array is printed. f(M) should expect a array argument M, and should return a string consisting of the desired representation of M for printing.\";\n\nstatic PyObject *\narray_set_string_function(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tPyObject *op;\n\tint repr=1;\n\tstatic char *kwlist[] = {\"f\", \"repr\", NULL};\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"O|i\", kwlist, \n\t\t\t\t\t&op, &repr)) return NULL; \n\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 (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\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\tif ((x==NULL) || (y==NULL)) {\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\tarr = (PyArrayObject *)PyArray_FromAny(condition, NULL, 0, 0, 0);\n\tif (arr == NULL) return NULL;\n\n\tif ((x==NULL) && (y==NULL)) {\n\t\tret = PyArray_Nonzero(arr);\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\n\tzero = PyInt_FromLong((long) 0);\n\n\tobj = PyArray_EnsureArray(PyArray_GenericBinaryFunction(arr, zero, n_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_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_Typecode d1={PyArray_NOTYPE, 0, 0};\n\tPyArray_Typecode d2={PyArray_NOTYPE, 0, 0};\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_TypecodeConverter, &d1,\n\t\t\t\t\tPyArray_TypecodeConverter, &d2))\n\t\treturn NULL;\n\tif (d1.type_num == PyArray_NOTYPE || \\\n\t d2.type_num == PyArray_NOTYPE) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"did not understand one of the types; \"\\\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 struct PyMethodDef array_module_methods[] = {\n\t{\"set_string_function\", (PyCFunction)array_set_string_function, \n\t METH_VARARGS|METH_KEYWORDS, doc_set_string_function},\n\t{\"set_numeric_ops\", (PyCFunction)array_set_ops_function,\n\t METH_VARARGS|METH_KEYWORDS, doc_set_ops_function},\n\t{\"set_typeDict\", (PyCFunction)array_set_typeDict,\n\t METH_VARARGS, doc_set_typeDict},\n\n\t{\"array\",\t(PyCFunction)_array_fromobject, \n\t METH_VARARGS|METH_KEYWORDS, doc_fromobject},\n\t{\"arange\", (PyCFunction)array_arange, \n\t METH_VARARGS|METH_KEYWORDS, doc_arange},\n\t{\"zeros\",\t(PyCFunction)array_zeros, \n\t METH_VARARGS|METH_KEYWORDS, doc_zeros},\n\t{\"empty\",\t(PyCFunction)array_empty, \n\t METH_VARARGS|METH_KEYWORDS, doc_empty},\n\t{\"scalar\", (PyCFunction)array_scalar,\n\t METH_VARARGS|METH_KEYWORDS, doc_scalar},\n\t{\"where\", (PyCFunction)array_where,\n\t METH_VARARGS, doc_where},\n\t{\"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/* {\"arrayMap\",\t(PyCFunction)array_arrayMap, \n\t METH_VARARGS, doc_arrayMap},*/\n\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(Numeric, Generic);\n SINGLE_INHERIT(Integer, Numeric);\n SINGLE_INHERIT(Inexact, Numeric);\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 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 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 SINGLE_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\t \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, \"NOTSWAPPED\", s=PyInt_FromLong(NOTSWAPPED));\n Py_DECREF(s);\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\tif (PyType_Ready(&PyArrayIter_Type) < 0)\n\t\treturn; \n \n\tif (PyType_Ready(&PyArrayMapIter_Type) < 0)\n return; \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\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) \n return; /* otherwise there is an error */\n\n\n err:\t\n\t/* Check for errors */\n\tif (PyErr_Occurred())\n PyErr_Print();\n\t\tPy_FatalError(\"can't initialize module multiarray\");\n\n\treturn;\n}\n\n", "source_code_before": "\n/*\n Python Multiarray Module -- A useful collection of functions for creating and\n using ndarrays\n\n Original file \n Copyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\n Modified for scipy_core in 2005 \n\n Travis E. Oliphant\n Assistant Professor at\n Brigham Young University\n \n*/\n\n/* $Id: multiarraymodule.c,v 1.36 2005/09/14 00:14:00 teoliphant Exp $ */\n\n#include \"Python.h\"\n#include \"structmember.h\"\n/*#include \n#include \n*/\n\n#define _MULTIARRAYMODULE\n#include \"scipy/arrayobject.h\"\n\n#define PyAO PyArrayObject\n\nstatic PyObject *typeDict=NULL; /* Must be explicitly loaded */\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\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\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\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\nstatic int \nPyArray_CompareLists(intp *l1, intp *l2, int n) \n{\n int i;\n for(i=0;itype_num;\n\t}\n\n\tnew = PyArray_New(self->ob_type,\n\t\t\t self->nd, self->dimensions,\n\t\t\t self->descr->type_num,\n\t\t\t self->strides,\n\t\t\t self->data,\n\t\t\t self->itemsize,\n\t\t\t self->flags, (PyObject *)self);\n\n\tif (new==NULL) return NULL;\n\t\n Py_INCREF(self);\n PyArray_BASE(new) = (PyObject *)self;\n if ((type_num != PyArray_NOTYPE) && \\\n (type_num != self->descr->type_num)) {\n if (!PyTypeNum_ISFLEXIBLE(type_num)) {\n v = PyArray_TypeObjectFromType(type_num);\n }\n else {\n PyArray_Descr *descr;\n int itemsize = type->itemsize;\n descr = PyArray_DescrFromType(type_num);\n if (type_num == PyArray_UNICODE) \n itemsize /= sizeof(Py_UNICODE);\n /* construct a string representation */\n v = PyString_FromFormat(\"%c%d\", descr->type, \n itemsize);\n }\n if (v == NULL) goto fail;\n /* set attribute new.dtype = newtype */\n if (PyObject_SetAttrString(new, \"dtype\", v) < 0) goto fail;\n Py_DECREF(v);\n }\n\treturn new;\t\n\n fail:\n Py_XDECREF(v);\n Py_XDECREF(new);\n return NULL;\n}\n\nstatic PyObject *\nPyArray_Ravel(PyArrayObject *a, int fortran)\n{\n\tPyArray_Dims newdim = {NULL,1};\n\tintp val[1] = {-1};\n\n if (a->nd == 1) {\n Py_INCREF(a);\n return (PyObject *)a;\n }\n\tnewdim.ptr = val;\n\tif (!fortran && PyArray_ISCONTIGUOUS(a)) \n\t\treturn PyArray_Newshape(a, &newdim);\n\telse\n\t return PyArray_Flatten(a, fortran);\n}\n\nstatic PyObject *\nPyArray_Flatten(PyArrayObject *a, int fortran)\n{\n\tPyObject *ret, *new;\n\tintp size;\n\n\tsize = PyArray_SIZE(a);\n\tret = PyArray_New(a->ob_type,\n\t\t\t 1, &size,\n\t\t\t a->descr->type_num,\n\t\t\t NULL,\n NULL,\n\t\t\t a->itemsize,\n\t\t\t 0, (PyObject *)a);\n\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\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\tgoto fail;\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\tgoto fail;\n\t\t\t}\n\t\t}\n\t}\n \n\tret = (PyAO *)PyArray_New(self->ob_type,\n\t\t\t\t n, dimensions,\n\t\t\t\t self->descr->type_num,\n\t\t\t\t strides,\n\t\t\t\t self->data,\n\t\t\t\t self->itemsize,\n\t\t\t\t self->flags, (PyObject *)self);\n\t\n\tif (ret== NULL)\n goto fail;\n\t\n Py_INCREF(self);\n ret->base = (PyObject *)self;\n\tPyArray_UpdateFlags(ret, CONTIGUOUS | FORTRAN);\n\t\n return (PyObject *)ret;\n\t\n fail:\n return NULL;\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\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\tret = PyArray_New(self->ob_type, newnd, dimensions, \n\t\t\t self->descr->type_num, strides,\n\t\t\t self->data, self->itemsize, self->flags,\n\t\t\t (PyObject *)self);\n\tself->flags &= ~OWN_DATA;\n\tself->base = (PyObject *)self;\n\tPy_INCREF(self);\n\treturn (PyObject *)ret;\n}\n\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\nstatic PyObject *\nPyArray_Std(PyArrayObject *self, int axis, int rtype)\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\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->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->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\tPyTuple_SET_ITEM(ret, j, item);\n\t\t\tif (item == NULL) goto fail;\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->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\treturn ret;\n\n fail:\n\tPy_XDECREF(ret);\n\tPy_XDECREF(it);\n\treturn NULL;\n \n}\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)) goto fail;\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) goto fail;\n\tret = PyArray_Choose((PyAO *)selector, newtup);\n\tPy_DECREF(selector);\n\tPy_DECREF(newtup);\n\treturn ret;\n\n fail:\n\tPy_XDECREF(res1);\n\tPy_XDECREF(res2);\n\tPy_XDECREF(two);\n\tPy_XDECREF(selector);\n\treturn NULL;\n}\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_Copy(self);\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\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\nstatic PyObject *\nPyArray_Diagonal(PyArrayObject *self, int offset, int axis1, int axis2)\n{\n\tint n = self->nd;\n\tPyObject *new;\n\tPyObject *newaxes;\n\tint i, pos;\t\n\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 = PyTuple_New(n);\n\tif (newaxes==NULL) return NULL;\n\t/* insert at the end */\n\tPyTuple_SET_ITEM(newaxes, n-2, PyInt_FromLong((long)axis1));\n\tPyTuple_SET_ITEM(newaxes, n-1, PyInt_FromLong((long)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->type_num;\n\t\ttypecode.itemsize = self->itemsize;\n\t\ttypecode.fortran = 0;\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\treturn -1;\n\t}\n\tif ((ap = (PyArrayObject*)PyArray_FromAny(*op, &typecode, nd, nd,\n\t\t\t\t\t\t CARRAY_FLAGS)) == NULL)\n\t\treturn -1;\n\tswitch(nd) {\n\tcase 1:\n\t\t*((char **)ptr) = ap->data;\n\t\tbreak;\n\tcase 2:\n\t\tn = ap->dimensions[0];\n\t\tptr2 = (char **)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 ***)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\nstatic int \nPyArray_As1D(PyObject **op, char **ptr, int *d1, int typecode) \n{\n\tintp newd1;\n\t\n\tif (PyArray_AsCArray(op, (void *)ptr, &newd1, 1, typecode) == -1)\n\t\treturn -1;\t\n\t*d1 = (int) newd1;\n\treturn 0;\n}\n\n\nstatic int \nPyArray_As2D(PyObject **op, char ***ptr, int *d1, int *d2, int typecode) \n{\n\tintp newdims[2];\n\n\tif (PyArray_AsCArray(op, (void *)ptr, newdims, 2, typecode) == -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\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\tfree(ptr);\n }\n Py_DECREF(ap);\n return 0;\n}\n\n\nstatic PyObject *\n_swap_and_concat(PyObject *op, int axis, int n)\n{\n\tPyObject *newtup=NULL;\n\tPyObject *otmp, *arr;\n\tint i;\n\n\tnewtup = PyTuple_New(n);\n\tif (newtup==NULL) return NULL;\n\tfor (i=0; i= MAX_DIMS) {\n\t\t\totmp = PyArray_Ravel(mps[i],0);\n\t\t\tPy_DECREF(mps[i]);\n\t\t\tmps[i] = (PyArrayObject *)otmp;\n\t\t}\n\t\tprior2 = PyArray_GetPriority((PyObject *)(mps[i]), 0.0);\n\t\tif (prior2 > prior1) {\n\t\t\tprior1 = prior2;\n\t\t\tsubtype = mps[i]->ob_type;\n\t\t\tret = mps[i];\n\t\t}\n\t}\n\t\n\tnew_dim = 0;\n\tfor(i=0; ind;\n\t\telse {\n\t\t\tif (nd != mps[i]->nd) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"arrays must have same \"\\\n\t\t\t\t\t\t\"number of dimensions\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CompareLists(mps[0]->dimensions+1, \n\t\t\t\t\t\t mps[i]->dimensions+1, \n\t\t\t\t\t\t nd-1)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"array dimensions must \"\\\n\t\t\t\t\t\t\"agree except for d_0\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t}\n\t\tif (nd == 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"0-d arrays can't be concatenated\");\n\t\t\tgoto fail;\n\t\t}\n\t\tnew_dim += mps[i]->dimensions[0];\n\t}\n\t\n\ttmp = mps[0]->dimensions[0];\n\tmps[0]->dimensions[0] = new_dim;\n\tret = (PyArrayObject *)PyArray_New(subtype, nd,\n\t\t\t\t\t mps[0]->dimensions, \n\t\t\t\t\t type_num, NULL, NULL, 0, 0,\n (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 = PyTuple_New(n);\n\tfor (i=0; ind;\n\t\tpermutation = (intp *)malloc(n*sizeof(int));\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\tgoto fail;\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\tret = (PyArrayObject *)PyArray_New(ap->ob_type, n, permutation, \n\t\t\t\t\t ap->descr->type_num, NULL,\n\t\t\t\t\t ap->data, ap->itemsize, ap->flags,\n\t\t\t\t\t (PyObject *)ap);\n\tif (ret == NULL) goto fail;\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);\n\t\n\tif (op && (op != Py_None))\n\t\tPyArray_Free(op, (char *)axes);\n\tfree(permutation);\n\treturn (PyObject *)ret;\n\t\n fail:\n\tPy_XDECREF(ret);\n\tif (permutation != NULL) free(permutation);\n\tif (op != Py_None)\n\t\tPyArray_Free(op, (char *)axes);\n\treturn NULL;\n}\n\nstatic PyObject *\nPyArray_Repeat(PyArrayObject *aop, PyObject *op, int axis) {\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\tret = (PyArrayObject *)PyArray_New(aop->ob_type, aop->nd,\n\t\t\t\t\t aop->dimensions, \n\t\t\t\t\t aop->descr->type_num,\n\t\t\t\t\t NULL, NULL, aop->itemsize, 0,\n\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->itemsize;\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\t/* why not ??? \n\tif (PyTypeNum_ISFLEXIBLE(type_num)) {\n\t\tPyErr_SetString(PyExc_NotImplementedError, \n\t\t\t\t\"not implemented for flexible sizes\");\n\t\treturn NULL;\n\t}\n\t*/\n\tret = (PyArrayObject *)PyArray_New(ap->ob_type, ap->nd,\n\t\t\t\t\t ap->dimensions, type_num,\n\t\t\t\t\t NULL, NULL, 0, 0, (PyObject *)ap);\n\tif (ret == NULL) goto fail;\n\t\n\telsize = ret->itemsize;\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->compare(a,b,global_obj);\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#define SWAPBACK(op, ap) { \\\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\nstatic PyObject *\nPyArray_Sort(PyArrayObject *op, int axis) \n{\n\tPyArrayObject *ap=NULL, *store_arr=NULL;\n\tchar *ip;\n\tint i, n, m, elsize, orign;\n\n\tif ((ap = (PyAO*) _check_axis(op, &axis, 0))==NULL) return NULL;\n\n\tSWAPAXES(op, ap);\n\n\tap = (PyArrayObject *)PyArray_CopyFromObject((PyObject *)op, \n\t\t\t\t\t\t PyArray_NOTYPE,\n\t\t\t\t\t\t 1, 0);\n\tPy_DECREF(op);\n\n\tif (ap == NULL) return NULL;\n\n\tif (ap->descr->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"compare not supported for type\");\n\t\tPy_DECREF(ap);\n\t\treturn NULL;\n\t}\n\t\n\telsize = ap->itemsize;\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; iitemsize;\n\tconst intp *ipa = ip1;\n\tconst intp *ipb = ip2;\t\n\treturn global_obj->descr->compare(global_data + (isize * *ipa),\n global_data + (isize * *ipb), \n\t\t\t\t\t global_obj);\n}\n\nstatic PyObject *\nPyArray_ArgSort(PyArrayObject *op, int axis) \n{\n\tPyArrayObject *ap, *ret, *store;\n\tintp *ip;\n\tintp i, j, n, m, orign;\n\tint argsort_elsize;\n\tchar *store_ptr;\n\n\tif ((ap = (PyAO *)_check_axis(op, &axis, 0))==NULL) return NULL;\n\n\tSWAPAXES(op, ap);\n\n\tap = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)op, \n\t\t\t\t\t\t\t PyArray_NOTYPE,\n\t\t\t\t\t\t\t 1, 0);\n\tPy_DECREF(op);\n\n\tif (ap == NULL) return NULL;\n\t\n\tret = (PyArrayObject *)PyArray_New(ap->ob_type, ap->nd,\n\t\t\t\t\t ap->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, (PyObject *)ap);\n\tif (ret == NULL) goto fail;\n\t\n\tif (ap->descr->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\tip = (intp *)ret->data;\n\targsort_elsize = ap->itemsize;\n\tm = ap->dimensions[ap->nd-1];\n\tif (m == 0) goto finish;\n\n\tn = PyArray_SIZE(ap)/m;\n\tstore_ptr = global_data;\n\tglobal_data = ap->data;\n\tstore = global_obj;\n\tglobal_obj = ap;\n\tfor (i=0; idescr->compare;\n\tintp min_i, max_i, i, j;\n\tint location, elsize = ap1->itemsize;\n\tintp elements = ap1->dimensions[ap1->nd-1];\n\tintp n = PyArray_Size((PyObject *)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\nstatic PyObject *\nPyArray_SearchSorted(PyArrayObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1, *ap2, *ret;\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->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"compare not supported for type\");\n\t\tgoto fail;\n\t}\n\t\n\tlocal_where(ap1, ap2, ret); \n\t\n\tPy_DECREF(ap1);\n\tPy_DECREF(ap2);\n\treturn (PyObject *)ret;\n\t\n fail:\n\tPy_XDECREF(ap1);\n\tPy_XDECREF(ap2);\n\tPy_XDECREF(ret);\n\treturn NULL;\n}\n\n\n\n/* Could perhaps be redone to not make contiguous arrays \n */\n\nstatic PyObject *\nPyArray_InnerProduct(PyObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1, *ap2, *ret;\n\tintp i, j, l, i1, i2, n1, n2;\n\tint typenum;\n\tintp is1, is2, os;\n\tchar *ip1, *ip2, *op;\n\tintp dimensions[MAX_DIMS], nd;\n\tPyArray_DotFunc *dot;\n\tPyTypeObject *subtype;\n double prior1, prior2;\n\t\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\n\t\t\n\tret = NULL;\n\tap1 = (PyArrayObject *)PyArray_ContiguousFromAny(op1, typenum, \n\t\t\t\t\t\t\t 0, 0);\n\tif (ap1 == NULL) return NULL;\n\tap2 = (PyArrayObject *)PyArray_ContiguousFromAny(op2, typenum, \n\t\t\t\t\t\t\t 0, 0);\n\tif (ap2 == NULL) goto fail;\n\t\n\tif (ap1->nd == 0 || ap2->nd == 0) {\n\t\tret = (ap1->nd == 0 ? ap1 : ap2);\n\t\tret = (PyArrayObject *)ret->ob_type->tp_as_number->\\\n\t\t\tnb_multiply((PyObject *)ap1, (PyObject *)ap2);\n\t\tPy_DECREF(ap1);\n\t\tPy_DECREF(ap2);\n\t\treturn (PyObject *)ret;\n\t}\n\t\n\tl = ap1->dimensions[ap1->nd-1];\n\t\n\tif (ap2->dimensions[ap2->nd-1] != l) {\n\t\tPyErr_SetString(PyExc_ValueError, \"matrices are not aligned\");\n\t\tgoto fail;\n\t}\n\t\n\tif (l == 0) n1 = n2 = 0;\n\telse {\n\t\tn1 = PyArray_SIZE(ap1)/l;\n\t\tn2 = PyArray_SIZE(ap2)/l;\n\t}\n\n\tnd = ap1->nd+ap2->nd-2;\n\tj = 0;\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap1->dimensions[i];\n\t}\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap2->dimensions[i];\n\t}\n\n\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n prior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n prior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n subtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n\n\tret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions, \n\t\t\t\t\t typenum, NULL, NULL, 0, 0, \n (PyObject *)\n\t\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n\tif (ret == NULL) goto fail;\n\n\tdot = (ret->descr->dotfunc);\n\t\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"dot not available for this type\");\n\t\tgoto fail;\n\t}\n\n\t\n\tis1 = ap1->strides[ap1->nd-1]; \n\tis2 = ap2->strides[ap2->nd-1];\n\top = ret->data; os = ret->itemsize;\n\t\n\tip1 = ap1->data;\n\tfor(i1=0; i1data;\n\t\tfor(i2=0; i2nd == 0 || ap2->nd == 0) {\n\t\tret = (ap1->nd == 0 ? ap1 : ap2);\n\t\tret = (PyArrayObject *)ret->ob_type->tp_as_number->\\\n\t\t\tnb_multiply((PyObject *)ap1, (PyObject *)ap2);\n\t\tPy_DECREF(ap1);\n\t\tPy_DECREF(ap2);\n\t\treturn (PyObject *)ret;\n\t}\n\t\n\tl = ap1->dimensions[ap1->nd-1];\n\tif (ap2->nd > 1) {\n\t\tmatchDim = ap2->nd - 2;\n\t\totherDim = ap2->nd - 1;\n\t}\n\telse {\n\t\tmatchDim = 0;\n\t\totherDim = 0;\n\t}\n\n\tif (ap2->dimensions[matchDim] != l) {\n\t\tPyErr_SetString(PyExc_ValueError, \"objects are not aligned\");\n\t\tgoto fail;\n\t}\n\t\n\tif (l == 0) n1 = n2 = 0;\n\telse {\n\t\tn1 = PyArray_SIZE(ap1)/l;\n\t\tn2 = PyArray_SIZE(ap2)/l;\n\t}\n\n\tnd = ap1->nd+ap2->nd-2;\n\tj = 0;\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap1->dimensions[i];\n\t}\n\tfor(i=0; ind-2; i++) {\n\t\tdimensions[j++] = ap2->dimensions[i];\n\t}\n\tif(ap2->nd > 1) {\n\t\tdimensions[j++] = ap2->dimensions[ap2->nd-1];\n\t}\n\t/*\n\tfprintf(stderr, \"nd=%d dimensions=\", nd);\n\t for(i=0; i prior1 ? ap2->ob_type : ap1->ob_type);\n\n\tret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions, \n\t\t\t\t\t typenum, NULL, NULL, 0, 0, \n (PyObject *)\n\t\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n\tif (ret == NULL) goto fail;\n\n\tdot = ret->descr->dotfunc;\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"dot not available for this type\");\n\t\tgoto fail;\n\t}\n\t\t\n\tis1 = ap1->strides[ap1->nd-1]; is2 = ap2->strides[matchDim];\n\tif(ap1->nd > 1)\n\t\tis1r = ap1->strides[ap1->nd-2];\n\telse\n\t\tis1r = ap1->strides[ap1->nd-1];\n\tis2r = ap2->strides[otherDim];\n\n\top = ret->data; os = ret->itemsize;\n\n\tip1 = ap1->data;\n\tfor(i1=0; i1data;\n\t\tfor(i2=0; i2ob_type, 2, dims, PyArray_TYPE(arr),\n\t\t\t NULL, NULL, elsize, 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[ap1->nd-1];\n\tn2 = ap2->dimensions[ap2->nd-1];\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 = (int)(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\t\n\tret = (PyArrayObject *)PyArray_New(ap1->ob_type, 1,\n\t\t\t\t\t &length, typenum, \n\t\t\t\t\t NULL, NULL, 0, 0, \n (PyObject *)ap1);\n\tif (ret == NULL) goto fail;\n\n\t\n\tdot = ret->descr->dotfunc;\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"function not available for this type\");\n\t\tgoto fail;\n\t}\n\t\n\tis1 = ap1->strides[ap1->nd-1]; is2 = ap2->strides[ap2->nd-1];\n\top = ret->data; os = ret->itemsize;\n\t\n\tip1 = ap1->data; ip2 = ap2->data+n_left*is2;\n\tn = n-n_left;\n\tfor(i=0; idescr->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->itemsize;\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 ret = (PyArrayObject *)PyArray_New(self->ob_type, nd, shape, \n\t\t\t\t\t self->descr->type_num,\n\t\t\t\t\t NULL, NULL, 0, 0, \n (PyObject *)self);\n\t\n if (ret == NULL) goto fail;\n\t\n max_item = self->dimensions[axis];\n chunk = chunk * ret->itemsize;\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\nstatic PyObject *\nPyArray_Put(PyArrayObject *self, PyObject *indices0, PyObject* values0) \n{\n PyArrayObject *indices, *values;\n int i, chunk, ni, max_item, nv, tmp; \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->itemsize;\n\n indices = (PyArrayObject *)PyArray_ContiguousFromAny(indices0, PyArray_INTP, 0, 0);\n if (indices == NULL) goto fail;\n ni = PyArray_SIZE(indices);\n\n values = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny(values0, self->descr->type_num, \n\t\t\t\t\t 0, 0);\n if (values == NULL) goto fail;\n nv = PyArray_SIZE(values);\n if (nv > 0) { /* nv == 0 for a null array */\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 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\nstatic PyObject *\nPyArray_PutMask(PyArrayObject *self, PyObject *mask0, PyObject* values0) \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->itemsize;\n\n mask = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny(mask0, PyArray_BOOL, 0, 0);\n if (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\t\tfor(i=0; idata + chunk * (i % nv);\n\t\t\ttmp = ((Bool *)(mask->data))[i];\n\t\t\tif (tmp) {\n\t\t\t\tmemmove(dest + i * chunk, src, chunk);\n\t\t\t\tif (thistype == PyArray_OBJECT)\n\t\t\t\t\tPy_INCREF(*((PyObject **)src));\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 \nstatic int \nPyArray_Converter(PyObject *object, PyObject **address) \n{\n if (PyArray_Check(object)) {\n *address = object;\n\t\tPy_INCREF(object);\n return PY_SUCCEED;\n }\n else {\n\t\t*address = PyArray_FromAny(object, NULL, 0, 0, CARRAY_FLAGS);\n\t\tif (*address == NULL) return PY_FAIL;\n\t\treturn PY_SUCCEED;\n }\n}\n\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\nstatic int\nPyArray_TypestrConvert(int itemsize, int gentype)\n{\n\tregister int newtype = gentype;\n\t\n\tif (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\nstatic int\nPyArray_BufferConverter(PyObject *obj, PyArray_Chunk *buf)\n{\n int buflen;\n\n buf->ptr = NULL;\n buf->flags = WRITEABLE;\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\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) goto fail;\n return PY_SUCCEED;\n\n fail:\n\tPyDimMem_FREE(seq->ptr);\n\treturn PY_FAIL;\n}\n\n/* This function takes a Python object representing a type and converts it \n to a C type_num and an itemsize (elements of PyArray_Typecode structure)\n \n Many objects can be used to represent a type.\n */\n\nstatic int\nPyArray_TypecodeConverter(PyObject *obj, PyArray_Typecode *at)\n{\n char *type;\n PyArray_Descr *descr;\n int check_num=PyArray_NOTYPE+10;\n\tint len;\n\tPyObject *item, *attr=NULL;\n\n\tat->itemsize = 0;\n if (obj == Py_None) {\n at->type_num = PyArray_NOTYPE;\n return PY_SUCCEED;\n }\n\n if (PyType_Check(obj) && PyType_IsSubtype((PyTypeObject *)obj, \n &PyGenericArrType_Type)) {\n PyArray_TypecodeFromTypeObject(obj, at);\n return PY_SUCCEED;\n }\n\n\n\t/* type object could be an array */\n\tif (PyArray_Check(obj)) {\n\t\tat->type_num = PyArray_TYPE(obj);\n\t\tat->itemsize = PyArray_ITEMSIZE(obj);\n\t\treturn PY_SUCCEED;\n\t}\n\n\t/* or an array scalar */\n if (PyArray_IsScalar(obj, Generic)) {\n PyArray_TypecodeFromScalar(obj, at);\n return PY_SUCCEED;\n }\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);\t\t\n\t\tif (len > 0) {\n\t\t\tcheck_num = (int) type[0];\n\t\t}\n\t\tif (len > 1) {\n\t\t\tat->itemsize = atoi(type+1);\n\t\t\t/* When specifying length of UNICODE\n\t\t\t the number of characters is given to match \n\t\t\t the STRING interface. Each character can be\n\t\t\t more than one byte and itemsize must be\n\t\t\t the number of bytes.\n\t\t\t*/\n\t\t\tif (check_num == PyArray_UNICODELTR ||\t\\\n\t\t\t check_num == PyArray_UNICODE) \n\t\t\t at->itemsize *= sizeof(Py_UNICODE);\n\n\t\t\t/* Support for generic processing */\n\t\t\telse if ((check_num != PyArray_STRINGLTR) &&\n\t\t\t\t (check_num != PyArray_VOIDLTR) &&\n\t\t\t\t (check_num != PyArray_STRING) &&\n\t\t\t\t (check_num != PyArray_VOID)) {\n\t\t\t\tcheck_num = \\\n\t\t\t\t\tPyArray_TypestrConvert(at->itemsize,\n\t\t\t\t\t\t\t check_num);\n\t\t\t at->itemsize = 0;\n\t\t\t\tif (check_num == PyArray_NOTYPE) goto fail;\n\t\t\t}\n\t\t}\n\t}\n\t/* Arbitray object with dtypechar and itemsize attributes. */\n\telse if (PyObject_HasAttrString(obj, \"dtypechar\") && \n\t\t PyObject_HasAttrString(obj, \"itemsize\")) {\n\t\tattr = PyObject_GetAttrString(obj, \"dtypechar\");\n\t\tif (attr && PyString_GET_SIZE(attr) > 0) {\n\t\t\ttype = PyString_AsString(attr);\n\t\t\tcheck_num = (int) type[0];\n\t\t}\n\t\tPy_XDECREF(attr);\n\t\tif (!PyErr_Occurred()) {\n\t\t\tattr = PyObject_GetAttrString(obj, \"itemsize\");\n\t\t\tat->itemsize = PyInt_AsLong(attr);\n\t\t\tPy_XDECREF(attr);\n\t\t}\t\t\t\n\t}\t\t\n\telse if (PyType_Check(obj)) {\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 *)(&PyBool_Type))\n\t\t\tcheck_num = PyArray_BOOL;\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 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}\t\n else { /* Default -- try integer conversion */\n\t\t/* Don't allow integer conversion */\n /* check_num = PyInt_AsLong(obj); */\n\t\t/* fprintf(stderr, \"****\\n\\ntype=%s\\n\\n****\\n\", \n\t\t\tobj->ob_type->tp_name);\n\t\t*/\n\t\tgoto fail;\n\t}\n\n\tif (PyErr_Occurred()) goto fail;\n\n\t/*\n\tif (check_num == PyArray_NOTYPE) return PY_FAIL;\n\t*/\n\tif (check_num == PyArray_NOTYPE) {\n\t\tat->type_num = PyArray_NOTYPE;\n\t\tat->itemsize = 0;\n\t\treturn PY_SUCCEED;\n\t}\n\n if ((descr = PyArray_DescrFromType(check_num))==NULL) {\n\t\t/* Now check to see if the object is registered\n\t\t in typeDict */\n\t\tif (typeDict != NULL) {\n\t\t\titem = PyDict_GetItem(typeDict, obj);\n\t\t\tif (item) {\n\t\t\t\tPyArray_TypecodeFromTypeObject(obj, at);\n\t\t\t\tPyErr_Clear();\n\t\t\t\treturn PY_SUCCEED;\n\t\t\t}\n\t\t}\n return PY_FAIL;\n\t}\n\t\n at->type_num = descr->type_num;\n\tif (at->itemsize == 0) at->itemsize = descr->elsize;\n\t\n return PY_SUCCEED;\n\n fail:\n\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\"data type not understood\");\n\treturn PY_FAIL;\n}\t\n\n\n/* This function returns true if the two typecodes are \n equivalent (same basic kind and same itemsize).\n*/\n\nstatic Bool\nPyArray_EquivalentTypes(PyArray_Typecode *typ1, PyArray_Typecode *typ2)\n{\n\tregister int typenum1=typ1->type_num;\n\tregister int typenum2=typ2->type_num;\n\tregister int size1=typ1->itemsize;\n\tregister int size2=typ2->itemsize;\n\n\tif (size1 != size2) return FALSE;\n\tif (typenum1==typenum2) return TRUE;\n\n\t/* If we are here then size1 == size2 */\n\tif (typenum1 < PyArray_FLOAT) {\n\t\tif (PyTypeNum_ISBOOL(typenum1))\n\t\t\treturn (Bool)(PyTypeNum_ISBOOL(typenum2));\n\t\telse if (PyTypeNum_ISUNSIGNED(typenum1))\n\t\t\treturn (Bool)(PyTypeNum_ISUNSIGNED(typenum2));\n\t\telse \n\t\t\treturn (Bool)(PyTypeNum_ISSIGNED(typenum2));\n\t}\n\telse {\n\t\tif (PyTypeNum_ISFLOAT(typenum1))\n\t\t\treturn (Bool)(PyTypeNum_ISFLOAT(typenum2));\n\t\telse if (PyTypeNum_ISCOMPLEX(typenum1))\n\t\t\treturn (Bool)(PyTypeNum_ISCOMPLEX(typenum2));\n\t}\n\t/* Default size1 != size2 and typenum1 != typenum2 */\n\treturn FALSE;\t\n}\n\nstatic Bool \nPyArray_EquivArrTypes(PyArrayObject *a1, PyArrayObject *a2)\n{\n PyArray_Typecode type1={0,0,0};\n PyArray_Typecode type2={0,0,0};\n\n\ttype1.type_num = PyArray_TYPE(a1);\n\ttype2.type_num = PyArray_TYPE(a2);\n\ttype1.itemsize = PyArray_ITEMSIZE(a1);\n\ttype2.itemsize = PyArray_ITEMSIZE(a2);\n\t\t\t\n return PyArray_EquivalentTypes(&type1, &type2);\n}\n\n/* All flexible types of the same typenum seen as equivalent */\nstatic Bool\nPyArray_EquivalentTypenums(int typenum1, int typenum2)\n{\n\tPyArray_Typecode type1={0,0,0};\n\tPyArray_Typecode type2={0,0,0};\n\t\n\ttype1.type_num = typenum1;\n\ttype2.type_num = typenum2;\n\ttype1.itemsize = PyArray_DescrFromType(typenum1)->elsize;\n\ttype2.itemsize = PyArray_DescrFromType(typenum2)->elsize;\n\t\n\treturn PyArray_EquivalentTypes(&type1, &type2);\n}\n\n\n/*** END C-API FUNCTIONS **/\n\n\n#define _ARET(x) PyArray_Return((PyArrayObject *)(x))\n\nstatic char doc_fromobject[] = \"array(object, dtype=None, copy=1, fortran=0, \"\\\n \"subok=0)\\n\"\\\n \"will return a new array formed from the given object type given.\\n\"\\\n \"Object can anything with an __array__ method, or any object\\n\"\\\n \"exposing the array interface, or any (nested) sequence.\\n\"\\\n \"If no type is given, then the type will be determined as the\\n\"\\\n \"minimum type required to hold the objects in the sequence.\\n\"\\\n \"If copy is zero and sequence is already an array with the right \\n\"\\\n \"type, a reference will be returned. If the sequence is an array,\\n\"\\\n \"type can be used only to upcast the array. For downcasting \\n\"\\\n \"use .astype(t) method. If subok is true, then subclasses of the\\n\"\\\n \"array may be returned. Otherwise, a base-class ndarray is returned\";\n\nstatic PyObject *\n_array_fromobject(PyObject *ignored, PyObject *args, PyObject *kws)\n{\n\tPyObject *op, *ret=NULL;\n\tstatic char *kwd[]= {\"object\", \"dtype\", \"copy\", \"fortran\", \"subok\", \n NULL};\n Bool subok=FALSE;\n\tBool copy=TRUE;\n\tPyArray_Typecode type = {PyArray_NOTYPE, 0, 0};\n\tPyArray_Typecode oldtype = {PyArray_NOTYPE, 0, 0};\n\tint type_num;\n\tBool fortran=FALSE;\n\tint flags=0;\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kws, \"O|O&O&O&O&\", kwd, &op, \n\t\t\t\t\tPyArray_TypecodeConverter,\n &type, \n\t\t\t\t\tPyArray_BoolConverter, ©, \n\t\t\t\t\tPyArray_BoolConverter, &fortran,\n PyArray_BoolConverter, &subok)) \n\t\treturn NULL;\n\ttype_num = type.type_num;\n\n\t/* fast exit if simple call */\n\tif ((PyArray_CheckExact(op) && PyBigArray_CheckExact(op)) && \\\n (copy==0) && \\\n\t (fortran == PyArray_CHKFLAGS(op, FORTRAN))) {\n\t\tif (type_num == PyArray_NOTYPE) {\n\t\t\tPy_INCREF(op);\n\t\t\treturn op;\n\t\t}\n\t\t/* One more chance */\n\t\toldtype.type_num = PyArray_TYPE(op);\n\t\toldtype.itemsize = PyArray_ITEMSIZE(op);\n\t\tif (PyArray_EquivalentTypes(&oldtype, &type)) {\n\t\t\tPy_INCREF(op);\n\t\t\treturn op;\n\t\t}\n\t}\n\n\ttype.fortran = fortran; \n\tif (copy) {\n\t\tflags = ENSURECOPY;\n\t}\n if (!subok) {\n flags |= ENSUREARRAY;\n }\n\n\tif ((ret = PyArray_FromAny(op, &type, 0, 0, flags)) == NULL) \n\t\treturn NULL;\n\n\treturn ret;\n}\n\nstatic PyObject *\nPyArray_Empty(int nd, intp *dims, PyArray_Typecode *type)\n{\n\tPyArrayObject *ret;\n\tintp n;\n \n\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, nd, dims, \n\t\t\t\t\t type->type_num,\n\t\t\t\t\t NULL, NULL, type->itemsize, \n\t\t\t\t\t type->fortran, NULL);\n\tif (ret == NULL) return NULL;\n \n\tn = PyArray_SIZE(ret);\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=intp,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_Typecode typecode = {PyArray_NOTYPE, 0, 0};\n PyArray_Dims shape;\n\tBool fortran = FALSE;\t\n PyObject *ret;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &shape, \n PyArray_TypecodeConverter,\n\t\t\t\t\t &typecode, \n\t\t\t\t\t PyArray_BoolConverter, &fortran)) \n\t\treturn NULL;\n\t\n\ttypecode.fortran = fortran;\n if (typecode.type_num ==PyArray_NOTYPE) \n\t\ttypecode.type_num = PyArray_INTP;\n \n\tret = PyArray_Empty(shape.len, shape.ptr, &typecode); \n PyDimMem_FREE(shape.ptr);\n return ret;\n}\n\nstatic char doc_scalar[] = \"scalar(dtypestr,obj) will return a new scalar array of the given type initialized with obj. Mainly for pickle support. typestr must be a valid data typestr (complete with < > or |). If dtypestr is object, 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[] = {\"dtypestr\",\"obj\", NULL};\n\tPyArray_Typecode typecode;\n\tPyObject *obj=NULL;\n\tchar *typestr;\n\tint typestrlen;\n\tint swap, alloc=0;\n\tvoid *dptr;\n\tPyObject *ret;\n\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"z#|O\",\n\t\t\t\t\t kwlist, &typestr, &typestrlen,\n\t\t\t\t\t &obj)) \n\t\treturn NULL;\n\t\n\tif (_array_typecode_fromstr(typestr, &swap, &typecode) < 0) \n\t\treturn NULL;\n\t\n\tif (typecode.itemsize == 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\tswap = 0;\n\t}\n\telse {\n\t\tif (obj == NULL) {\n\t\t\tdptr = malloc(typecode.itemsize);\n\t\t\tif (dptr == NULL) {\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tmemset(dptr, '\\0', typecode.itemsize);\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.itemsize) {\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.type_num,\n\t\t\t typecode.itemsize, swap); \n\n\t/* free dptr which contains zeros */\n\tif (alloc) free(dptr);\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_Zeros(int nd, intp *dims, PyArray_Typecode *type)\n{\n\tPyArrayObject *ret;\n\tintp n;\n\n\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, nd, dims, \n\t\t\t\t\t type->type_num,\n\t\t\t\t\t NULL, NULL, type->itemsize, \n\t\t\t\t\t type->fortran, NULL);\n\tif (ret == NULL) return NULL;\n \n\tn = PyArray_SIZE(ret);\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 {\t\t\n\t\tmemset(ret->data, 0, n*(ret->itemsize));\n\t}\n\treturn (PyObject *)ret;\n\n}\n\nstatic char doc_zeros[] = \"zeros((d1,...,dn),dtype=intp,fortran=0) will return a new array of shape (d1,...,dn) and type typecode with all it's entries initialized to zero.\";\n\n\nstatic PyObject *\narray_zeros(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {\"shape\",\"dtype\",\"fortran\",NULL};\n\tPyArray_Typecode typecode = {PyArray_NOTYPE, 0, 0};\n PyArray_Dims shape;\n\tBool fortran = FALSE;\t\n PyObject *ret;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &shape, \n PyArray_TypecodeConverter,\n\t\t\t\t\t &typecode, \n\t\t\t\t\t PyArray_BoolConverter,\n\t\t\t\t\t &fortran)) \n\t\treturn NULL;\n\t\n\ttypecode.fortran = fortran;\n if (typecode.type_num ==PyArray_NOTYPE) \n\t\ttypecode.type_num = PyArray_INTP;\n \n\tret = PyArray_Zeros(shape.len, shape.ptr, &typecode); \n PyDimMem_FREE(shape.ptr);\n return 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 char doc_fromString[] = \"fromstring(string, dtype=intp, count=-1, swap=False) 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\tPyArrayObject *ret; \n\tchar *data;\n\tlonglong nin=-1;\n\tintp s, n;\n\tstatic char *kwlist[] = {\"string\", \"dtype\", \"count\", \"swap\",NULL};\n\tPyArray_Typecode type = {PyArray_INTP, sizeof(intp), 0};\n\tint itemsize;\n\tint swapped=FALSE;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"s#|O&LO&\", kwlist, \n\t\t\t\t\t &data, &s, \n\t\t\t\t\t PyArray_TypecodeConverter, &type,\n\t\t\t\t\t &nin, \n\t\t\t\t\t PyArray_BoolConverter,\n\t\t\t\t\t &swapped)) {\n\t\treturn NULL;\n\t}\n\t\n\tn = (intp) nin;\n\n\titemsize = type.itemsize;\n\tif (itemsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \"zero-valued itemsize\");\n\t\treturn NULL;\n\t}\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\"string size must be a multiple\"\\\n\t\t\t\t\t\" of element size\");\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\"string is smaller than requested\"\\\n\t\t\t\t\t\" size\");\n\t\t\treturn NULL;\n\t\t}\n\t}\n\n\tif ((ret = (PyArrayObject *)PyArray_New(&PyArray_Type, 1, &n, \n\t\t\t\t\t\ttype.type_num, NULL, \n\t\t\t\t\t\tNULL, itemsize, 0,\n\t\t\t\t\t\tNULL)) == NULL)\n\t\treturn NULL;\n\t\t\n\tmemcpy(ret->data, data, n*ret->itemsize);\n\tif (swapped) ret->flags &= ~NOTSWAPPED;\n\tPyArray_INCREF(ret);\n\treturn (PyObject *)ret;\n}\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\nstatic int\n_fill_in_itemsize(PyArray_Typecode *typecode)\n{\n\tPyArray_Descr *descr;\n\tdescr = PyArray_DescrFromType(typecode->type_num);\n\tif (descr==NULL) return -1;\n\ttypecode->itemsize = descr->elsize;\n\treturn 0;\n}\n\n\nstatic PyObject *\nPyArray_FromFile(FILE *fp, PyArray_Typecode *typecode, intp num, char *sep)\n{\n\tPyArrayObject *r;\n\tsize_t nread = 0;\n\tPyArray_ScanFunc *scan;\n\n\tif (typecode->itemsize == 0) {\n\t\tif (_fill_in_itemsize(typecode) < 0) \n\t\t\treturn NULL;\n\t}\n\n\tif (num == -1 && sep == NULL) { /* 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\tfseek(fp, (long) start, SEEK_SET);\n\t\tif (numbytes == -1) {\n\t\t\tPyErr_SetString(PyExc_IOError, \"could not seek in file\");\n\t\t\treturn NULL;\n\t\t}\n\t\tif (typecode->itemsize == 0) {\n\t\t\ttypecode->itemsize = numbytes;\n\t\t\tnum = 1;\n\t\t}\n\t\telse {\n\t\t\tnum = numbytes / typecode->itemsize;\n\t\t}\n\t}\n\t\n\tif (sep==NULL) { /* binary data */\n\t\tr = (PyArrayObject *)PyArray_New(&PyArray_Type, 1, &num, \n\t\t\t\t\t\t typecode->type_num,\n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t typecode->itemsize, 0, NULL);\n\t\tif (r==NULL) return NULL;\n\t\tnread = fread(r->data, typecode->itemsize, 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 = PyArray_DescrFromType(typecode->type_num)->scanfunc;\n\t\tif (scan == NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"don't know how to read \"\t\\\n\t\t\t\t\t\"character files with that \"\t\\\n\t\t\t\t\t\"array type\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (num != -1) { /* number to read is known */\n\t\t\tr = (PyArrayObject *)PyArray_New(&PyArray_Type, 1, \n\t\t\t\t\t\t\t &num, \n\t\t\t\t\t\t\t typecode->type_num,\n\t\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t\t typecode->itemsize, \n\t\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, r->itemsize, sep, NULL);\n\t\t\t\tif (done < -2) break;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += r->itemsize;\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 *)PyArray_New(&PyArray_Type, 1, \n\t\t\t\t\t\t\t &size, \n\t\t\t\t\t\t\t typecode->type_num,\n\t\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t\t typecode->itemsize, \n\t\t\t\t\t\t\t 0, NULL);\n\t\t\tif (r==NULL) return NULL;\n\t\t\ttotalbytes = bytes = size * typecode->itemsize;\n\t\t\tdptr = r->data;\n\t\t\twhile (!done) {\n\t\t\t\tdone = scan(fp, dptr, r->itemsize, 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->itemsize;\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->itemsize);\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->itemsize);\n\t\tPyArray_DIM(r,0) = nread;\n\t}\n\treturn (PyObject *)r;\n}\n\nstatic char doc_fromfile[] = \\\n\t\"fromfile(file=, dtype=intp, count=-1, sep='')\\n\"\\\n\t\"\\n\"\\\n\t\" Return an array of the given data type from a \\n\"\\\n\t\" (text or binary) file. The file argument can be an open file\\n\"\\\n\t\" or a string with the name of a file to read from. If\\n\"\\\n\t\" count==-1, then the entire file is read, otherwise count is\\n\"\\\n\t\" the number of items of the given type read in. If sep is ''\\n\"\\\n\t\" then read a binary file, otherwise it gives the separator\\n\"\\\n\t\" between elements in a text file.\\n\"\\\n\t\"\\n\"\\\n\t\" WARNING: This function should be used sparingly, as it is not\\n\"\\\n\t\" a robust method of persistence. But it can be useful to\\n\"\\\n\t\" read in simply-formatted or binary data quickly.\";\n\nstatic PyObject *\narray_fromfile(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tPyObject *file=NULL, *ret;\n\tFILE *fp;\n\tchar *sep=\"\";\n\tchar *mode=NULL;\n\tlonglong nin=-1;\n\tstatic char *kwlist[] = {\"file\", \"dtype\", \"count\", \"sep\", NULL};\n\tPyArray_Typecode type = {PyArray_INTP, sizeof(intp), 0};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"O|O&Ls\", kwlist, \n\t\t\t\t\t &file,\n\t\t\t\t\t PyArray_TypecodeConverter, &type,\n\t\t\t\t\t &nin, &sep)) {\n\t\treturn NULL;\n\t}\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, \"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\nstatic PyObject *\nPyArray_FromBuffer(PyObject *buf, PyArray_Typecode *type, \n\t\t intp count, int swapped) \n{\n\tPyArrayObject *ret;\n\tchar *data;\n\tint ts;\n\tintp s, n;\n\tint itemsize;\n\tint write=1;\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\treturn NULL;\n\t}\n\tif (type->itemsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"itemsize cannot be zero in type\");\n\t\treturn NULL;\n\t}\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\treturn NULL;\n\t\t}\n\t}\n\ts = (intp)ts;\t\n\tn = (intp)count;\n\titemsize = type->itemsize;\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\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\treturn NULL;\n\t\t}\n\t}\n\t\n\tif ((ret = (PyArrayObject *)PyArray_New(&PyArray_Type, 1, &n, \n\t\t\t\t\t\ttype->type_num, NULL, \n\t\t\t\t\t\tdata, itemsize, DEFAULT_FLAGS,\n\t\t\t\t\t\tNULL)) == NULL)\n\t\treturn NULL;\n\t\n\tif (!write) ret->flags &= ~WRITEABLE;\n\tif (swapped) ret->flags &= ~NOTSWAPPED;\n\tPy_INCREF(buf);\n\t/* Store a reference for decref on deallocation */\n\tret->base = buf;\n\tPyArray_UpdateFlags(ret, ALIGNED);\n\treturn (PyObject *)ret; \t\n}\n\nstatic char doc_frombuffer[] = \\\n\t\"frombuffer(buffer=, dtype=intp, count=-1, swap=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 the buffer has data that is out\\n\" \\\n\t\" not in machine byte-order, than set swap=1. 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;\n\tstatic char *kwlist[] = {\"buffer\", \"dtype\", \"count\", \n\t\t\t\t \"swap\", NULL};\n\tPyArray_Typecode type = {PyArray_INTP, sizeof(intp), 0};\n\tint swapped=0;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"O|O&Li\", kwlist, \n\t\t\t\t\t &obj,\n\t\t\t\t\t PyArray_TypecodeConverter, &type,\n\t\t\t\t\t &nin, &swapped)) {\n\t\treturn NULL;\n\t}\n\n\treturn PyArray_FromBuffer(obj, &type, (intp)nin, swapped);\n}\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\nstatic PyObject *\nPyArray_Arange(double start, double stop, double step, int type_num)\n{\n\tintp length, i;\n\tPyObject *range;\n\tchar *rptr;\n\tint elsize, type;\n\tdouble value;\n\tPyArray_Descr *dbl_descr;\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\tdbl_descr = PyArray_DescrFromType(PyArray_DOUBLE);\n \n\trptr = ((PyArrayObject *)range)->data;\n\telsize = ((PyArrayObject *)range)->itemsize;\n\ttype = ((PyArrayObject *)range)->descr->type_num;\n\tfor (i=0; i < length; i++) {\n\t\tvalue = start + i*step;\n\t\tdbl_descr->cast[type]((char*)&value, rptr, 1, NULL, \n\t\t\t\t (PyArrayObject *)range);\n\t\trptr += elsize;\n\t}\n \n\treturn range;\n}\n\n\nstatic char doc_arange[] = \"arange(start, stop=None, step=1, dtype=intp)\\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=Py_None, *o_step=NULL;\n\tstatic char *kwd[]= {\"start\", \"stop\", \"step\", \"dtype\", NULL};\n\tdouble start, stop, step;\n\tPyArray_Typecode typecode = {PyArray_NOTYPE, 0};\n\tint type_num;\n\tint deftype = PyArray_INTP;\n\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_TypecodeConverter, \n\t\t\t\t\t&typecode)) \n\t\treturn NULL;\n\n\tdeftype = PyArray_ObjectType(o_start, deftype);\n\tif (o_stop != Py_None) {\n\t\tdeftype = PyArray_ObjectType(o_stop, deftype);\n\t}\n\tif (o_step != NULL) {\n\t\tdeftype = PyArray_ObjectType(o_step, deftype);\n\t}\n\n\ttype_num = typecode.type_num;\n\tif (type_num == PyArray_NOTYPE) {\n\t\ttype_num = deftype;\n\t}\n\n\tstart = PyFloat_AsDouble(o_start);\n\tif error_converting(start) return NULL;\n\n\tif (o_step == NULL) {\n\t\tstep = 1;\n\t}\n\telse {\n\t\tstep = PyFloat_AsDouble(o_step);\n\t\tif error_converting(step) return NULL;\n\t}\n\n\tif (o_stop == Py_None) {\n\t\tstop = start;\n\t\tstart = 0;\n\t}\n\telse {\n\t\tstop = PyFloat_AsDouble(o_stop);\n\t\tif error_converting(stop) return NULL;\n\t}\n\n\treturn PyArray_Arange(start, stop, step, type_num);\n}\n\n#undef _ARET\n\n/*****\n static char doc_arrayMap[] = \"arrayMap(func, [a1,...,an])\";\n\n static PyObject *array_arrayMap(PyObject *dummy, PyObject *args) {\n PyObject *shape, *a0;\n \n if (PyArg_ParseTuple(args, \"OO\", &a0, &shape) == NULL) return NULL;\n\t\n return PyArray_Map(a0, shape);\n }\n*****/\n\nstatic char \ndoc_set_string_function[] = \"set_string_function(f, repr=1) sets the python function f to be the function used to obtain a pretty printable string version of a array whenever a array is printed. f(M) should expect a array argument M, and should return a string consisting of the desired representation of M for printing.\";\n\nstatic PyObject *\narray_set_string_function(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tPyObject *op;\n\tint repr=1;\n\tstatic char *kwlist[] = {\"f\", \"repr\", NULL};\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"O|i\", kwlist, \n\t\t\t\t\t&op, &repr)) return NULL; \n\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 (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\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\tif ((x==NULL) || (y==NULL)) {\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\tarr = (PyArrayObject *)PyArray_FromAny(condition, NULL, 0, 0, 0);\n\tif (arr == NULL) return NULL;\n\n\tif ((x==NULL) && (y==NULL)) {\n\t\tret = PyArray_Nonzero(arr);\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\n\tzero = PyInt_FromLong((long) 0);\n\n\tobj = PyArray_EnsureArray(PyArray_GenericBinaryFunction(arr, zero, n_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_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_Typecode d1={PyArray_NOTYPE, 0, 0};\n\tPyArray_Typecode d2={PyArray_NOTYPE, 0, 0};\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_TypecodeConverter, &d1,\n\t\t\t\t\tPyArray_TypecodeConverter, &d2))\n\t\treturn NULL;\n\tif (d1.type_num == PyArray_NOTYPE || \\\n\t d2.type_num == PyArray_NOTYPE) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"did not understand one of the types; \"\\\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 struct PyMethodDef array_module_methods[] = {\n\t{\"set_string_function\", (PyCFunction)array_set_string_function, \n\t METH_VARARGS|METH_KEYWORDS, doc_set_string_function},\n\t{\"set_numeric_ops\", (PyCFunction)array_set_ops_function,\n\t METH_VARARGS|METH_KEYWORDS, doc_set_ops_function},\n\t{\"set_typeDict\", (PyCFunction)array_set_typeDict,\n\t METH_VARARGS, doc_set_typeDict},\n\n\t{\"array\",\t(PyCFunction)_array_fromobject, \n\t METH_VARARGS|METH_KEYWORDS, doc_fromobject},\n\t{\"arange\", (PyCFunction)array_arange, \n\t METH_VARARGS|METH_KEYWORDS, doc_arange},\n\t{\"zeros\",\t(PyCFunction)array_zeros, \n\t METH_VARARGS|METH_KEYWORDS, doc_zeros},\n\t{\"empty\",\t(PyCFunction)array_empty, \n\t METH_VARARGS|METH_KEYWORDS, doc_empty},\n\t{\"scalar\", (PyCFunction)array_scalar,\n\t METH_VARARGS|METH_KEYWORDS, doc_scalar},\n\t{\"where\", (PyCFunction)array_where,\n\t METH_VARARGS, doc_where},\n\t{\"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/* {\"arrayMap\",\t(PyCFunction)array_arrayMap, \n\t METH_VARARGS, doc_arrayMap},*/\n\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(Numeric, Generic);\n SINGLE_INHERIT(Integer, Numeric);\n SINGLE_INHERIT(Inexact, Numeric);\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 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 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 SINGLE_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\t \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, \"NOTSWAPPED\", s=PyInt_FromLong(NOTSWAPPED));\n Py_DECREF(s);\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\tif (PyType_Ready(&PyArrayIter_Type) < 0)\n\t\treturn; \n \n\tif (PyType_Ready(&PyArrayMapIter_Type) < 0)\n return; \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\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) \n return; /* otherwise there is an error */\n\n\n err:\t\n\t/* Check for errors */\n\tif (PyErr_Occurred())\n PyErr_Print();\n\t\tPy_FatalError(\"can't initialize module multiarray\");\n\n\treturn;\n}\n\n", "methods": [ { "name": "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": 51, "end_line": 56, "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": 59, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "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": 68, "end_line": 80, "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": 83, "end_line": 90, "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_Typecode * type)", "filename": "multiarraymodule.c", "nloc": 42, "complexity": 9, "token_count": 245, "parameters": [ "self", "type" ], "start_line": 93, "end_line": 141, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "PyArray_Ravel", "long_name": "PyArray_Ravel( PyArrayObject * a , int fortran)", "filename": "multiarraymodule.c", "nloc": 14, "complexity": 4, "token_count": 87, "parameters": [ "a", "fortran" ], "start_line": 144, "end_line": 158, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "PyArray_Flatten", "long_name": "PyArray_Flatten( PyArrayObject * a , int fortran)", "filename": "multiarraymodule.c", "nloc": 32, "complexity": 5, "token_count": 162, "parameters": [ "a", "fortran" ], "start_line": 161, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "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": 202, "end_line": 211, "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": 214, "end_line": 240, "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": 75, "complexity": 17, "token_count": 411, "parameters": [ "self", "newdims" ], "start_line": 248, "end_line": 339, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 92, "top_nesting_level": 0 }, { "name": "PyArray_Squeeze", "long_name": "PyArray_Squeeze( PyArrayObject * self)", "filename": "multiarraymodule.c", "nloc": 30, "complexity": 4, "token_count": 192, "parameters": [ "self" ], "start_line": 347, "end_line": 378, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "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": 382, "end_line": 403, "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)", "filename": "multiarraymodule.c", "nloc": 43, "complexity": 12, "token_count": 433, "parameters": [ "self", "axis", "rtype" ], "start_line": 406, "end_line": 461, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 56, "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": 465, "end_line": 475, "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": 478, "end_line": 488, "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": 491, "end_line": 501, "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": 504, "end_line": 515, "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": 518, "end_line": 529, "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": 532, "end_line": 543, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_Compress", "long_name": "PyArray_Compress( PyArrayObject * self , PyObject * condition , int axis)", "filename": "multiarraymodule.c", "nloc": 18, "complexity": 3, "token_count": 110, "parameters": [ "self", "condition", "axis" ], "start_line": 547, "end_line": 567, "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": 50, "complexity": 13, "token_count": 403, "parameters": [ "self" ], "start_line": 570, "end_line": 628, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 59, "top_nesting_level": 0 }, { "name": "PyArray_Clip", "long_name": "PyArray_Clip( PyArrayObject * self , PyObject * min , PyObject * max)", "filename": "multiarraymodule.c", "nloc": 30, "complexity": 6, "token_count": 241, "parameters": [ "self", "min", "max" ], "start_line": 631, "end_line": 664, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "top_nesting_level": 0 }, { "name": "PyArray_Conjugate", "long_name": "PyArray_Conjugate( PyArrayObject * self)", "filename": "multiarraymodule.c", "nloc": 36, "complexity": 9, "token_count": 225, "parameters": [ "self" ], "start_line": 667, "end_line": 703, "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": 706, "end_line": 716, "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": 106, "complexity": 24, "token_count": 808, "parameters": [ "self", "offset", "axis1", "axis2" ], "start_line": 719, "end_line": 840, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 122, "top_nesting_level": 0 }, { "name": "PyArray_AsCArray", "long_name": "PyArray_AsCArray( PyObject ** op , * ptr , intp * dims , int nd , int type_num)", "filename": "multiarraymodule.c", "nloc": 55, "complexity": 13, "token_count": 432, "parameters": [ "op", "ptr", "dims", "nd", "type_num" ], "start_line": 857, "end_line": 913, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 57, "top_nesting_level": 0 }, { "name": "PyArray_As1D", "long_name": "PyArray_As1D( PyObject ** op , char ** ptr , int * d1 , int typecode)", "filename": "multiarraymodule.c", "nloc": 8, "complexity": 2, "token_count": 60, "parameters": [ "op", "ptr", "d1", "typecode" ], "start_line": 918, "end_line": 926, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "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": 9, "complexity": 2, "token_count": 81, "parameters": [ "op", "ptr", "d1", "d2", "typecode" ], "start_line": 930, "end_line": 940, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "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": 945, "end_line": 956, "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": 960, "end_line": 988, "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": 114, "complexity": 24, "token_count": 771, "parameters": [ "op", "axis" ], "start_line": 997, "end_line": 1125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 129, "top_nesting_level": 0 }, { "name": "PyArray_SwapAxes", "long_name": "PyArray_SwapAxes( PyArrayObject * ap , int a1 , int a2)", "filename": "multiarraymodule.c", "nloc": 37, "complexity": 12, "token_count": 227, "parameters": [ "ap", "a1", "a2" ], "start_line": 1128, "end_line": 1167, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 }, { "name": "PyArray_Transpose", "long_name": "PyArray_Transpose( PyArrayObject * ap , PyObject * op)", "filename": "multiarraymodule.c", "nloc": 49, "complexity": 16, "token_count": 405, "parameters": [ "ap", "op" ], "start_line": 1171, "end_line": 1230, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 60, "top_nesting_level": 0 }, { "name": "PyArray_Repeat", "long_name": "PyArray_Repeat( PyArrayObject * aop , PyObject * op , int axis)", "filename": "multiarraymodule.c", "nloc": 75, "complexity": 15, "token_count": 520, "parameters": [ "aop", "op", "axis" ], "start_line": 1233, "end_line": 1325, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 93, "top_nesting_level": 0 }, { "name": "PyArray_Choose", "long_name": "PyArray_Choose( PyArrayObject * ip , PyObject * op)", "filename": "multiarraymodule.c", "nloc": 89, "complexity": 18, "token_count": 650, "parameters": [ "ip", "op" ], "start_line": 1329, "end_line": 1441, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 113, "top_nesting_level": 0 }, { "name": "qsortCompare", "long_name": "qsortCompare( const * a , const * b)", "filename": "multiarraymodule.c", "nloc": 4, "complexity": 1, "token_count": 28, "parameters": [ "a", "b" ], "start_line": 1449, "end_line": 1452, "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)", "filename": "multiarraymodule.c", "nloc": 36, "complexity": 7, "token_count": 250, "parameters": [ "op", "axis" ], "start_line": 1474, "end_line": 1523, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "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": 63, "parameters": [ "ip1", "ip2" ], "start_line": 1529, "end_line": 1537, "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)", "filename": "multiarraymodule.c", "nloc": 48, "complexity": 8, "token_count": 350, "parameters": [ "op", "axis" ], "start_line": 1540, "end_line": 1599, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 60, "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": 1602, "end_line": 1637, "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": 223, "parameters": [ "op1", "op2" ], "start_line": 1640, "end_line": 1685, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 46, "top_nesting_level": 0 }, { "name": "PyArray_InnerProduct", "long_name": "PyArray_InnerProduct( PyObject * op1 , PyObject * op2)", "filename": "multiarraymodule.c", "nloc": 83, "complexity": 17, "token_count": 657, "parameters": [ "op1", "op2" ], "start_line": 1693, "end_line": 1796, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 104, "top_nesting_level": 0 }, { "name": "PyArray_MatrixProduct", "long_name": "PyArray_MatrixProduct( PyObject * op1 , PyObject * op2)", "filename": "multiarraymodule.c", "nloc": 101, "complexity": 20, "token_count": 783, "parameters": [ "op1", "op2" ], "start_line": 1801, "end_line": 1925, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 125, "top_nesting_level": 0 }, { "name": "PyArray_CopyAndTranspose", "long_name": "PyArray_CopyAndTranspose( PyObject * op)", "filename": "multiarraymodule.c", "nloc": 44, "complexity": 6, "token_count": 278, "parameters": [ "op" ], "start_line": 1928, "end_line": 1979, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 0 }, { "name": "PyArray_Correlate", "long_name": "PyArray_Correlate( PyObject * op1 , PyObject * op2 , int mode)", "filename": "multiarraymodule.c", "nloc": 89, "complexity": 13, "token_count": 625, "parameters": [ "op1", "op2", "mode" ], "start_line": 1982, "end_line": 2080, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 99, "top_nesting_level": 0 }, { "name": "PyArray_ArgMin", "long_name": "PyArray_ArgMin( PyArrayObject * ap , int axis)", "filename": "multiarraymodule.c", "nloc": 21, "complexity": 5, "token_count": 138, "parameters": [ "ap", "axis" ], "start_line": 2083, "end_line": 2108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "PyArray_Max", "long_name": "PyArray_Max( PyArrayObject * ap , int axis)", "filename": "multiarraymodule.c", "nloc": 11, "complexity": 2, "token_count": 67, "parameters": [ "ap", "axis" ], "start_line": 2111, "end_line": 2122, "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": 67, "parameters": [ "ap", "axis" ], "start_line": 2125, "end_line": 2136, "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": 2139, "end_line": 2162, "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": 322, "parameters": [ "op", "axis" ], "start_line": 2166, "end_line": 2223, "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": 62, "complexity": 12, "token_count": 468, "parameters": [ "self0", "indices0", "axis" ], "start_line": 2227, "end_line": 2299, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 73, "top_nesting_level": 0 }, { "name": "PyArray_Put", "long_name": "PyArray_Put( PyArrayObject * self , PyObject * indices0 , PyObject * values0)", "filename": "multiarraymodule.c", "nloc": 47, "complexity": 10, "token_count": 319, "parameters": [ "self", "indices0", "values0" ], "start_line": 2302, "end_line": 2354, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "top_nesting_level": 0 }, { "name": "PyArray_PutMask", "long_name": "PyArray_PutMask( PyArrayObject * self , PyObject * mask0 , PyObject * values0)", "filename": "multiarraymodule.c", "nloc": 56, "complexity": 10, "token_count": 334, "parameters": [ "self", "mask0", "values0" ], "start_line": 2357, "end_line": 2419, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 63, "top_nesting_level": 0 }, { "name": "PyArray_Converter", "long_name": "PyArray_Converter( PyObject * object , PyObject ** address)", "filename": "multiarraymodule.c", "nloc": 13, "complexity": 3, "token_count": 66, "parameters": [ "object", "address" ], "start_line": 2431, "end_line": 2443, "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": 2446, "end_line": 2454, "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": 90, "complexity": 33, "token_count": 284, "parameters": [ "itemsize", "gentype" ], "start_line": 2458, "end_line": 2567, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 110, "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": 2582, "end_line": 2607, "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": 35, "complexity": 10, "token_count": 186, "parameters": [ "obj", "seq" ], "start_line": 2619, "end_line": 2655, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "PyArray_TypecodeConverter", "long_name": "PyArray_TypecodeConverter( PyObject * obj , PyArray_Typecode * at)", "filename": "multiarraymodule.c", "nloc": 106, "complexity": 34, "token_count": 629, "parameters": [ "obj", "at" ], "start_line": 2664, "end_line": 2805, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 142, "top_nesting_level": 0 }, { "name": "PyArray_EquivalentTypes", "long_name": "PyArray_EquivalentTypes( PyArray_Typecode * typ1 , PyArray_Typecode * typ2)", "filename": "multiarraymodule.c", "nloc": 24, "complexity": 8, "token_count": 162, "parameters": [ "typ1", "typ2" ], "start_line": 2813, "end_line": 2840, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "PyArray_EquivArrTypes", "long_name": "PyArray_EquivArrTypes( PyArrayObject * a1 , PyArrayObject * a2)", "filename": "multiarraymodule.c", "nloc": 10, "complexity": 1, "token_count": 80, "parameters": [ "a1", "a2" ], "start_line": 2843, "end_line": 2854, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_EquivalentTypenums", "long_name": "PyArray_EquivalentTypenums( int typenum1 , int typenum2)", "filename": "multiarraymodule.c", "nloc": 10, "complexity": 1, "token_count": 76, "parameters": [ "typenum1", "typenum2" ], "start_line": 2858, "end_line": 2869, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "_array_fromobject", "long_name": "_array_fromobject( PyObject * ignored , PyObject * args , PyObject * kws)", "filename": "multiarraymodule.c", "nloc": 45, "complexity": 11, "token_count": 282, "parameters": [ "ignored", "args", "kws" ], "start_line": 2891, "end_line": 2942, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 0 }, { "name": "PyArray_Empty", "long_name": "PyArray_Empty( int nd , intp * dims , PyArray_Typecode * type)", "filename": "multiarraymodule.c", "nloc": 15, "complexity": 3, "token_count": 99, "parameters": [ "nd", "dims", "type" ], "start_line": 2945, "end_line": 2961, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "array_empty", "long_name": "array_empty( PyObject * ignored , PyObject * args , PyObject * kwds)", "filename": "multiarraymodule.c", "nloc": 21, "complexity": 3, "token_count": 134, "parameters": [ "ignored", "args", "kwds" ], "start_line": 2967, "end_line": 2991, "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": 56, "complexity": 11, "token_count": 290, "parameters": [ "ignored", "args", "kwds" ], "start_line": 2996, "end_line": 3060, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 65, "top_nesting_level": 0 }, { "name": "PyArray_Zeros", "long_name": "PyArray_Zeros( int nd , intp * dims , PyArray_Typecode * type)", "filename": "multiarraymodule.c", "nloc": 20, "complexity": 3, "token_count": 133, "parameters": [ "nd", "dims", "type" ], "start_line": 3064, "end_line": 3086, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "array_zeros", "long_name": "array_zeros( PyObject * ignored , PyObject * args , PyObject * kwds)", "filename": "multiarraymodule.c", "nloc": 22, "complexity": 3, "token_count": 134, "parameters": [ "ignored", "args", "kwds" ], "start_line": 3092, "end_line": 3116, "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": 3123, "end_line": 3132, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "array_fromString", "long_name": "array_fromString( PyObject * ignored , PyObject * args , PyObject * keywds)", "filename": "multiarraymodule.c", "nloc": 50, "complexity": 8, "token_count": 283, "parameters": [ "ignored", "args", "keywds" ], "start_line": 3137, "end_line": 3192, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 56, "top_nesting_level": 0 }, { "name": "_fill_in_itemsize", "long_name": "_fill_in_itemsize( PyArray_Typecode * typecode)", "filename": "multiarraymodule.c", "nloc": 8, "complexity": 2, "token_count": 42, "parameters": [ "typecode" ], "start_line": 3207, "end_line": 3214, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_FromFile", "long_name": "PyArray_FromFile( FILE * fp , PyArray_Typecode * typecode , intp num , char * sep)", "filename": "multiarraymodule.c", "nloc": 113, "complexity": 23, "token_count": 682, "parameters": [ "fp", "typecode", "num", "sep" ], "start_line": 3218, "end_line": 3345, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 128, "top_nesting_level": 0 }, { "name": "array_fromfile", "long_name": "array_fromfile( PyObject * ignored , PyObject * args , PyObject * keywds)", "filename": "multiarraymodule.c", "nloc": 34, "complexity": 6, "token_count": 221, "parameters": [ "ignored", "args", "keywds" ], "start_line": 3363, "end_line": 3398, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "PyArray_FromBuffer", "long_name": "PyArray_FromBuffer( PyObject * buf , PyArray_Typecode * type , intp count , int swapped)", "filename": "multiarraymodule.c", "nloc": 58, "complexity": 11, "token_count": 306, "parameters": [ "buf", "type", "count", "swapped" ], "start_line": 3401, "end_line": 3464, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 64, "top_nesting_level": 0 }, { "name": "array_frombuffer", "long_name": "array_frombuffer( PyObject * ignored , PyObject * args , PyObject * keywds)", "filename": "multiarraymodule.c", "nloc": 16, "complexity": 2, "token_count": 115, "parameters": [ "ignored", "args", "keywds" ], "start_line": 3478, "end_line": 3495, "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": 3502, "end_line": 3513, "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": 3520, "end_line": 3526, "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": 3533, "end_line": 3539, "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": 3543, "end_line": 3549, "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": 3553, "end_line": 3562, "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": 29, "complexity": 4, "token_count": 229, "parameters": [ "start", "stop", "step", "type_num" ], "start_line": 3566, "end_line": 3599, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "top_nesting_level": 0 }, { "name": "array_arange", "long_name": "array_arange( PyObject * ignored , PyObject * args , PyObject * kws)", "filename": "multiarraymodule.c", "nloc": 42, "complexity": 10, "token_count": 258, "parameters": [ "ignored", "args", "kws" ], "start_line": 3605, "end_line": 3653, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "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": 11, "complexity": 2, "token_count": 78, "parameters": [ "dummy", "args", "kwds" ], "start_line": 3673, "end_line": 3684, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "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": 3, "token_count": 67, "parameters": [ "self", "args", "kwds" ], "start_line": 3690, "end_line": 3707, "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": 29, "complexity": 8, "token_count": 226, "parameters": [ "condition", "x", "y" ], "start_line": 3711, "end_line": 3747, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "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": 3755, "end_line": 3763, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "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": 3769, "end_line": 3780, "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": 23, "complexity": 5, "token_count": 145, "parameters": [ "dummy", "args", "kwds" ], "start_line": 3787, "end_line": 3811, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "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": 3871, "end_line": 3980, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 110, "top_nesting_level": 0 }, { "name": "set_flaginfo", "long_name": "set_flaginfo( PyObject * d)", "filename": "multiarraymodule.c", "nloc": 23, "complexity": 1, "token_count": 171, "parameters": [ "d" ], "start_line": 3985, "end_line": 4011, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 0 }, { "name": "initmultiarray", "long_name": "initmultiarray()", "filename": "multiarraymodule.c", "nloc": 50, "complexity": 12, "token_count": 341, "parameters": [], "start_line": 4016, "end_line": 4094, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 79, "top_nesting_level": 0 } ], "methods_before": [ { "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": 51, "end_line": 56, "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": 59, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "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": 68, "end_line": 80, "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": 83, "end_line": 90, "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_Typecode * type)", "filename": "multiarraymodule.c", "nloc": 42, "complexity": 9, "token_count": 245, "parameters": [ "self", "type" ], "start_line": 93, "end_line": 141, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "PyArray_Ravel", "long_name": "PyArray_Ravel( PyArrayObject * a , int fortran)", "filename": "multiarraymodule.c", "nloc": 14, "complexity": 4, "token_count": 87, "parameters": [ "a", "fortran" ], "start_line": 144, "end_line": 158, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "PyArray_Flatten", "long_name": "PyArray_Flatten( PyArrayObject * a , int fortran)", "filename": "multiarraymodule.c", "nloc": 32, "complexity": 5, "token_count": 162, "parameters": [ "a", "fortran" ], "start_line": 161, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "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": 202, "end_line": 211, "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": 214, "end_line": 240, "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": 75, "complexity": 17, "token_count": 411, "parameters": [ "self", "newdims" ], "start_line": 248, "end_line": 339, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 92, "top_nesting_level": 0 }, { "name": "PyArray_Squeeze", "long_name": "PyArray_Squeeze( PyArrayObject * self)", "filename": "multiarraymodule.c", "nloc": 30, "complexity": 4, "token_count": 192, "parameters": [ "self" ], "start_line": 347, "end_line": 378, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "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": 382, "end_line": 403, "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)", "filename": "multiarraymodule.c", "nloc": 43, "complexity": 12, "token_count": 433, "parameters": [ "self", "axis", "rtype" ], "start_line": 406, "end_line": 461, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 56, "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": 465, "end_line": 475, "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": 478, "end_line": 488, "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": 491, "end_line": 501, "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": 504, "end_line": 515, "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": 518, "end_line": 529, "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": 532, "end_line": 543, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_Compress", "long_name": "PyArray_Compress( PyArrayObject * self , PyObject * condition , int axis)", "filename": "multiarraymodule.c", "nloc": 18, "complexity": 3, "token_count": 110, "parameters": [ "self", "condition", "axis" ], "start_line": 547, "end_line": 567, "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": 50, "complexity": 13, "token_count": 403, "parameters": [ "self" ], "start_line": 570, "end_line": 628, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 59, "top_nesting_level": 0 }, { "name": "PyArray_Clip", "long_name": "PyArray_Clip( PyArrayObject * self , PyObject * min , PyObject * max)", "filename": "multiarraymodule.c", "nloc": 30, "complexity": 6, "token_count": 241, "parameters": [ "self", "min", "max" ], "start_line": 631, "end_line": 664, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "top_nesting_level": 0 }, { "name": "PyArray_Conjugate", "long_name": "PyArray_Conjugate( PyArrayObject * self)", "filename": "multiarraymodule.c", "nloc": 36, "complexity": 9, "token_count": 225, "parameters": [ "self" ], "start_line": 667, "end_line": 703, "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": 706, "end_line": 716, "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": 106, "complexity": 24, "token_count": 808, "parameters": [ "self", "offset", "axis1", "axis2" ], "start_line": 719, "end_line": 840, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 122, "top_nesting_level": 0 }, { "name": "PyArray_AsCArray", "long_name": "PyArray_AsCArray( PyObject ** op , * ptr , intp * dims , int nd , int type_num)", "filename": "multiarraymodule.c", "nloc": 55, "complexity": 13, "token_count": 432, "parameters": [ "op", "ptr", "dims", "nd", "type_num" ], "start_line": 857, "end_line": 913, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 57, "top_nesting_level": 0 }, { "name": "PyArray_As1D", "long_name": "PyArray_As1D( PyObject ** op , char ** ptr , int * d1 , int typecode)", "filename": "multiarraymodule.c", "nloc": 8, "complexity": 2, "token_count": 60, "parameters": [ "op", "ptr", "d1", "typecode" ], "start_line": 918, "end_line": 926, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "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": 9, "complexity": 2, "token_count": 81, "parameters": [ "op", "ptr", "d1", "d2", "typecode" ], "start_line": 930, "end_line": 940, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "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": 945, "end_line": 956, "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": 960, "end_line": 988, "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": 114, "complexity": 24, "token_count": 771, "parameters": [ "op", "axis" ], "start_line": 997, "end_line": 1125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 129, "top_nesting_level": 0 }, { "name": "PyArray_SwapAxes", "long_name": "PyArray_SwapAxes( PyArrayObject * ap , int a1 , int a2)", "filename": "multiarraymodule.c", "nloc": 37, "complexity": 12, "token_count": 227, "parameters": [ "ap", "a1", "a2" ], "start_line": 1128, "end_line": 1167, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 }, { "name": "PyArray_Transpose", "long_name": "PyArray_Transpose( PyArrayObject * ap , PyObject * op)", "filename": "multiarraymodule.c", "nloc": 49, "complexity": 15, "token_count": 403, "parameters": [ "ap", "op" ], "start_line": 1171, "end_line": 1230, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 60, "top_nesting_level": 0 }, { "name": "PyArray_Repeat", "long_name": "PyArray_Repeat( PyArrayObject * aop , PyObject * op , int axis)", "filename": "multiarraymodule.c", "nloc": 75, "complexity": 15, "token_count": 520, "parameters": [ "aop", "op", "axis" ], "start_line": 1233, "end_line": 1325, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 93, "top_nesting_level": 0 }, { "name": "PyArray_Choose", "long_name": "PyArray_Choose( PyArrayObject * ip , PyObject * op)", "filename": "multiarraymodule.c", "nloc": 89, "complexity": 18, "token_count": 650, "parameters": [ "ip", "op" ], "start_line": 1329, "end_line": 1441, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 113, "top_nesting_level": 0 }, { "name": "qsortCompare", "long_name": "qsortCompare( const * a , const * b)", "filename": "multiarraymodule.c", "nloc": 4, "complexity": 1, "token_count": 28, "parameters": [ "a", "b" ], "start_line": 1449, "end_line": 1452, "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)", "filename": "multiarraymodule.c", "nloc": 36, "complexity": 7, "token_count": 250, "parameters": [ "op", "axis" ], "start_line": 1474, "end_line": 1523, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "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": 63, "parameters": [ "ip1", "ip2" ], "start_line": 1529, "end_line": 1537, "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)", "filename": "multiarraymodule.c", "nloc": 48, "complexity": 8, "token_count": 350, "parameters": [ "op", "axis" ], "start_line": 1540, "end_line": 1599, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 60, "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": 1602, "end_line": 1637, "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": 223, "parameters": [ "op1", "op2" ], "start_line": 1640, "end_line": 1685, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 46, "top_nesting_level": 0 }, { "name": "PyArray_InnerProduct", "long_name": "PyArray_InnerProduct( PyObject * op1 , PyObject * op2)", "filename": "multiarraymodule.c", "nloc": 83, "complexity": 17, "token_count": 657, "parameters": [ "op1", "op2" ], "start_line": 1693, "end_line": 1796, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 104, "top_nesting_level": 0 }, { "name": "PyArray_MatrixProduct", "long_name": "PyArray_MatrixProduct( PyObject * op1 , PyObject * op2)", "filename": "multiarraymodule.c", "nloc": 101, "complexity": 20, "token_count": 783, "parameters": [ "op1", "op2" ], "start_line": 1801, "end_line": 1925, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 125, "top_nesting_level": 0 }, { "name": "PyArray_CopyAndTranspose", "long_name": "PyArray_CopyAndTranspose( PyObject * op)", "filename": "multiarraymodule.c", "nloc": 44, "complexity": 6, "token_count": 278, "parameters": [ "op" ], "start_line": 1928, "end_line": 1979, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 0 }, { "name": "PyArray_Correlate", "long_name": "PyArray_Correlate( PyObject * op1 , PyObject * op2 , int mode)", "filename": "multiarraymodule.c", "nloc": 89, "complexity": 13, "token_count": 625, "parameters": [ "op1", "op2", "mode" ], "start_line": 1982, "end_line": 2080, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 99, "top_nesting_level": 0 }, { "name": "PyArray_ArgMin", "long_name": "PyArray_ArgMin( PyArrayObject * ap , int axis)", "filename": "multiarraymodule.c", "nloc": 21, "complexity": 5, "token_count": 138, "parameters": [ "ap", "axis" ], "start_line": 2083, "end_line": 2108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "PyArray_Max", "long_name": "PyArray_Max( PyArrayObject * ap , int axis)", "filename": "multiarraymodule.c", "nloc": 11, "complexity": 2, "token_count": 67, "parameters": [ "ap", "axis" ], "start_line": 2111, "end_line": 2122, "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": 67, "parameters": [ "ap", "axis" ], "start_line": 2125, "end_line": 2136, "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": 2139, "end_line": 2162, "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": 322, "parameters": [ "op", "axis" ], "start_line": 2166, "end_line": 2223, "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": 62, "complexity": 12, "token_count": 468, "parameters": [ "self0", "indices0", "axis" ], "start_line": 2227, "end_line": 2299, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 73, "top_nesting_level": 0 }, { "name": "PyArray_Put", "long_name": "PyArray_Put( PyArrayObject * self , PyObject * indices0 , PyObject * values0)", "filename": "multiarraymodule.c", "nloc": 47, "complexity": 10, "token_count": 319, "parameters": [ "self", "indices0", "values0" ], "start_line": 2302, "end_line": 2354, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "top_nesting_level": 0 }, { "name": "PyArray_PutMask", "long_name": "PyArray_PutMask( PyArrayObject * self , PyObject * mask0 , PyObject * values0)", "filename": "multiarraymodule.c", "nloc": 56, "complexity": 10, "token_count": 334, "parameters": [ "self", "mask0", "values0" ], "start_line": 2357, "end_line": 2419, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 63, "top_nesting_level": 0 }, { "name": "PyArray_Converter", "long_name": "PyArray_Converter( PyObject * object , PyObject ** address)", "filename": "multiarraymodule.c", "nloc": 13, "complexity": 3, "token_count": 66, "parameters": [ "object", "address" ], "start_line": 2431, "end_line": 2443, "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": 2446, "end_line": 2454, "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": 90, "complexity": 33, "token_count": 284, "parameters": [ "itemsize", "gentype" ], "start_line": 2458, "end_line": 2567, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 110, "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": 2582, "end_line": 2607, "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": 35, "complexity": 10, "token_count": 186, "parameters": [ "obj", "seq" ], "start_line": 2619, "end_line": 2655, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "PyArray_TypecodeConverter", "long_name": "PyArray_TypecodeConverter( PyObject * obj , PyArray_Typecode * at)", "filename": "multiarraymodule.c", "nloc": 106, "complexity": 34, "token_count": 629, "parameters": [ "obj", "at" ], "start_line": 2664, "end_line": 2805, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 142, "top_nesting_level": 0 }, { "name": "PyArray_EquivalentTypes", "long_name": "PyArray_EquivalentTypes( PyArray_Typecode * typ1 , PyArray_Typecode * typ2)", "filename": "multiarraymodule.c", "nloc": 24, "complexity": 8, "token_count": 162, "parameters": [ "typ1", "typ2" ], "start_line": 2813, "end_line": 2840, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "PyArray_EquivArrTypes", "long_name": "PyArray_EquivArrTypes( PyArrayObject * a1 , PyArrayObject * a2)", "filename": "multiarraymodule.c", "nloc": 10, "complexity": 1, "token_count": 80, "parameters": [ "a1", "a2" ], "start_line": 2843, "end_line": 2854, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_EquivalentTypenums", "long_name": "PyArray_EquivalentTypenums( int typenum1 , int typenum2)", "filename": "multiarraymodule.c", "nloc": 10, "complexity": 1, "token_count": 76, "parameters": [ "typenum1", "typenum2" ], "start_line": 2858, "end_line": 2869, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "_array_fromobject", "long_name": "_array_fromobject( PyObject * ignored , PyObject * args , PyObject * kws)", "filename": "multiarraymodule.c", "nloc": 45, "complexity": 11, "token_count": 282, "parameters": [ "ignored", "args", "kws" ], "start_line": 2891, "end_line": 2942, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 0 }, { "name": "PyArray_Empty", "long_name": "PyArray_Empty( int nd , intp * dims , PyArray_Typecode * type)", "filename": "multiarraymodule.c", "nloc": 15, "complexity": 3, "token_count": 99, "parameters": [ "nd", "dims", "type" ], "start_line": 2945, "end_line": 2961, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "array_empty", "long_name": "array_empty( PyObject * ignored , PyObject * args , PyObject * kwds)", "filename": "multiarraymodule.c", "nloc": 21, "complexity": 3, "token_count": 134, "parameters": [ "ignored", "args", "kwds" ], "start_line": 2967, "end_line": 2991, "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": 56, "complexity": 11, "token_count": 290, "parameters": [ "ignored", "args", "kwds" ], "start_line": 2996, "end_line": 3060, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 65, "top_nesting_level": 0 }, { "name": "PyArray_Zeros", "long_name": "PyArray_Zeros( int nd , intp * dims , PyArray_Typecode * type)", "filename": "multiarraymodule.c", "nloc": 20, "complexity": 3, "token_count": 133, "parameters": [ "nd", "dims", "type" ], "start_line": 3064, "end_line": 3086, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "array_zeros", "long_name": "array_zeros( PyObject * ignored , PyObject * args , PyObject * kwds)", "filename": "multiarraymodule.c", "nloc": 22, "complexity": 3, "token_count": 134, "parameters": [ "ignored", "args", "kwds" ], "start_line": 3092, "end_line": 3116, "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": 3123, "end_line": 3132, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "array_fromString", "long_name": "array_fromString( PyObject * ignored , PyObject * args , PyObject * keywds)", "filename": "multiarraymodule.c", "nloc": 50, "complexity": 8, "token_count": 283, "parameters": [ "ignored", "args", "keywds" ], "start_line": 3137, "end_line": 3192, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 56, "top_nesting_level": 0 }, { "name": "_fill_in_itemsize", "long_name": "_fill_in_itemsize( PyArray_Typecode * typecode)", "filename": "multiarraymodule.c", "nloc": 8, "complexity": 2, "token_count": 42, "parameters": [ "typecode" ], "start_line": 3207, "end_line": 3214, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_FromFile", "long_name": "PyArray_FromFile( FILE * fp , PyArray_Typecode * typecode , intp num , char * sep)", "filename": "multiarraymodule.c", "nloc": 113, "complexity": 23, "token_count": 682, "parameters": [ "fp", "typecode", "num", "sep" ], "start_line": 3218, "end_line": 3345, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 128, "top_nesting_level": 0 }, { "name": "array_fromfile", "long_name": "array_fromfile( PyObject * ignored , PyObject * args , PyObject * keywds)", "filename": "multiarraymodule.c", "nloc": 34, "complexity": 6, "token_count": 221, "parameters": [ "ignored", "args", "keywds" ], "start_line": 3363, "end_line": 3398, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "PyArray_FromBuffer", "long_name": "PyArray_FromBuffer( PyObject * buf , PyArray_Typecode * type , intp count , int swapped)", "filename": "multiarraymodule.c", "nloc": 58, "complexity": 11, "token_count": 306, "parameters": [ "buf", "type", "count", "swapped" ], "start_line": 3401, "end_line": 3464, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 64, "top_nesting_level": 0 }, { "name": "array_frombuffer", "long_name": "array_frombuffer( PyObject * ignored , PyObject * args , PyObject * keywds)", "filename": "multiarraymodule.c", "nloc": 16, "complexity": 2, "token_count": 115, "parameters": [ "ignored", "args", "keywds" ], "start_line": 3478, "end_line": 3495, "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": 3502, "end_line": 3513, "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": 3520, "end_line": 3526, "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": 3533, "end_line": 3539, "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": 3543, "end_line": 3549, "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": 3553, "end_line": 3562, "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": 29, "complexity": 4, "token_count": 229, "parameters": [ "start", "stop", "step", "type_num" ], "start_line": 3566, "end_line": 3599, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "top_nesting_level": 0 }, { "name": "array_arange", "long_name": "array_arange( PyObject * ignored , PyObject * args , PyObject * kws)", "filename": "multiarraymodule.c", "nloc": 42, "complexity": 10, "token_count": 258, "parameters": [ "ignored", "args", "kws" ], "start_line": 3605, "end_line": 3653, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "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": 11, "complexity": 2, "token_count": 78, "parameters": [ "dummy", "args", "kwds" ], "start_line": 3673, "end_line": 3684, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "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": 3, "token_count": 67, "parameters": [ "self", "args", "kwds" ], "start_line": 3690, "end_line": 3707, "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": 29, "complexity": 8, "token_count": 226, "parameters": [ "condition", "x", "y" ], "start_line": 3711, "end_line": 3747, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "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": 3755, "end_line": 3763, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "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": 3769, "end_line": 3780, "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": 23, "complexity": 5, "token_count": 145, "parameters": [ "dummy", "args", "kwds" ], "start_line": 3787, "end_line": 3811, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "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": 3871, "end_line": 3980, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 110, "top_nesting_level": 0 }, { "name": "set_flaginfo", "long_name": "set_flaginfo( PyObject * d)", "filename": "multiarraymodule.c", "nloc": 23, "complexity": 1, "token_count": 171, "parameters": [ "d" ], "start_line": 3985, "end_line": 4011, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 0 }, { "name": "initmultiarray", "long_name": "initmultiarray()", "filename": "multiarraymodule.c", "nloc": 50, "complexity": 12, "token_count": 341, "parameters": [], "start_line": 4016, "end_line": 4094, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 79, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "PyArray_Transpose", "long_name": "PyArray_Transpose( PyArrayObject * ap , PyObject * op)", "filename": "multiarraymodule.c", "nloc": 49, "complexity": 16, "token_count": 405, "parameters": [ "ap", "op" ], "start_line": 1171, "end_line": 1230, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 60, "top_nesting_level": 0 } ], "nloc": 3165, "complexity": 654, "token_count": 20656, "diff_parsed": { "added": [ "\tif (op == NULL || op == Py_None) {", "\t\tpermutation = (intp *)malloc(n*sizeof(intp));", "\t\tpermutation = (intp *)malloc(n*sizeof(intp));", "\tif (permutation) free(permutation);", "\tif (op && (op != Py_None))" ], "deleted": [ "\tif (op == Py_None || op == NULL) {", "\t\tpermutation = (intp *)malloc(n*sizeof(int));", "\t\tpermutation = (intp *)malloc(n*sizeof(int));", "\tif (permutation != NULL) free(permutation);", "\tif (op != Py_None)" ] } } ] }, { "hash": "a74ef76e2f32e6de16fea37668daed0edb376fc6", "msg": "Fixed stepping issue for length-1 arrays.", "author": { "name": "Travis Oliphant", "email": "oliphant@enthought.com" }, "committer": { "name": "Travis Oliphant", "email": "oliphant@enthought.com" }, "author_date": "2005-10-27T03:04:32+00:00", "author_timezone": 0, "committer_date": "2005-10-27T03:04:32+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "64ee901f909f7fb5d8e572be318fd5ed5674fe30" ], "project_name": "repo_copy", "project_path": "/tmp/tmpn4cqam_6/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": "scipy/base/src/ufuncobject.c", "new_path": "scipy/base/src/ufuncobject.c", "filename": "ufuncobject.c", "extension": "c", "change_type": "MODIFY", "diff": "@@ -1094,7 +1094,7 @@ construct_matrices(PyUFuncLoopObject *loop, PyObject *args, PyArrayObject **mps)\n }\n \telse { /* uniformly-strided case ONE_UFUNCLOOP */\n \t\tfor (i=0; inargs; i++) {\n-\t\t\tif (mps[i]->nd == 0)\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", "added_lines": 1, "deleted_lines": 1, "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 \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\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 */\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\n#define UFUNC_REDUCE 0\n#define UFUNC_ACCUMULATE 1\n#define UFUNC_REDUCEAT 2\n#define UFUNC_OUTER 3\n\n\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\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\t\t\n\t\tkey = PyInt_FromLong((long) arg_types[0]);\n\t\tif (key == NULL) return -1;\n\t\tobj = PyDict_GetItem(self->userloops, key);\n\t\tif (obj == NULL) {\n\t\t\tPy_DECREF(key);\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\t\tPy_DECREF(key);\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\t*data = self->data[i];\n\t*function = self->functions[i];\n\n\treturn 0;\n}\n\nstatic int\n_getpyvalues(char *name, int *bufsize, int *errmask, PyObject **errobj)\n{\n\n PyObject *thedict;\n PyObject *ref=NULL;\n\tPyObject *retval;\n\n thedict = PyEval_GetLocals();\n ref = PyDict_GetItemString(thedict, UFUNC_PYVALS_NAME);\n if (ref == NULL) {\n\t\tthedict = PyEval_GetGlobals();\n\t\tref = PyDict_GetItemString(thedict, UFUNC_PYVALS_NAME);\n }\n if (ref == NULL) {\n \t thedict = PyEval_GetBuiltins();\n ref = PyDict_GetItemString(thedict, UFUNC_PYVALS_NAME);\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\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"buffer size (%d) is not \"\t\\\n\t\t\t \"in range (%d - %d)\", \n\t\t\t *bufsize, PyArray_MIN_BUFSIZE, \n\t\t\t PyArray_MAX_BUFSIZE);\n\t\treturn -1;\n\t}\t\n\n\t*errmask = PyInt_AsLong(PyList_GET_ITEM(ref, 1));\n\tif (*errmask < 0) {\n\t\tif (PyErr_Occurred()) return -1;\n\t\tPyErr_Format(PyExc_ValueError,\t\t\\\n\t\t\t \"invalid error mask (%d)\", \n\t\t\t *errmask);\n\t\treturn -1;\n\t}\n\t\n\tretval = PyList_GET_ITEM(ref, 2);\n\tif (retval != Py_None && !PyCallable_Check(retval)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"callback function must be callable\");\n\t\treturn -1;\n\t}\n\n\t*errobj = Py_BuildValue(\"NO\", \n\t\t\t\tPyString_FromString(name),\n\t\t\t\tretval);\n\tif (*errobj == NULL) return -1;\n\t\n\treturn 0;\n}\n\n\nstatic char\n_scalar_kind(int typenum, PyArrayObject **arr) \n{\n\tif (PyTypeNum_ISSIGNED(typenum)) return UFUNC_INTNEG_SCALAR;\n\tif (PyTypeNum_ISFLOAT(typenum)) return UFUNC_FLOAT_SCALAR;\n\tif (PyTypeNum_ISCOMPLEX(typenum)) return UFUNC_COMPLEX_SCALAR;\n\tif (PyTypeNum_ISUNSIGNED(typenum)) return UFUNC_INTPOS_SCALAR;\n\tif (PyTypeNum_ISBOOL(typenum)) return UFUNC_BOOL_SCALAR;\n\treturn UFUNC_OBJECT_SCALAR;\n}\n\n\n/* Create copies for any arrays that are less than loop->bufsize\n in total size and are mis-behaved or in need\n of casting.\n*/\n\nstatic int\n_create_copies(PyUFuncLoopObject *loop, int *arg_types, PyArrayObject **mps)\n{\n\tint nin = loop->ufunc->nin;\n\tint i;\n\tintp size;\n\tPyObject *new;\n\tPyArray_Typecode ntype = {PyArray_NOTYPE, 0, 0};\n\tPyArray_Typecode atype = {PyArray_NOTYPE, 0, 0};\n\n\tfor (i=0; ielsize;\n\t\t\tif (PyArray_EquivalentTypes(&atype, &ntype)) {\n\t\t\t\targ_types[i] = PyArray_TYPE(mps[i]);\n\t\t\t}\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.type_num = arg_types[i];\n\t\t\t\tntype.itemsize = 0;\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 |\t\\\n\t\t\t\t\t\t BEHAVED_FLAGS_RO);\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\nstatic int\nconstruct_matrices(PyUFuncLoopObject *loop, PyObject *args, PyArrayObject **mps)\n{\n int nargs, i, cnt, cntcast, maxsize;\n int arg_types[MAX_ARGS];\n\tchar scalars[MAX_ARGS];\n\tPyUFuncObject *self=loop->ufunc;\n\tBool allscalars=TRUE;\n\tPyTypeObject *subtype=&PyArray_Type;\n\n /* Check number of arguments */\n nargs = PyTuple_Size(args);\n if ((nargs != self->nin) && (nargs != self->nargs)) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid number of arguments\");\n return -1;\n }\n\n\n /* Get each input argument */\n for (i=0; inin; i++) {\n mps[i] = (PyArrayObject *)\\\n\t\t\tPyArray_FromAny(PyTuple_GET_ITEM(args,i), \n\t\t\t\t\tNULL, 0, 0, 0);\n if (mps[i] == NULL) return -1;\n arg_types[i] = PyArray_TYPE(mps[i]);\n if (PyTypeNum_ISFLEXIBLE(arg_types[i])) {\n PyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"ufuncs do not support\"\t\\\n \" flexible arrays\");\n return -1;\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\t\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 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 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_Typecode ntype = {PyArray_NOTYPE, 0, 0};\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\n\t\t/* reset types for outputs that are equivalent \n\t\t -- no sense casting uselessly\n\t\t*/\n\t\tif (mps[i]->descr->type_num != arg_types[i]) {\n\t\t\tPyArray_Typecode atype = {PyArray_NOTYPE, 0, 0};\n\t\t\tntype.type_num = PyArray_TYPE(mps[i]);\n\t\t\tntype.itemsize = PyArray_ITEMSIZE(mps[i]);\n\t\t\tatype.type_num = arg_types[i];\n\t\t\tatype.itemsize = \\\n\t\t\t\tPyArray_DescrFromType(arg_types[i])->elsize;\n\t\t\tif (PyArray_EquivalentTypes(&atype, &ntype)) {\n\t\t\t\targ_types[i] = PyArray_TYPE(mps[i]);\n\t\t\t}\n\t\t}\n\n\t\t/* still not the same -- or will we have to use buffers?*/\n\t\tif (mps[i]->descr->type_num != arg_types[i] ||\n\t\t !PyArray_ISBEHAVED_RO(mps[i])) {\n\t\t\tif (loop->size < loop->bufsize) {\n\t\t\t\tPyObject *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\tntype.type_num = arg_types[i];\n\t\t\t\tntype.itemsize = 0;\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 | \n\t\t\t\t\t\t BEHAVED_FLAGS_RO |\n\t\t\t\t\t\t UPDATEIFCOPY);\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\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\tcnt = cntcast = 0; /* keeps track of bytes to allocate */\n\tmaxsize = 0;\n for (i=0; inargs; i++) {\n\t\tcnt += mps[i]->itemsize;\n if (arg_types[i] != mps[i]->descr->type_num) {\n\t\t\tPyArray_Descr *descr;\n\n loop->meth = BUFFER_UFUNCLOOP;\n\t\t\tdescr = PyArray_DescrFromType(arg_types[i]);\n\t\t\tcntcast += descr->elsize;\n if (i < self->nin) {\n loop->cast[i] = \\\n\t\t\t\t\tmps[i]->descr->cast[arg_types[i]];\n\t\t\t}\n else {\n loop->cast[i] = descr->\\\n\t\t\t\t\tcast[mps[i]->descr->type_num];\n\t\t\t}\n\n }\n loop->swap[i] = !(PyArray_ISNOTSWAPPED(mps[i]));\n if (!PyArray_ISBEHAVED_RO(mps[i])) {\n loop->meth = BUFFER_UFUNCLOOP;\n }\n if (!loop->obj && mps[i]->descr->type_num == PyArray_OBJECT)\n loop->obj = 1;\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 == NOBUFFER_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\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\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 }\n else if (loop->meth == BUFFER_UFUNCLOOP) {\n for (i=0; inargs; i++) {\n\t\t\tloop->steps[i] = mps[i]->itemsize; \n\t\t}\n }\n\telse { /* 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\tif (loop->meth == BUFFER_UFUNCLOOP) {\n\t\tchar *castptr;\n\t\tint oldsize=0;\n\t\tloop->buffer[0] = (char *)malloc(loop->bufsize*(cnt+cntcast));\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\t\tif (loop->buffer[0] == NULL) return -1;\n\t\tcastptr = loop->buffer[0] + loop->bufsize*cnt;\n\t\tfor (i=0; inargs; i++) {\n\t\t\tif (i > 0)\n\t\t\t\tloop->buffer[i] = loop->buffer[i-1] + \\\n\t\t\t\t\tloop->bufsize * mps[i-1]->itemsize;\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\tloop->castbuf[i] = castptr + \n\t\t\t\t\tloop->bufsize*oldsize;\n\t\t\t\t/* fprintf(stderr, \"castbuf[%d] = %p\\n\", i, loop->castbuf[i]); */\n#define _PyD PyArray_DescrFromType\n\t\t\t\toldsize = _PyD(arg_types[i])->elsize;\n#undef _PyD\n\t\t\t\tloop->bufptr[i] = loop->castbuf[i];\n\t\t\t\tcastptr = loop->castbuf[i];\n\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\tloop->dptr[i] = loop->buffer[i];\n\t\t}\n\t}\n\n return nargs;\n}\n\nstatic PyTypeObject PyUFuncLoop_Type;\n\nstatic void ufuncloop_dealloc(PyUFuncLoopObject *);\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\tif ((loop=PyObject_NEW(PyUFuncLoopObject, &PyUFuncLoop_Type)) == NULL)\n\t\treturn NULL;\n\t/* --- no real speed increase this way\n\tloop = malloc(sizeof(PyUFuncLoopObject));\n\t*/\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 (_getpyvalues((self->name ? self->name : \"\"),\n\t\t\t &(loop->bufsize), &(loop->errormask), \n\t\t\t &(loop->errobj)) < 0)\n\t\tgoto fail;\n\n\t/* Setup the matrices */\n\tif (construct_matrices(loop, args, mps) < 0) goto fail;\n\t\n\tPyUFunc_clearfperr();\n\n\treturn loop;\n\n fail:\n\tufuncloop_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 something besides NULL, NULL \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\nstatic int \nPyUFunc_GenericFunction(PyUFuncObject *self, PyObject *args, \n\t\t\tPyArrayObject **mps) \n{\n\tPyUFuncLoopObject *loop;\n\tint i;\n\tint temp;\n BEGIN_THREADS_DEF\n\n\tif (!(loop = construct_loop(self, args, mps))) return -1;\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();\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();\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\t/* Make local copies of all loop variables */\n\t\t/* Optimizations needed:\n\t\t 1) move data better into the buffer better\n\t\t --- not one at a time -- this requires some \n pre-analysis and is only possible over \n the largest dimension.\n\t\t*/\n\n\t\tPyArray_CopySwapNFunc *copyswapn[MAX_ARGS];\n\t\tPyArrayIterObject **iters=loop->iters;\n\t\tint *swap=loop->swap;\n\t\tvoid **dptr=loop->dptr;\n\t\tint mpselsize[MAX_ARGS];\n\t\tintp index=loop->index, size=loop->size;\n\t\tintp bufcnt=loop->bufcnt;\n\t\tint bufsize=loop->bufsize;\n\t\tvoid **bufptr = loop->bufptr;\n\t\tvoid **buffer = loop->buffer;\n\t\tvoid **castbuf = loop->castbuf;\n\t\tintp *steps = loop->steps;\n\t\tBool pyobject[MAX_ARGS];\n\t\t\n\t\tfor (i=0; inargs; i++) {\n\t\t\tcopyswapn[i] = mps[i]->descr->copyswapn;\n\t\t\tmpselsize[i] = mps[i]->itemsize;\n\t\t\tpyobject[i] = (loop->obj && \\\n (mps[i]->descr->type_num == PyArray_OBJECT));\n\t\t}\n\t\t/* Do generic buffered looping here (works for any kind of\n\t\t arrays): Everything uses a buffer. \n\n\t\t 1. fill the input buffers.\n\t\t 2. If buffer is filled then \n\t\t a. cast any input buffers needing it. \n\t\t b. call inner function (which loops over the buffer).\n\t\t\t c. cast any output buffers needing it.\n\t\t\t d. copy output buffer back to output arrays.\n 3. goto next position\n\t\t*/ \n\t\t/*fprintf(stderr, \"BUFFER...%d\\n\", loop->size);*/\n\t\t/*\n\t\tfor (i=0; inargs; i++) {\n\t\t\tfprintf(stderr, \"iters[%d]->dataptr = %p, %p of size %d\\n\", i, \n\t\t\t\titers[i], iters[i]->ao->data, PyArray_NBYTES(iters[i]->ao));\n\t\t}\n\t\t*/\n\t\twhile (index < size) {\n\t\t\t/*copy input data */\n\t\t\tfor (i=0; inin; i++) {\n\t\t\t\tif (pyobject[i]) {\n\t\t\t\t\tPy_INCREF(*((PyObject **)iters[i]->dataptr));\n\t\t\t\t}\n\t\t\t\t/*\t\t\t\tfprintf(stderr, \"index = %d, i=%d, writing to %p\\n\", index, i, dptr[i]); */\n\t\t\t\tmemcpy(dptr[i], iters[i]->dataptr,\n\t\t\t\t mpselsize[i]);\n\t\t\t\tdptr[i] += mpselsize[i];\n\t\t\t\tPyArray_ITER_NEXT(iters[i]);\n\t\t\t}\n\t\t\tbufcnt++;\n\t\t\tindex++; \n\t\t\tif ((bufcnt == bufsize) || \\\n\t\t\t (index == size)) {\n\t\t\t\t\n\t\t\t\tfor (i=0; inin; i++) {\n\t\t\t\t\tif (swap[i]) {\n\t\t\t\t\t\t/* fprintf(stderr, \"swapping...\\n\");*/\n\t\t\t\t\t\tcopyswapn[i](buffer[i], NULL,\n\t\t\t\t\t\t\t bufcnt, 1, \n\t\t\t\t\t\t\t mpselsize[i]);\n\t\t\t\t\t}\n\t\t\t\t\tif (loop->cast[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 bufcnt,\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\n\t\t\t\tloop->function((char **)bufptr, \n\t\t\t\t\t &bufcnt, \n\t\t\t\t\t steps, loop->funcdata);\n \n\t\t\t\tUFUNC_CHECK_ERROR();\n\n\t\t\t\tfor (i=self->nin; inargs; i++) {\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 bufcnt,\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\t/* fprintf(stderr, \"swapping back...\\n\"); */\n\t\t\t\t\t\tcopyswapn[i](buffer[i], NULL,\n\t\t\t\t\t\t\t bufcnt, 1, \n\t\t\t\t\t\t\t mpselsize[i]);\n\t\t\t\t\t}\n\t\t\t\t\tfor (temp = 0; temp < bufcnt; temp++) {\n\t\t\t\t\t\t/* fprintf(stderr, \"temp=%d, i=%d; reading from %p\\n\", temp, i, dptr[i]);*/\n\t\t\t\t\t\tif (pyobject[i]) {\n\t\t\t\t\t\t\tPy_XDECREF(*((PyObject **)iters[i]->dataptr));\n\t\t\t\t\t\t\tPy_INCREF(*((PyObject **)dptr[i]));\n\t\t\t\t\t\t}\n\t\t\t\t\t\tmemcpy(iters[i]->dataptr,\n\t\t\t\t\t\t dptr[i], mpselsize[i]);\n\t\t\t\t\t\tPyArray_ITER_NEXT(iters[i]);\n\t\t\t\t\t\tdptr[i] += mpselsize[i];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbufcnt = 0;\n\t\t\t\tfor (i=0; inargs; i++) \n\t\t\t\t\tdptr[i] = buffer[i];\n\t\t\t\t\n\t\t\t} \n\t\t}\n\t}\n\t}\t\n\t\n LOOP_END_THREADS\n\n\tPy_DECREF(loop);\n\treturn 0;\n\n fail:\n LOOP_END_THREADS\n\n\tPy_DECREF(loop); \n\treturn -1;\n }\n\nstatic PyArrayObject *\n_getidentity(PyUFuncObject *self, int otype, char *str)\n{\n PyObject *obj, *arr;\n PyArray_Typecode typecode = {otype, 0, 0};\n\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\t\n arr = PyArray_FromAny(obj, &typecode, 0, 0, CARRAY_FLAGS);\n Py_DECREF(obj);\n return (PyArrayObject *)arr;\n}\n\nstatic int\n_create_reduce_copy(PyUFuncReduceObject *loop, PyArrayObject **arr, int rtype)\n{\n\tintp maxsize;\n\tPyObject *new;\n\tPyArray_Typecode ntype = {rtype, 0, 0};\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\tnew = PyArray_FromAny((PyObject *)(*arr), \n\t\t\t\t\t &ntype, 0, 0,\n\t\t\t\t\t FORCECAST |\t\t\\\n\t\t\t\t\t BEHAVED_FLAGS_RO);\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\t\n\treturn 0;\n}\n\n\n\nstatic PyTypeObject PyUFuncReduce_Type;\n\nstatic void ufuncreduce_dealloc(PyUFuncReduceObject *);\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\tif ((loop=PyObject_NEW(PyUFuncReduceObject, \n\t\t\t &PyUFuncReduce_Type)) == NULL)\n\t\treturn NULL;\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 (_getpyvalues(str, &(loop->bufsize), &(loop->errormask), \n\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 if (loop->meth == ZERODIM_REDUCELOOP) {\n idarr = _getidentity(self, otype, str);\n if (idarr == NULL) goto fail;\n if (idarr->itemsize > 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->itemsize);\n Py_DECREF(idarr);\n goto fail;\n }\n memcpy(loop->idptr, idarr->data, idarr->itemsize);\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->itemsize;\n loop->outsize = loop->ret->itemsize;\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\t\n\tif (loop->meth == BUFFER_UFUNCLOOP) {\n\n\t\tloop->steps[0] = loop->outsize;\n if (otype != aar->descr->type_num) {\n loop->buffer = (char *)malloc(loop->bufsize*\\\n (loop->outsize + \\\n aar->itemsize));\n if (loop->buffer == NULL) goto fail;\n loop->castbuf = loop->buffer + \\\n loop->bufsize*aar->itemsize;\n loop->bufptr[0] = loop->castbuf; \n loop->cast = aar->descr->cast[otype];\n }\n else {\n loop->buffer = (char *)malloc(loop->bufsize*\\\n loop->outsize);\n if (loop->buffer == NULL) goto fail;\n loop->bufptr[0] = loop->buffer;\n }\n\t}\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\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\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:\n\t\t/*fprintf(stderr, \"ONEDIM..%d\\n\", loop->size); */\n while(loop->index < loop->size) {\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:\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 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();\n\n PyArray_ITER_NEXT(loop->it)\n loop->bufptr[1] += loop->outsize;\n loop->bufptr[2] = loop->bufptr[1];\n loop->index++; \n\t\t\tif (PyErr_Occurred()) goto fail;\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->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\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->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->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();\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 Py_DECREF(loop);\n return (PyObject *)ret;\n\n fail:\n LOOP_END_THREADS\n\n Py_XDECREF(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\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 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 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();\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->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\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->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->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();\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 Py_DECREF(loop);\n return (PyObject *)ret;\n\n fail:\n\tLOOP_END_THREADS\n\n Py_XDECREF(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\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\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();\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; ibufptr[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->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();\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 Py_DECREF(loop);\n return (PyObject *)ret;\n\t\n fail:\n\tLOOP_END_THREADS\n\n\tPy_XDECREF(loop);\n\treturn NULL;\n}\n\n\n/* This code handles reduce, reduceat, and accumulate \n (accumulate and reduce are special cases of the more general reduceat \n but they are handled separately for speed) \n*/\n\nstatic PyObject * \nPyUFunc_GenericReduction(PyUFuncObject *self, PyObject *args, \n PyObject *kwds, int operation) \n{\n\tint axis=0;\n\tPyArrayObject *mp, *ret = NULL;\n\tPyObject *op, *res=NULL;\n\tPyObject *obj_ind; \n\tPyArrayObject *indices = NULL;\n\tPyArray_Typecode otype= {PyArray_NOTYPE, 0, 0};\n PyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tstatic char *kwlist1[] = {\"array\", \"axis\", \"rtype\", NULL};\n\tstatic char *kwlist2[] = {\"array\", \"indices\", \"axis\", \"rtype\", 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\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_TypecodeConverter, \n\t\t\t\t\t\t&otype)) return NULL;\n indices = (PyArrayObject *)PyArray_FromAny(obj_ind, &indtype, \n\t\t\t\t\t\t\t 1, 1, CARRAY_FLAGS);\n if (indices == NULL) return NULL;\n\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_TypecodeConverter, \n\t\t\t\t\t\t&otype)) return NULL;\n\t}\n\t\n\t/* Ensure input is an array */\t\n\tmp = (PyArrayObject *)PyArray_FromAny(op, NULL, 0, 0, 0);\n\tif (mp == NULL) return NULL;\n\n /* Check to see if input is zero-dimensional */\n if (mp->nd == 0) {\n PyErr_Format(PyExc_TypeError, \"cannot %s on a scalar\",\n _reduce_type[operation]);\n Py_DECREF(mp);\n return NULL; \n }\n\n /* Check to see that type (and otype) is not FLEXIBLE */\n\tif (PyArray_ISFLEXIBLE(mp) || 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.type_num == PyArray_NOTYPE) {\t\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->itemsize < sizeof(long))) {\n\t\t\tif (PyTypeNum_ISUNSIGNED(typenum))\n\t\t\t\totype.type_num = PyArray_ULONG;\n\t\t\telse\n\t\t\t\totype.type_num = 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\totype.type_num = PyArray_LONG;\n\t\t}\n\t\telse {\n\t\t\totype.type_num = typenum;\n\t\t}\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\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}\n\tif (res == NULL) PyErr_Clear();\n\telse if (res == Py_None) Py_DECREF(res);\n\telse {\n\t\tPy_DECREF(ret);\n\t\treturn res;\n\t}\t\n\treturn PyArray_Return(ret);\n\t\n}\n\n\n\n/* ---------- */\n\nstatic PyObject *\n_find_array_wrap(PyObject *args)\n{\n\tint nargs, i;\n\tint np = 0;\n\tint argmax = 0;\n\tint val;\n\tdouble priority[MAX_ARGS];\n\tdouble maxpriority = PyArray_SUBTYPE_PRIORITY;\n\tPyObject *with_wrap[MAX_ARGS];\n\tPyObject *attr;\n\tPyObject *obj;\n\n\tnargs = PyTuple_Size(args);\n\tfor (i=0; i maxpriority) {\n\t\t\tmaxpriority = priority[i];\n\t\t\targmax = i;\n\t\t}\n\t}\n\n\treturn with_wrap[argmax];\n}\n\nstatic PyObject *\nufunc_generic_call(PyUFuncObject *self, PyObject *args) \n{\n\tint i;\n\tPyTupleObject *ret;\n\tPyArrayObject *mps[MAX_ARGS];\n\tPyObject *retobj[MAX_ARGS];\n\tPyObject *res;\n\tPyObject *obj;\n\t\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\tif (PyUFunc_GenericFunction(self, args, mps) == -1) {\n\t\tfor(i=0; inargs; i++) Py_XDECREF(mps[i]);\n\t\treturn NULL;\n\t}\n\t\n\tfor(i=0; inin; i++) Py_DECREF(mps[i]);\n\n\t/* Use __array_wrap__ on all outputs \n\t if present on one of the input arguments.\n\t If present for multiple inputs:\n\t use __array_wrap__ of input object with largest \n\t\t__array_priority__ (default = 0.0)\n\t */\n\tobj = _find_array_wrap(args);\n\t\n\t/* wrap outputs */\n\tfor (i=0; inout; i++) {\n\t\tint j=self->nin+i;\n\t\t/* check to see if any UPDATEIFCOPY flags are set \n\t\t which meant that a temporary output was generated \n\t\t*/\n\t\tif (mps[j]->flags & UPDATEIFCOPY) {\n\t\t\tPyObject *old = mps[j]->base;\n\t\t\tPy_INCREF(old); /* we want to hang on to this */\n\t\t\tPy_DECREF(mps[j]); /* should trigger the copy \n\t\t\t\t\t back into old */\n\t\t\tmps[j] = (PyArrayObject *)old;\n\t\t}\n\t\tif (obj != NULL) {\n\t\t\tres = PyObject_CallMethod(obj, \"__array_wrap__\",\n\t\t\t\t\t\t \"O\", mps[j]);\n\t\t\tif (res == NULL) PyErr_Clear();\n\t\t\telse if (res == Py_None) Py_DECREF(res);\n\t\t\telse {\n\t\t\t\tPy_DECREF(mps[j]);\n\t\t\t\tretobj[i] = res;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\tretobj[i] = PyArray_Return(mps[j]);\n\t}\n\t\n\tif (self->nout == 1) { \n\t\treturn retobj[0];\n\t} else { \n\t\tret = (PyTupleObject *)PyTuple_New(self->nout);\n\t\tfor(i=0; inout; i++) {\n\t\t\tPyTuple_SET_ITEM(ret, i, retobj[i]);\n\t\t}\n\t\treturn (PyObject *)ret;\n\t}\t\n\n}\n\nstatic 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\tif ((self = PyObject_NEW(PyUFuncObject, &PyUFunc_Type)) == NULL) \n\t\treturn NULL;\n\t\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 = malloc(offset[0] + offset[1] + sizeof(void *) + \\\n\t\t\t (fname_len+14));\n\n\tif (self->ptr == NULL) return PyErr_NoMemory();\n Py_INCREF(function);\n self->obj = function;\n\tfdata = (PyUFunc_PyFuncData *)(self->ptr);\n fdata->nin = nin;\n fdata->nout = nout;\n fdata->callable = function;\n \n self->data = (void **)(self->ptr + offset[0]);\n self->data[0] = (void *)fdata;\n\t\n\tself->types = (char *)self->data + sizeof(void *);\n for (i=0; inargs; i++) self->types[i] = PyArray_OBJECT;\n\n str = self->types + offset[1];\n memcpy(str, fname, fname_len);\n memcpy(str+fname_len, \" (vectorized)\", 14);\n \n self->name = str;\n\n /* Do a better job someday */\n self->doc = \"dynamic ufunc based on a python function\";\n \n\t\n\treturn (PyObject *)self;\n}\n\n\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\t\n\tif ((self = PyObject_NEW(PyUFuncObject, &PyUFunc_Type)) == NULL) \n\t\treturn NULL;\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\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=PyArray_DescrFromType(usertype);\n \tPyObject *key, *cobj;\n\tint ret;\t\n\t\n\tif ((usertype < PyArray_USERDEF) || (descr==NULL)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"cannot register typenumber\");\n\t\treturn -1;\n\t}\n\tif (ufunc->userloops == NULL) {\n\t\tufunc->userloops = PyDict_New();\n\t}\n\tkey = PyInt_FromLong(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\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) free(self->buffer);\n Py_DECREF(self->ufunc);\n }\n PyObject_DEL(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]) free(self->buffer[0]);\n\t\tPy_XDECREF(self->errobj);\n\t\tPy_DECREF(self->ufunc);\n\t}\n\tPyObject_DEL(self);\n}\n\n\nstatic void\nufunc_dealloc(PyUFuncObject *self)\n{\n if (self->ptr) free(self->ptr);\n\tPy_XDECREF(self->userloops);\n Py_XDECREF(self->obj);\n\tPyObject_DEL(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\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 = 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\tfree(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\"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\nstatic PyTypeObject PyUFuncLoop_Type = {\n\tPyObject_HEAD_INIT(0)\n\t0,\t\t\t\t/*ob_size*/\n\t\"ufuncloop\",\t\t\t/*tp_name*/\n\tsizeof(PyUFuncLoopObject),\t/*tp_basicsize*/\n\t0,\t\t\t\t/*tp_itemsize*/\n\t/* methods */\n\t(destructor)ufuncloop_dealloc\t/*tp_dealloc*/\n};\n\n\nstatic PyTypeObject PyUFuncReduce_Type = {\n\tPyObject_HEAD_INIT(0)\n\t0,\t\t\t\t/*ob_size*/\n\t\"ufuncreduce\",\t\t\t/*tp_name*/\n\tsizeof(PyUFuncReduceObject),\t/*tp_basicsize*/\n\t0,\t\t\t\t/*tp_itemsize*/\n\t/* methods */\n\t(destructor)ufuncreduce_dealloc\t/*tp_dealloc*/\n};\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 \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\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 */\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\n#define UFUNC_REDUCE 0\n#define UFUNC_ACCUMULATE 1\n#define UFUNC_REDUCEAT 2\n#define UFUNC_OUTER 3\n\n\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\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\t\t\n\t\tkey = PyInt_FromLong((long) arg_types[0]);\n\t\tif (key == NULL) return -1;\n\t\tobj = PyDict_GetItem(self->userloops, key);\n\t\tif (obj == NULL) {\n\t\t\tPy_DECREF(key);\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\t\tPy_DECREF(key);\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\t*data = self->data[i];\n\t*function = self->functions[i];\n\n\treturn 0;\n}\n\nstatic int\n_getpyvalues(char *name, int *bufsize, int *errmask, PyObject **errobj)\n{\n\n PyObject *thedict;\n PyObject *ref=NULL;\n\tPyObject *retval;\n\n thedict = PyEval_GetLocals();\n ref = PyDict_GetItemString(thedict, UFUNC_PYVALS_NAME);\n if (ref == NULL) {\n\t\tthedict = PyEval_GetGlobals();\n\t\tref = PyDict_GetItemString(thedict, UFUNC_PYVALS_NAME);\n }\n if (ref == NULL) {\n \t thedict = PyEval_GetBuiltins();\n ref = PyDict_GetItemString(thedict, UFUNC_PYVALS_NAME);\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\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"buffer size (%d) is not \"\t\\\n\t\t\t \"in range (%d - %d)\", \n\t\t\t *bufsize, PyArray_MIN_BUFSIZE, \n\t\t\t PyArray_MAX_BUFSIZE);\n\t\treturn -1;\n\t}\t\n\n\t*errmask = PyInt_AsLong(PyList_GET_ITEM(ref, 1));\n\tif (*errmask < 0) {\n\t\tif (PyErr_Occurred()) return -1;\n\t\tPyErr_Format(PyExc_ValueError,\t\t\\\n\t\t\t \"invalid error mask (%d)\", \n\t\t\t *errmask);\n\t\treturn -1;\n\t}\n\t\n\tretval = PyList_GET_ITEM(ref, 2);\n\tif (retval != Py_None && !PyCallable_Check(retval)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"callback function must be callable\");\n\t\treturn -1;\n\t}\n\n\t*errobj = Py_BuildValue(\"NO\", \n\t\t\t\tPyString_FromString(name),\n\t\t\t\tretval);\n\tif (*errobj == NULL) return -1;\n\t\n\treturn 0;\n}\n\n\nstatic char\n_scalar_kind(int typenum, PyArrayObject **arr) \n{\n\tif (PyTypeNum_ISSIGNED(typenum)) return UFUNC_INTNEG_SCALAR;\n\tif (PyTypeNum_ISFLOAT(typenum)) return UFUNC_FLOAT_SCALAR;\n\tif (PyTypeNum_ISCOMPLEX(typenum)) return UFUNC_COMPLEX_SCALAR;\n\tif (PyTypeNum_ISUNSIGNED(typenum)) return UFUNC_INTPOS_SCALAR;\n\tif (PyTypeNum_ISBOOL(typenum)) return UFUNC_BOOL_SCALAR;\n\treturn UFUNC_OBJECT_SCALAR;\n}\n\n\n/* Create copies for any arrays that are less than loop->bufsize\n in total size and are mis-behaved or in need\n of casting.\n*/\n\nstatic int\n_create_copies(PyUFuncLoopObject *loop, int *arg_types, PyArrayObject **mps)\n{\n\tint nin = loop->ufunc->nin;\n\tint i;\n\tintp size;\n\tPyObject *new;\n\tPyArray_Typecode ntype = {PyArray_NOTYPE, 0, 0};\n\tPyArray_Typecode atype = {PyArray_NOTYPE, 0, 0};\n\n\tfor (i=0; ielsize;\n\t\t\tif (PyArray_EquivalentTypes(&atype, &ntype)) {\n\t\t\t\targ_types[i] = PyArray_TYPE(mps[i]);\n\t\t\t}\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.type_num = arg_types[i];\n\t\t\t\tntype.itemsize = 0;\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 |\t\\\n\t\t\t\t\t\t BEHAVED_FLAGS_RO);\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\nstatic int\nconstruct_matrices(PyUFuncLoopObject *loop, PyObject *args, PyArrayObject **mps)\n{\n int nargs, i, cnt, cntcast, maxsize;\n int arg_types[MAX_ARGS];\n\tchar scalars[MAX_ARGS];\n\tPyUFuncObject *self=loop->ufunc;\n\tBool allscalars=TRUE;\n\tPyTypeObject *subtype=&PyArray_Type;\n\n /* Check number of arguments */\n nargs = PyTuple_Size(args);\n if ((nargs != self->nin) && (nargs != self->nargs)) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid number of arguments\");\n return -1;\n }\n\n\n /* Get each input argument */\n for (i=0; inin; i++) {\n mps[i] = (PyArrayObject *)\\\n\t\t\tPyArray_FromAny(PyTuple_GET_ITEM(args,i), \n\t\t\t\t\tNULL, 0, 0, 0);\n if (mps[i] == NULL) return -1;\n arg_types[i] = PyArray_TYPE(mps[i]);\n if (PyTypeNum_ISFLEXIBLE(arg_types[i])) {\n PyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"ufuncs do not support\"\t\\\n \" flexible arrays\");\n return -1;\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\t\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 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 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_Typecode ntype = {PyArray_NOTYPE, 0, 0};\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\n\t\t/* reset types for outputs that are equivalent \n\t\t -- no sense casting uselessly\n\t\t*/\n\t\tif (mps[i]->descr->type_num != arg_types[i]) {\n\t\t\tPyArray_Typecode atype = {PyArray_NOTYPE, 0, 0};\n\t\t\tntype.type_num = PyArray_TYPE(mps[i]);\n\t\t\tntype.itemsize = PyArray_ITEMSIZE(mps[i]);\n\t\t\tatype.type_num = arg_types[i];\n\t\t\tatype.itemsize = \\\n\t\t\t\tPyArray_DescrFromType(arg_types[i])->elsize;\n\t\t\tif (PyArray_EquivalentTypes(&atype, &ntype)) {\n\t\t\t\targ_types[i] = PyArray_TYPE(mps[i]);\n\t\t\t}\n\t\t}\n\n\t\t/* still not the same -- or will we have to use buffers?*/\n\t\tif (mps[i]->descr->type_num != arg_types[i] ||\n\t\t !PyArray_ISBEHAVED_RO(mps[i])) {\n\t\t\tif (loop->size < loop->bufsize) {\n\t\t\t\tPyObject *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\tntype.type_num = arg_types[i];\n\t\t\t\tntype.itemsize = 0;\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 | \n\t\t\t\t\t\t BEHAVED_FLAGS_RO |\n\t\t\t\t\t\t UPDATEIFCOPY);\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\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\tcnt = cntcast = 0; /* keeps track of bytes to allocate */\n\tmaxsize = 0;\n for (i=0; inargs; i++) {\n\t\tcnt += mps[i]->itemsize;\n if (arg_types[i] != mps[i]->descr->type_num) {\n\t\t\tPyArray_Descr *descr;\n\n loop->meth = BUFFER_UFUNCLOOP;\n\t\t\tdescr = PyArray_DescrFromType(arg_types[i]);\n\t\t\tcntcast += descr->elsize;\n if (i < self->nin) {\n loop->cast[i] = \\\n\t\t\t\t\tmps[i]->descr->cast[arg_types[i]];\n\t\t\t}\n else {\n loop->cast[i] = descr->\\\n\t\t\t\t\tcast[mps[i]->descr->type_num];\n\t\t\t}\n\n }\n loop->swap[i] = !(PyArray_ISNOTSWAPPED(mps[i]));\n if (!PyArray_ISBEHAVED_RO(mps[i])) {\n loop->meth = BUFFER_UFUNCLOOP;\n }\n if (!loop->obj && mps[i]->descr->type_num == PyArray_OBJECT)\n loop->obj = 1;\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 == NOBUFFER_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\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\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 }\n else if (loop->meth == BUFFER_UFUNCLOOP) {\n for (i=0; inargs; i++) {\n\t\t\tloop->steps[i] = mps[i]->itemsize; \n\t\t}\n }\n\telse { /* uniformly-strided case ONE_UFUNCLOOP */\n\t\tfor (i=0; inargs; i++) {\n\t\t\tif (mps[i]->nd == 0)\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\tif (loop->meth == BUFFER_UFUNCLOOP) {\n\t\tchar *castptr;\n\t\tint oldsize=0;\n\t\tloop->buffer[0] = (char *)malloc(loop->bufsize*(cnt+cntcast));\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\t\tif (loop->buffer[0] == NULL) return -1;\n\t\tcastptr = loop->buffer[0] + loop->bufsize*cnt;\n\t\tfor (i=0; inargs; i++) {\n\t\t\tif (i > 0)\n\t\t\t\tloop->buffer[i] = loop->buffer[i-1] + \\\n\t\t\t\t\tloop->bufsize * mps[i-1]->itemsize;\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\tloop->castbuf[i] = castptr + \n\t\t\t\t\tloop->bufsize*oldsize;\n\t\t\t\t/* fprintf(stderr, \"castbuf[%d] = %p\\n\", i, loop->castbuf[i]); */\n#define _PyD PyArray_DescrFromType\n\t\t\t\toldsize = _PyD(arg_types[i])->elsize;\n#undef _PyD\n\t\t\t\tloop->bufptr[i] = loop->castbuf[i];\n\t\t\t\tcastptr = loop->castbuf[i];\n\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\tloop->dptr[i] = loop->buffer[i];\n\t\t}\n\t}\n\n return nargs;\n}\n\nstatic PyTypeObject PyUFuncLoop_Type;\n\nstatic void ufuncloop_dealloc(PyUFuncLoopObject *);\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\tif ((loop=PyObject_NEW(PyUFuncLoopObject, &PyUFuncLoop_Type)) == NULL)\n\t\treturn NULL;\n\t/* --- no real speed increase this way\n\tloop = malloc(sizeof(PyUFuncLoopObject));\n\t*/\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 (_getpyvalues((self->name ? self->name : \"\"),\n\t\t\t &(loop->bufsize), &(loop->errormask), \n\t\t\t &(loop->errobj)) < 0)\n\t\tgoto fail;\n\n\t/* Setup the matrices */\n\tif (construct_matrices(loop, args, mps) < 0) goto fail;\n\t\n\tPyUFunc_clearfperr();\n\n\treturn loop;\n\n fail:\n\tufuncloop_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 something besides NULL, NULL \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\nstatic int \nPyUFunc_GenericFunction(PyUFuncObject *self, PyObject *args, \n\t\t\tPyArrayObject **mps) \n{\n\tPyUFuncLoopObject *loop;\n\tint i;\n\tint temp;\n BEGIN_THREADS_DEF\n\n\tif (!(loop = construct_loop(self, args, mps))) return -1;\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();\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();\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\t/* Make local copies of all loop variables */\n\t\t/* Optimizations needed:\n\t\t 1) move data better into the buffer better\n\t\t --- not one at a time -- this requires some \n pre-analysis and is only possible over \n the largest dimension.\n\t\t*/\n\n\t\tPyArray_CopySwapNFunc *copyswapn[MAX_ARGS];\n\t\tPyArrayIterObject **iters=loop->iters;\n\t\tint *swap=loop->swap;\n\t\tvoid **dptr=loop->dptr;\n\t\tint mpselsize[MAX_ARGS];\n\t\tintp index=loop->index, size=loop->size;\n\t\tintp bufcnt=loop->bufcnt;\n\t\tint bufsize=loop->bufsize;\n\t\tvoid **bufptr = loop->bufptr;\n\t\tvoid **buffer = loop->buffer;\n\t\tvoid **castbuf = loop->castbuf;\n\t\tintp *steps = loop->steps;\n\t\tBool pyobject[MAX_ARGS];\n\t\t\n\t\tfor (i=0; inargs; i++) {\n\t\t\tcopyswapn[i] = mps[i]->descr->copyswapn;\n\t\t\tmpselsize[i] = mps[i]->itemsize;\n\t\t\tpyobject[i] = (loop->obj && \\\n (mps[i]->descr->type_num == PyArray_OBJECT));\n\t\t}\n\t\t/* Do generic buffered looping here (works for any kind of\n\t\t arrays): Everything uses a buffer. \n\n\t\t 1. fill the input buffers.\n\t\t 2. If buffer is filled then \n\t\t a. cast any input buffers needing it. \n\t\t b. call inner function (which loops over the buffer).\n\t\t\t c. cast any output buffers needing it.\n\t\t\t d. copy output buffer back to output arrays.\n 3. goto next position\n\t\t*/ \n\t\t/*fprintf(stderr, \"BUFFER...%d\\n\", loop->size);*/\n\t\t/*\n\t\tfor (i=0; inargs; i++) {\n\t\t\tfprintf(stderr, \"iters[%d]->dataptr = %p, %p of size %d\\n\", i, \n\t\t\t\titers[i], iters[i]->ao->data, PyArray_NBYTES(iters[i]->ao));\n\t\t}\n\t\t*/\n\t\twhile (index < size) {\n\t\t\t/*copy input data */\n\t\t\tfor (i=0; inin; i++) {\n\t\t\t\tif (pyobject[i]) {\n\t\t\t\t\tPy_INCREF(*((PyObject **)iters[i]->dataptr));\n\t\t\t\t}\n\t\t\t\t/*\t\t\t\tfprintf(stderr, \"index = %d, i=%d, writing to %p\\n\", index, i, dptr[i]); */\n\t\t\t\tmemcpy(dptr[i], iters[i]->dataptr,\n\t\t\t\t mpselsize[i]);\n\t\t\t\tdptr[i] += mpselsize[i];\n\t\t\t\tPyArray_ITER_NEXT(iters[i]);\n\t\t\t}\n\t\t\tbufcnt++;\n\t\t\tindex++; \n\t\t\tif ((bufcnt == bufsize) || \\\n\t\t\t (index == size)) {\n\t\t\t\t\n\t\t\t\tfor (i=0; inin; i++) {\n\t\t\t\t\tif (swap[i]) {\n\t\t\t\t\t\t/* fprintf(stderr, \"swapping...\\n\");*/\n\t\t\t\t\t\tcopyswapn[i](buffer[i], NULL,\n\t\t\t\t\t\t\t bufcnt, 1, \n\t\t\t\t\t\t\t mpselsize[i]);\n\t\t\t\t\t}\n\t\t\t\t\tif (loop->cast[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 bufcnt,\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\n\t\t\t\tloop->function((char **)bufptr, \n\t\t\t\t\t &bufcnt, \n\t\t\t\t\t steps, loop->funcdata);\n \n\t\t\t\tUFUNC_CHECK_ERROR();\n\n\t\t\t\tfor (i=self->nin; inargs; i++) {\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 bufcnt,\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\t/* fprintf(stderr, \"swapping back...\\n\"); */\n\t\t\t\t\t\tcopyswapn[i](buffer[i], NULL,\n\t\t\t\t\t\t\t bufcnt, 1, \n\t\t\t\t\t\t\t mpselsize[i]);\n\t\t\t\t\t}\n\t\t\t\t\tfor (temp = 0; temp < bufcnt; temp++) {\n\t\t\t\t\t\t/* fprintf(stderr, \"temp=%d, i=%d; reading from %p\\n\", temp, i, dptr[i]);*/\n\t\t\t\t\t\tif (pyobject[i]) {\n\t\t\t\t\t\t\tPy_XDECREF(*((PyObject **)iters[i]->dataptr));\n\t\t\t\t\t\t\tPy_INCREF(*((PyObject **)dptr[i]));\n\t\t\t\t\t\t}\n\t\t\t\t\t\tmemcpy(iters[i]->dataptr,\n\t\t\t\t\t\t dptr[i], mpselsize[i]);\n\t\t\t\t\t\tPyArray_ITER_NEXT(iters[i]);\n\t\t\t\t\t\tdptr[i] += mpselsize[i];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbufcnt = 0;\n\t\t\t\tfor (i=0; inargs; i++) \n\t\t\t\t\tdptr[i] = buffer[i];\n\t\t\t\t\n\t\t\t} \n\t\t}\n\t}\n\t}\t\n\t\n LOOP_END_THREADS\n\n\tPy_DECREF(loop);\n\treturn 0;\n\n fail:\n LOOP_END_THREADS\n\n\tPy_DECREF(loop); \n\treturn -1;\n }\n\nstatic PyArrayObject *\n_getidentity(PyUFuncObject *self, int otype, char *str)\n{\n PyObject *obj, *arr;\n PyArray_Typecode typecode = {otype, 0, 0};\n\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\t\n arr = PyArray_FromAny(obj, &typecode, 0, 0, CARRAY_FLAGS);\n Py_DECREF(obj);\n return (PyArrayObject *)arr;\n}\n\nstatic int\n_create_reduce_copy(PyUFuncReduceObject *loop, PyArrayObject **arr, int rtype)\n{\n\tintp maxsize;\n\tPyObject *new;\n\tPyArray_Typecode ntype = {rtype, 0, 0};\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\tnew = PyArray_FromAny((PyObject *)(*arr), \n\t\t\t\t\t &ntype, 0, 0,\n\t\t\t\t\t FORCECAST |\t\t\\\n\t\t\t\t\t BEHAVED_FLAGS_RO);\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\t\n\treturn 0;\n}\n\n\n\nstatic PyTypeObject PyUFuncReduce_Type;\n\nstatic void ufuncreduce_dealloc(PyUFuncReduceObject *);\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\tif ((loop=PyObject_NEW(PyUFuncReduceObject, \n\t\t\t &PyUFuncReduce_Type)) == NULL)\n\t\treturn NULL;\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 (_getpyvalues(str, &(loop->bufsize), &(loop->errormask), \n\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 if (loop->meth == ZERODIM_REDUCELOOP) {\n idarr = _getidentity(self, otype, str);\n if (idarr == NULL) goto fail;\n if (idarr->itemsize > 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->itemsize);\n Py_DECREF(idarr);\n goto fail;\n }\n memcpy(loop->idptr, idarr->data, idarr->itemsize);\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->itemsize;\n loop->outsize = loop->ret->itemsize;\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\t\n\tif (loop->meth == BUFFER_UFUNCLOOP) {\n\n\t\tloop->steps[0] = loop->outsize;\n if (otype != aar->descr->type_num) {\n loop->buffer = (char *)malloc(loop->bufsize*\\\n (loop->outsize + \\\n aar->itemsize));\n if (loop->buffer == NULL) goto fail;\n loop->castbuf = loop->buffer + \\\n loop->bufsize*aar->itemsize;\n loop->bufptr[0] = loop->castbuf; \n loop->cast = aar->descr->cast[otype];\n }\n else {\n loop->buffer = (char *)malloc(loop->bufsize*\\\n loop->outsize);\n if (loop->buffer == NULL) goto fail;\n loop->bufptr[0] = loop->buffer;\n }\n\t}\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\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\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:\n\t\t/*fprintf(stderr, \"ONEDIM..%d\\n\", loop->size); */\n while(loop->index < loop->size) {\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:\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 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();\n\n PyArray_ITER_NEXT(loop->it)\n loop->bufptr[1] += loop->outsize;\n loop->bufptr[2] = loop->bufptr[1];\n loop->index++; \n\t\t\tif (PyErr_Occurred()) goto fail;\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->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\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->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->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();\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 Py_DECREF(loop);\n return (PyObject *)ret;\n\n fail:\n LOOP_END_THREADS\n\n Py_XDECREF(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\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 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 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();\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->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\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->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->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();\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 Py_DECREF(loop);\n return (PyObject *)ret;\n\n fail:\n\tLOOP_END_THREADS\n\n Py_XDECREF(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\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\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();\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; ibufptr[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->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();\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 Py_DECREF(loop);\n return (PyObject *)ret;\n\t\n fail:\n\tLOOP_END_THREADS\n\n\tPy_XDECREF(loop);\n\treturn NULL;\n}\n\n\n/* This code handles reduce, reduceat, and accumulate \n (accumulate and reduce are special cases of the more general reduceat \n but they are handled separately for speed) \n*/\n\nstatic PyObject * \nPyUFunc_GenericReduction(PyUFuncObject *self, PyObject *args, \n PyObject *kwds, int operation) \n{\n\tint axis=0;\n\tPyArrayObject *mp, *ret = NULL;\n\tPyObject *op, *res=NULL;\n\tPyObject *obj_ind; \n\tPyArrayObject *indices = NULL;\n\tPyArray_Typecode otype= {PyArray_NOTYPE, 0, 0};\n PyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tstatic char *kwlist1[] = {\"array\", \"axis\", \"rtype\", NULL};\n\tstatic char *kwlist2[] = {\"array\", \"indices\", \"axis\", \"rtype\", 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\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_TypecodeConverter, \n\t\t\t\t\t\t&otype)) return NULL;\n indices = (PyArrayObject *)PyArray_FromAny(obj_ind, &indtype, \n\t\t\t\t\t\t\t 1, 1, CARRAY_FLAGS);\n if (indices == NULL) return NULL;\n\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_TypecodeConverter, \n\t\t\t\t\t\t&otype)) return NULL;\n\t}\n\t\n\t/* Ensure input is an array */\t\n\tmp = (PyArrayObject *)PyArray_FromAny(op, NULL, 0, 0, 0);\n\tif (mp == NULL) return NULL;\n\n /* Check to see if input is zero-dimensional */\n if (mp->nd == 0) {\n PyErr_Format(PyExc_TypeError, \"cannot %s on a scalar\",\n _reduce_type[operation]);\n Py_DECREF(mp);\n return NULL; \n }\n\n /* Check to see that type (and otype) is not FLEXIBLE */\n\tif (PyArray_ISFLEXIBLE(mp) || 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.type_num == PyArray_NOTYPE) {\t\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->itemsize < sizeof(long))) {\n\t\t\tif (PyTypeNum_ISUNSIGNED(typenum))\n\t\t\t\totype.type_num = PyArray_ULONG;\n\t\t\telse\n\t\t\t\totype.type_num = 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\totype.type_num = PyArray_LONG;\n\t\t}\n\t\telse {\n\t\t\totype.type_num = typenum;\n\t\t}\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\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}\n\tif (res == NULL) PyErr_Clear();\n\telse if (res == Py_None) Py_DECREF(res);\n\telse {\n\t\tPy_DECREF(ret);\n\t\treturn res;\n\t}\t\n\treturn PyArray_Return(ret);\n\t\n}\n\n\n\n/* ---------- */\n\nstatic PyObject *\n_find_array_wrap(PyObject *args)\n{\n\tint nargs, i;\n\tint np = 0;\n\tint argmax = 0;\n\tint val;\n\tdouble priority[MAX_ARGS];\n\tdouble maxpriority = PyArray_SUBTYPE_PRIORITY;\n\tPyObject *with_wrap[MAX_ARGS];\n\tPyObject *attr;\n\tPyObject *obj;\n\n\tnargs = PyTuple_Size(args);\n\tfor (i=0; i maxpriority) {\n\t\t\tmaxpriority = priority[i];\n\t\t\targmax = i;\n\t\t}\n\t}\n\n\treturn with_wrap[argmax];\n}\n\nstatic PyObject *\nufunc_generic_call(PyUFuncObject *self, PyObject *args) \n{\n\tint i;\n\tPyTupleObject *ret;\n\tPyArrayObject *mps[MAX_ARGS];\n\tPyObject *retobj[MAX_ARGS];\n\tPyObject *res;\n\tPyObject *obj;\n\t\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\tif (PyUFunc_GenericFunction(self, args, mps) == -1) {\n\t\tfor(i=0; inargs; i++) Py_XDECREF(mps[i]);\n\t\treturn NULL;\n\t}\n\t\n\tfor(i=0; inin; i++) Py_DECREF(mps[i]);\n\n\t/* Use __array_wrap__ on all outputs \n\t if present on one of the input arguments.\n\t If present for multiple inputs:\n\t use __array_wrap__ of input object with largest \n\t\t__array_priority__ (default = 0.0)\n\t */\n\tobj = _find_array_wrap(args);\n\t\n\t/* wrap outputs */\n\tfor (i=0; inout; i++) {\n\t\tint j=self->nin+i;\n\t\t/* check to see if any UPDATEIFCOPY flags are set \n\t\t which meant that a temporary output was generated \n\t\t*/\n\t\tif (mps[j]->flags & UPDATEIFCOPY) {\n\t\t\tPyObject *old = mps[j]->base;\n\t\t\tPy_INCREF(old); /* we want to hang on to this */\n\t\t\tPy_DECREF(mps[j]); /* should trigger the copy \n\t\t\t\t\t back into old */\n\t\t\tmps[j] = (PyArrayObject *)old;\n\t\t}\n\t\tif (obj != NULL) {\n\t\t\tres = PyObject_CallMethod(obj, \"__array_wrap__\",\n\t\t\t\t\t\t \"O\", mps[j]);\n\t\t\tif (res == NULL) PyErr_Clear();\n\t\t\telse if (res == Py_None) Py_DECREF(res);\n\t\t\telse {\n\t\t\t\tPy_DECREF(mps[j]);\n\t\t\t\tretobj[i] = res;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\tretobj[i] = PyArray_Return(mps[j]);\n\t}\n\t\n\tif (self->nout == 1) { \n\t\treturn retobj[0];\n\t} else { \n\t\tret = (PyTupleObject *)PyTuple_New(self->nout);\n\t\tfor(i=0; inout; i++) {\n\t\t\tPyTuple_SET_ITEM(ret, i, retobj[i]);\n\t\t}\n\t\treturn (PyObject *)ret;\n\t}\t\n\n}\n\nstatic 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\tif ((self = PyObject_NEW(PyUFuncObject, &PyUFunc_Type)) == NULL) \n\t\treturn NULL;\n\t\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 = malloc(offset[0] + offset[1] + sizeof(void *) + \\\n\t\t\t (fname_len+14));\n\n\tif (self->ptr == NULL) return PyErr_NoMemory();\n Py_INCREF(function);\n self->obj = function;\n\tfdata = (PyUFunc_PyFuncData *)(self->ptr);\n fdata->nin = nin;\n fdata->nout = nout;\n fdata->callable = function;\n \n self->data = (void **)(self->ptr + offset[0]);\n self->data[0] = (void *)fdata;\n\t\n\tself->types = (char *)self->data + sizeof(void *);\n for (i=0; inargs; i++) self->types[i] = PyArray_OBJECT;\n\n str = self->types + offset[1];\n memcpy(str, fname, fname_len);\n memcpy(str+fname_len, \" (vectorized)\", 14);\n \n self->name = str;\n\n /* Do a better job someday */\n self->doc = \"dynamic ufunc based on a python function\";\n \n\t\n\treturn (PyObject *)self;\n}\n\n\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\t\n\tif ((self = PyObject_NEW(PyUFuncObject, &PyUFunc_Type)) == NULL) \n\t\treturn NULL;\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\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=PyArray_DescrFromType(usertype);\n \tPyObject *key, *cobj;\n\tint ret;\t\n\t\n\tif ((usertype < PyArray_USERDEF) || (descr==NULL)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"cannot register typenumber\");\n\t\treturn -1;\n\t}\n\tif (ufunc->userloops == NULL) {\n\t\tufunc->userloops = PyDict_New();\n\t}\n\tkey = PyInt_FromLong(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\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) free(self->buffer);\n Py_DECREF(self->ufunc);\n }\n PyObject_DEL(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]) free(self->buffer[0]);\n\t\tPy_XDECREF(self->errobj);\n\t\tPy_DECREF(self->ufunc);\n\t}\n\tPyObject_DEL(self);\n}\n\n\nstatic void\nufunc_dealloc(PyUFuncObject *self)\n{\n if (self->ptr) free(self->ptr);\n\tPy_XDECREF(self->userloops);\n Py_XDECREF(self->obj);\n\tPyObject_DEL(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\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 = 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\tfree(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\"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\nstatic PyTypeObject PyUFuncLoop_Type = {\n\tPyObject_HEAD_INIT(0)\n\t0,\t\t\t\t/*ob_size*/\n\t\"ufuncloop\",\t\t\t/*tp_name*/\n\tsizeof(PyUFuncLoopObject),\t/*tp_basicsize*/\n\t0,\t\t\t\t/*tp_itemsize*/\n\t/* methods */\n\t(destructor)ufuncloop_dealloc\t/*tp_dealloc*/\n};\n\n\nstatic PyTypeObject PyUFuncReduce_Type = {\n\tPyObject_HEAD_INIT(0)\n\t0,\t\t\t\t/*ob_size*/\n\t\"ufuncreduce\",\t\t\t/*tp_name*/\n\tsizeof(PyUFuncReduceObject),\t/*tp_basicsize*/\n\t0,\t\t\t\t/*tp_itemsize*/\n\t/* methods */\n\t(destructor)ufuncreduce_dealloc\t/*tp_dealloc*/\n};\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": 39, "end_line": 49, "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": 52, "end_line": 63, "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": 66, "end_line": 77, "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": 80, "end_line": 91, "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": 95, "end_line": 108, "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": 111, "end_line": 124, "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": 127, "end_line": 140, "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": 143, "end_line": 158, "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": 161, "end_line": 183, "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": 194, "end_line": 201, "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": 204, "end_line": 211, "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": 214, "end_line": 222, "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": 225, "end_line": 234, "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": 238, "end_line": 249, "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": 252, "end_line": 263, "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": 267, "end_line": 278, "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": 282, "end_line": 293, "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": 296, "end_line": 311, "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": 314, "end_line": 336, "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": 345, "end_line": 393, "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": 417, "end_line": 463, "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": 467, "end_line": 496, "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": 501, "end_line": 506, "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": 536, "end_line": 562, "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": 565, "end_line": 586, "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": 70, "complexity": 17, "token_count": 455, "parameters": [ "self", "arg_types", "function", "data", "scalars" ], "start_line": 590, "end_line": 671, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 82, "top_nesting_level": 0 }, { "name": "_getpyvalues", "long_name": "_getpyvalues( char * name , int * bufsize , int * errmask , PyObject ** errobj)", "filename": "ufuncobject.c", "nloc": 60, "complexity": 15, "token_count": 348, "parameters": [ "name", "bufsize", "errmask", "errobj" ], "start_line": 674, "end_line": 740, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 67, "top_nesting_level": 0 }, { "name": "_scalar_kind", "long_name": "_scalar_kind( int typenum , PyArrayObject ** arr)", "filename": "ufuncobject.c", "nloc": 9, "complexity": 6, "token_count": 64, "parameters": [ "typenum", "arr" ], "start_line": 744, "end_line": 752, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "_create_copies", "long_name": "_create_copies( PyUFuncLoopObject * loop , int * arg_types , PyArrayObject ** mps)", "filename": "ufuncobject.c", "nloc": 37, "complexity": 8, "token_count": 285, "parameters": [ "loop", "arg_types", "mps" ], "start_line": 761, "end_line": 803, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "top_nesting_level": 0 }, { "name": "construct_matrices", "long_name": "construct_matrices( PyUFuncLoopObject * loop , PyObject * args , PyArrayObject ** mps)", "filename": "ufuncobject.c", "nloc": 237, "complexity": 57, "token_count": 1860, "parameters": [ "loop", "args", "mps" ], "start_line": 806, "end_line": 1137, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 332, "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": 203, "parameters": [ "self", "args", "mps" ], "start_line": 1144, "end_line": 1184, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 41, "top_nesting_level": 0 }, { "name": "PyUFunc_GenericFunction", "long_name": "PyUFunc_GenericFunction( PyUFuncObject * self , PyObject * args , PyArrayObject ** mps)", "filename": "ufuncobject.c", "nloc": 117, "complexity": 24, "token_count": 828, "parameters": [ "self", "args", "mps" ], "start_line": 1252, "end_line": 1424, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 173, "top_nesting_level": 0 }, { "name": "_getidentity", "long_name": "_getidentity( PyUFuncObject * self , int otype , char * str)", "filename": "ufuncobject.c", "nloc": 19, "complexity": 3, "token_count": 118, "parameters": [ "self", "otype", "str" ], "start_line": 1427, "end_line": 1447, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "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": 1450, "end_line": 1472, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "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": 169, "complexity": 35, "token_count": 1333, "parameters": [ "self", "arr", "axis", "otype", "operation", "ind_size", "str" ], "start_line": 1481, "end_line": 1691, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 211, "top_nesting_level": 0 }, { "name": "PyUFunc_Reduce", "long_name": "PyUFunc_Reduce( PyUFuncObject * self , PyArrayObject * arr , int axis , int otype)", "filename": "ufuncobject.c", "nloc": 100, "complexity": 16, "token_count": 660, "parameters": [ "self", "arr", "axis", "otype" ], "start_line": 1703, "end_line": 1833, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 131, "top_nesting_level": 0 }, { "name": "PyUFunc_Accumulate", "long_name": "PyUFunc_Accumulate( PyUFuncObject * self , PyArrayObject * arr , int axis , int otype)", "filename": "ufuncobject.c", "nloc": 101, "complexity": 15, "token_count": 683, "parameters": [ "self", "arr", "axis", "otype" ], "start_line": 1837, "end_line": 1967, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 131, "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": 107, "complexity": 20, "token_count": 765, "parameters": [ "self", "arr", "ind", "axis", "otype" ], "start_line": 1989, "end_line": 2115, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 127, "top_nesting_level": 0 }, { "name": "PyUFunc_GenericReduction", "long_name": "PyUFunc_GenericReduction( PyUFuncObject * self , PyObject * args , PyObject * kwds , int operation)", "filename": "ufuncobject.c", "nloc": 113, "complexity": 29, "token_count": 709, "parameters": [ "self", "args", "kwds", "operation" ], "start_line": 2124, "end_line": 2252, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 129, "top_nesting_level": 0 }, { "name": "_find_array_wrap", "long_name": "_find_array_wrap( PyObject * args)", "filename": "ufuncobject.c", "nloc": 49, "complexity": 12, "token_count": 260, "parameters": [ "args" ], "start_line": 2259, "end_line": 2311, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "top_nesting_level": 0 }, { "name": "ufunc_generic_call", "long_name": "ufunc_generic_call( PyUFuncObject * self , PyObject * args)", "filename": "ufuncobject.c", "nloc": 46, "complexity": 12, "token_count": 356, "parameters": [ "self", "args" ], "start_line": 2314, "end_line": 2379, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 66, "top_nesting_level": 0 }, { "name": "ufunc_frompyfunc", "long_name": "ufunc_frompyfunc( PyObject * dummy , PyObject * args , PyObject * kwds)", "filename": "ufuncobject.c", "nloc": 58, "complexity": 10, "token_count": 516, "parameters": [ "dummy", "args", "kwds" ], "start_line": 2387, "end_line": 2475, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 89, "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": 26, "complexity": 4, "token_count": 181, "parameters": [ "func", "data", "types", "ntypes", "nin", "nout", "identity", "name", "doc", "check_return" ], "start_line": 2479, "end_line": 2510, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "PyUFunc_RegisterLoopForType", "long_name": "PyUFunc_RegisterLoopForType( PyUFuncObject * ufunc , int usertype , PyUFuncGenericFunction function , * data)", "filename": "ufuncobject.c", "nloc": 41, "complexity": 8, "token_count": 241, "parameters": [ "ufunc", "usertype", "function", "data" ], "start_line": 2513, "end_line": 2554, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 42, "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": 2557, "end_line": 2569, "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": 2572, "end_line": 2584, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 2588, "end_line": 2594, "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": 2597, "end_line": 2604, "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": 2616, "end_line": 2685, "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": 2689, "end_line": 2693, "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": 2696, "end_line": 2700, "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": 2703, "end_line": 2706, "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": 2726, "end_line": 2748, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "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": 2753, "end_line": 2836, "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": 2841, "end_line": 2844, "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": 39, "end_line": 49, "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": 52, "end_line": 63, "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": 66, "end_line": 77, "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": 80, "end_line": 91, "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": 95, "end_line": 108, "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": 111, "end_line": 124, "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": 127, "end_line": 140, "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": 143, "end_line": 158, "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": 161, "end_line": 183, "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": 194, "end_line": 201, "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": 204, "end_line": 211, "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": 214, "end_line": 222, "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": 225, "end_line": 234, "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": 238, "end_line": 249, "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": 252, "end_line": 263, "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": 267, "end_line": 278, "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": 282, "end_line": 293, "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": 296, "end_line": 311, "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": 314, "end_line": 336, "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": 345, "end_line": 393, "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": 417, "end_line": 463, "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": 467, "end_line": 496, "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": 501, "end_line": 506, "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": 536, "end_line": 562, "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": 565, "end_line": 586, "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": 70, "complexity": 17, "token_count": 455, "parameters": [ "self", "arg_types", "function", "data", "scalars" ], "start_line": 590, "end_line": 671, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 82, "top_nesting_level": 0 }, { "name": "_getpyvalues", "long_name": "_getpyvalues( char * name , int * bufsize , int * errmask , PyObject ** errobj)", "filename": "ufuncobject.c", "nloc": 60, "complexity": 15, "token_count": 348, "parameters": [ "name", "bufsize", "errmask", "errobj" ], "start_line": 674, "end_line": 740, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 67, "top_nesting_level": 0 }, { "name": "_scalar_kind", "long_name": "_scalar_kind( int typenum , PyArrayObject ** arr)", "filename": "ufuncobject.c", "nloc": 9, "complexity": 6, "token_count": 64, "parameters": [ "typenum", "arr" ], "start_line": 744, "end_line": 752, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "_create_copies", "long_name": "_create_copies( PyUFuncLoopObject * loop , int * arg_types , PyArrayObject ** mps)", "filename": "ufuncobject.c", "nloc": 37, "complexity": 8, "token_count": 285, "parameters": [ "loop", "arg_types", "mps" ], "start_line": 761, "end_line": 803, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "top_nesting_level": 0 }, { "name": "construct_matrices", "long_name": "construct_matrices( PyUFuncLoopObject * loop , PyObject * args , PyArrayObject ** mps)", "filename": "ufuncobject.c", "nloc": 237, "complexity": 57, "token_count": 1859, "parameters": [ "loop", "args", "mps" ], "start_line": 806, "end_line": 1137, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 332, "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": 203, "parameters": [ "self", "args", "mps" ], "start_line": 1144, "end_line": 1184, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 41, "top_nesting_level": 0 }, { "name": "PyUFunc_GenericFunction", "long_name": "PyUFunc_GenericFunction( PyUFuncObject * self , PyObject * args , PyArrayObject ** mps)", "filename": "ufuncobject.c", "nloc": 117, "complexity": 24, "token_count": 828, "parameters": [ "self", "args", "mps" ], "start_line": 1252, "end_line": 1424, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 173, "top_nesting_level": 0 }, { "name": "_getidentity", "long_name": "_getidentity( PyUFuncObject * self , int otype , char * str)", "filename": "ufuncobject.c", "nloc": 19, "complexity": 3, "token_count": 118, "parameters": [ "self", "otype", "str" ], "start_line": 1427, "end_line": 1447, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "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": 1450, "end_line": 1472, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "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": 169, "complexity": 35, "token_count": 1333, "parameters": [ "self", "arr", "axis", "otype", "operation", "ind_size", "str" ], "start_line": 1481, "end_line": 1691, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 211, "top_nesting_level": 0 }, { "name": "PyUFunc_Reduce", "long_name": "PyUFunc_Reduce( PyUFuncObject * self , PyArrayObject * arr , int axis , int otype)", "filename": "ufuncobject.c", "nloc": 100, "complexity": 16, "token_count": 660, "parameters": [ "self", "arr", "axis", "otype" ], "start_line": 1703, "end_line": 1833, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 131, "top_nesting_level": 0 }, { "name": "PyUFunc_Accumulate", "long_name": "PyUFunc_Accumulate( PyUFuncObject * self , PyArrayObject * arr , int axis , int otype)", "filename": "ufuncobject.c", "nloc": 101, "complexity": 15, "token_count": 683, "parameters": [ "self", "arr", "axis", "otype" ], "start_line": 1837, "end_line": 1967, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 131, "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": 107, "complexity": 20, "token_count": 765, "parameters": [ "self", "arr", "ind", "axis", "otype" ], "start_line": 1989, "end_line": 2115, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 127, "top_nesting_level": 0 }, { "name": "PyUFunc_GenericReduction", "long_name": "PyUFunc_GenericReduction( PyUFuncObject * self , PyObject * args , PyObject * kwds , int operation)", "filename": "ufuncobject.c", "nloc": 113, "complexity": 29, "token_count": 709, "parameters": [ "self", "args", "kwds", "operation" ], "start_line": 2124, "end_line": 2252, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 129, "top_nesting_level": 0 }, { "name": "_find_array_wrap", "long_name": "_find_array_wrap( PyObject * args)", "filename": "ufuncobject.c", "nloc": 49, "complexity": 12, "token_count": 260, "parameters": [ "args" ], "start_line": 2259, "end_line": 2311, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "top_nesting_level": 0 }, { "name": "ufunc_generic_call", "long_name": "ufunc_generic_call( PyUFuncObject * self , PyObject * args)", "filename": "ufuncobject.c", "nloc": 46, "complexity": 12, "token_count": 356, "parameters": [ "self", "args" ], "start_line": 2314, "end_line": 2379, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 66, "top_nesting_level": 0 }, { "name": "ufunc_frompyfunc", "long_name": "ufunc_frompyfunc( PyObject * dummy , PyObject * args , PyObject * kwds)", "filename": "ufuncobject.c", "nloc": 58, "complexity": 10, "token_count": 516, "parameters": [ "dummy", "args", "kwds" ], "start_line": 2387, "end_line": 2475, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 89, "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": 26, "complexity": 4, "token_count": 181, "parameters": [ "func", "data", "types", "ntypes", "nin", "nout", "identity", "name", "doc", "check_return" ], "start_line": 2479, "end_line": 2510, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "PyUFunc_RegisterLoopForType", "long_name": "PyUFunc_RegisterLoopForType( PyUFuncObject * ufunc , int usertype , PyUFuncGenericFunction function , * data)", "filename": "ufuncobject.c", "nloc": 41, "complexity": 8, "token_count": 241, "parameters": [ "ufunc", "usertype", "function", "data" ], "start_line": 2513, "end_line": 2554, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 42, "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": 2557, "end_line": 2569, "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": 2572, "end_line": 2584, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 2588, "end_line": 2594, "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": 2597, "end_line": 2604, "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": 2616, "end_line": 2685, "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": 2689, "end_line": 2693, "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": 2696, "end_line": 2700, "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": 2703, "end_line": 2706, "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": 2726, "end_line": 2748, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "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": 2753, "end_line": 2836, "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": 2841, "end_line": 2844, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "construct_matrices", "long_name": "construct_matrices( PyUFuncLoopObject * loop , PyObject * args , PyArrayObject ** mps)", "filename": "ufuncobject.c", "nloc": 237, "complexity": 57, "token_count": 1860, "parameters": [ "loop", "args", "mps" ], "start_line": 806, "end_line": 1137, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 332, "top_nesting_level": 0 } ], "nloc": 2126, "complexity": 443, "token_count": 15768, "diff_parsed": { "added": [ "\t\t\tif (PyArray_SIZE(mps[i])==1)" ], "deleted": [ "\t\t\tif (mps[i]->nd == 0)" ] } } ] }, { "hash": "80a598c2820e332e26f758206eaa71133b6b84c1", "msg": "Fixed assert_approx_equal(0,0) failure bug.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2005-10-27T08:52:21+00:00", "author_timezone": 0, "committer_date": "2005-10-27T08:52:21+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "a74ef76e2f32e6de16fea37668daed0edb376fc6" ], "project_name": "repo_copy", "project_path": "/tmp/tmpn4cqam_6/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": "scipy/test/testing.py", "new_path": "scipy/test/testing.py", "filename": "testing.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -659,7 +659,7 @@ def assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):\n msg += err_msg\n actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n- scale = pow(10,math.floor(math.log10(0.5*(abs(desired)+abs(actual)))))\n+ scale = float(pow(10,math.floor(math.log10(0.5*(abs(desired)+abs(actual))))))\n try:\n sc_desired = desired/scale\n except ZeroDivisionError:\n", "added_lines": 1, "deleted_lines": 1, "source_code": "\"\"\"\nUnit-testing\n------------\n\n ScipyTest -- Scipy tests site manager\n ScipyTestCase -- unittest.TestCase with measure method\n IgnoreException -- raise when checking disabled feature ('ignoring' is displayed)\n set_package_path -- prepend package build directory to path\n set_local_path -- prepend local directory (to tests files) to path\n restore_path -- restore path after set_package_path\n\nTiming tools\n------------\n\n jiffies -- return 1/100ths of a second that the current process has used\n memusage -- virtual memory size in bytes of the running python [linux]\n\nUtility functions\n-----------------\n\n assert_equal -- assert equality\n assert_almost_equal -- assert equality with decimal tolerance\n assert_approx_equal -- assert equality with significant digits tolerance\n assert_array_equal -- assert arrays equality\n assert_array_almost_equal -- assert arrays equality with decimal tolerance\n assert_array_less -- assert arrays less-ordering\n rand -- array of random numbers from given shape\n\n\"\"\"\n\n__all__ = []\n\nimport os,sys,time,glob,string,traceback,unittest\nimport types\nimport imp\n\n#\n# Imports from scipy.base must be done at the end of this file.\n#\n\nDEBUG = 0\n\n__all__.append('set_package_path')\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 from scipy.distutils.misc_util import get_frame\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\n__all__.append('set_local_path')\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 from scipy.distutils.misc_util import get_frame\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\n__all__.append('restore_path')\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n\n__all__.extend(['jiffies','memusage'])\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\n\n def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())):\n \"\"\" Return virtual memory size in bytes of the running python.\n \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[22])\n except:\n return\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (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 = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>> ScipyTest().test(level=1,verbosity=2)\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 ScipyTestCase 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='__main__'):\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 print test_file\n print ' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module))\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 print ' !! FAILURE importing tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\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 print ' !! FAILURE building tests for ', mstr(test_module)\n print ' ',\n output_exception()\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 print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Scipy 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 suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None \\\n or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\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 runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n return runner\n\n def run(self):\n \"\"\" Run Scipy 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 print '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\n#------------\n \ndef remove_ignored_patterns(files,pattern):\n from fnmatch import fnmatch\n good_files = []\n for file in files:\n if not fnmatch(file,pattern):\n good_files.append(file)\n return good_files\n\ndef remove_ignored_files(original,ignored_files,cur_dir):\n \"\"\" This is actually expanded to do pattern matching.\n\n \"\"\"\n if not ignored_files: ignored_files = []\n ignored_modules = map(lambda x: x+'.py',ignored_files)\n ignored_packages = ignored_files[:]\n # always ignore setup.py and __init__.py files\n ignored_files = ['setup.py','setup_*.py','__init__.py']\n ignored_files += ignored_modules + ignored_packages\n ignored_files = map(lambda x,cur_dir=cur_dir: os.path.join(cur_dir,x),\n ignored_files)\n #print 'ignored:', ignored_files\n #good_files = filter(lambda x,ignored = ignored_files: x not in ignored,\n # original)\n good_files = original\n for pattern in ignored_files:\n good_files = remove_ignored_patterns(good_files,pattern)\n\n return good_files\n\n__all__.append('harvest_modules')\ndef harvest_modules(package,ignore=None):\n \"\"\"* Retreive a list of all modules that live within a package.\n\n Only retreive files that are immediate children of the\n package -- do not recurse through child packages or\n directories. The returned list contains actual modules, not\n just their names.\n *\"\"\"\n d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\n common_dir = os.path.join(d,'*.py')\n py_files = glob.glob(common_dir)\n #py_files.remove(os.path.join(d,'__init__.py'))\n #py_files.remove(os.path.join(d,'setup.py'))\n\n py_files = remove_ignored_files(py_files,ignore,d)\n #print 'py_files:', py_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n\n all_modules = []\n for file in py_files:\n d,f = os.path.split(file)\n base,ext = os.path.splitext(f)\n mod = prefix + '.' + base\n #print 'module: import ' + mod\n try:\n exec ('import ' + mod)\n all_modules.append(eval(mod))\n except:\n print 'FAILURE to import ' + mod\n output_exception()\n\n return all_modules\n\n__all__.append('harvest_packages')\ndef harvest_packages(package,ignore = None):\n \"\"\" Retreive a list of all sub-packages that live within a package.\n\n Only retreive packages that are immediate children of this\n package -- do not recurse through child packages or\n directories. The returned list contains actual package objects, not\n just their names.\n \"\"\"\n join = os.path.join\n\n d,f = os.path.split(package.__file__)\n\n common_dir = os.path.abspath(d)\n all_files = os.listdir(d)\n\n all_files = remove_ignored_files(all_files,ignore,'')\n #print 'all_files:', all_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n all_packages = []\n for directory in all_files:\n path = join(common_dir,directory)\n if os.path.isdir(path) and \\\n os.path.exists(join(path,'__init__.py')):\n sub_package = prefix + '.' + directory\n #print 'sub-package import ' + sub_package\n try:\n exec ('import ' + sub_package)\n all_packages.append(eval(sub_package))\n except:\n print 'FAILURE to import ' + sub_package\n output_exception()\n return all_packages\n\n__all__.append('harvest_modules_and_packages')\ndef harvest_modules_and_packages(package,ignore=None):\n \"\"\" Retreive list of all packages and modules that live within a package.\n\n See harvest_packages() and harvest_modules()\n \"\"\"\n all = harvest_modules(package,ignore) + harvest_packages(package,ignore)\n return all\n\n__all__.append('harvest_test_suites')\ndef harvest_test_suites(package,ignore = None,level=10):\n \"\"\"\n package -- the module to test. This is an actual module object\n (not a string)\n ignore -- a list of module names to omit from the tests\n level -- a value between 1 and 10. 1 will run the minimum number\n of tests. This is a fast \"smoke test\". Tests that take\n longer to run should have higher numbers ranging up to 10.\n \"\"\"\n suites=[]\n test_modules = harvest_modules_and_packages(package,ignore)\n #for i in test_modules:\n # print i.__name__\n for module in test_modules:\n if hasattr(module,'test_suite'):\n try:\n suite = module.test_suite(level=level)\n if suite:\n suites.append(suite)\n else:\n print \" !! FAILURE without error - shouldn't happen\",\n print module.__name__\n except:\n print ' !! FAILURE building test for ', module.__name__\n print ' ',\n output_exception()\n else:\n try:\n print 'No test suite found for ', module.__name__\n except AttributeError:\n # __version__.py getting replaced by a string throws a kink\n # in checking for modules, so we think is a module has\n # actually been overwritten\n print 'No test suite found for ', str(module)\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\n__all__.append('module_test')\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);%s.test(%d)' % \\\n ((test_module,)*3 + (level,))\n\n # This would be better cause it forces a reload of the orginal\n # module. It doesn't behave with packages however.\n #test_string = 'reload(%s);import %s;reload(%s);%s.test(%d)' % \\\n # ((mod_name,) + (test_module,)*3)\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n\n__all__.append('module_test_suite')\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);suite = %s.test_suite(%d)' % \\\n ((test_module,)*3+(level,))\n #print test_string\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n return suite\n #except:\n # print ' !! FAILURE loading test suite from', test_module, ':'\n # print ' ',\n # output_exception()\n\n\n# Utility function to facilitate testing.\n\n__all__.append('assert_equal')\ndef assert_equal(actual,desired,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n if isinstance(actual, ArrayType) or isinstance(desired, ArrayType):\n return assert_array_equal(actual, desired, err_msg)\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert desired == actual, msg\n\n__all__.append('assert_almost_equal')\ndef assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n if isinstance(actual, ArrayType) or isinstance(desired, ArrayType):\n return assert_array_almost_equal(actual, desired, decimal, err_msg)\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert round(abs(desired - actual),decimal) == 0, msg\n\n__all__.append('assert_approx_equal')\ndef assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n Approximately equal is defined as the number of significant digits\n correct\n \"\"\"\n msg = '\\nItems are not equal to %d significant digits:\\n' % significant\n msg += err_msg\n actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n scale = float(pow(10,math.floor(math.log10(0.5*(abs(desired)+abs(actual))))))\n try:\n sc_desired = desired/scale\n except ZeroDivisionError:\n sc_desired = 0.0\n try:\n sc_actual = actual/scale\n except ZeroDivisionError:\n sc_actual = 0.0\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n\n\n__all__.append('assert_array_equal')\ndef assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not equal'\n try:\n assert 0 in [len(shape(x)),len(shape(y))] \\\n or (len(shape(x))==len(shape(y)) and \\\n alltrue(equal(shape(x),shape(y)))),\\\n msg + ' (shapes %s, %s mismatch):\\n\\t' \\\n % (shape(x),shape(y)) + err_msg\n reduced = ravel(equal(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n raise ValueError, msg\n\n__all__.append('assert_array_almost_equal')\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n x = asarray(x)\n y = asarray(y)\n msg = '\\nArrays are not almost equal'\n try:\n cond = alltrue(equal(shape(x),shape(y)))\n if not cond:\n msg = msg + ' (shapes mismatch):\\n\\t'\\\n 'Shape of array 1: %s\\n\\tShape of array 2: %s' % (shape(x),shape(y))\n assert cond, msg + '\\n\\t' + err_msg\n reduced = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print sys.exc_value\n print shape(x),shape(y)\n print x, y\n raise ValueError, 'arrays are not almost equal'\n\n__all__.append('assert_array_less')\ndef assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not less-ordered'\n\n__all__.append('rand')\ndef rand(*args):\n \"\"\"Returns an array of random numbers with the given shape.\n \n This only uses the standard library, so it is useful for testing purposes. \n \"\"\"\n import random\n results = zeros(args,Float64)\n f = results.flat\n for i in range(len(f)):\n f[i] = random.random()\n return results\n\ndef output_exception():\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 \"%s:%d: %s: %s (in %s)\" %\\\n (filename, lineno, type.__name__, str(value), function)\n finally:\n type = value = tb = None # clean up\n\nfrom scipy.base import alltrue, equal, shape, ravel, around, zeros,\\\n Float64, asarray, less_equal, array2string, less, ArrayType\n\ntry:\n from scipy.base import math\nexcept ImportError,msg:\n print msg\n import math\n", "source_code_before": "\"\"\"\nUnit-testing\n------------\n\n ScipyTest -- Scipy tests site manager\n ScipyTestCase -- unittest.TestCase with measure method\n IgnoreException -- raise when checking disabled feature ('ignoring' is displayed)\n set_package_path -- prepend package build directory to path\n set_local_path -- prepend local directory (to tests files) to path\n restore_path -- restore path after set_package_path\n\nTiming tools\n------------\n\n jiffies -- return 1/100ths of a second that the current process has used\n memusage -- virtual memory size in bytes of the running python [linux]\n\nUtility functions\n-----------------\n\n assert_equal -- assert equality\n assert_almost_equal -- assert equality with decimal tolerance\n assert_approx_equal -- assert equality with significant digits tolerance\n assert_array_equal -- assert arrays equality\n assert_array_almost_equal -- assert arrays equality with decimal tolerance\n assert_array_less -- assert arrays less-ordering\n rand -- array of random numbers from given shape\n\n\"\"\"\n\n__all__ = []\n\nimport os,sys,time,glob,string,traceback,unittest\nimport types\nimport imp\n\n#\n# Imports from scipy.base must be done at the end of this file.\n#\n\nDEBUG = 0\n\n__all__.append('set_package_path')\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 from scipy.distutils.misc_util import get_frame\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\n__all__.append('set_local_path')\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 from scipy.distutils.misc_util import get_frame\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\n__all__.append('restore_path')\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n\n__all__.extend(['jiffies','memusage'])\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\n\n def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())):\n \"\"\" Return virtual memory size in bytes of the running python.\n \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[22])\n except:\n return\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (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 = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>> ScipyTest().test(level=1,verbosity=2)\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 ScipyTestCase 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='__main__'):\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 print test_file\n print ' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module))\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 print ' !! FAILURE importing tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\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 print ' !! FAILURE building tests for ', mstr(test_module)\n print ' ',\n output_exception()\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 print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Scipy 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 suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None \\\n or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\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 runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n return runner\n\n def run(self):\n \"\"\" Run Scipy 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 print '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\n#------------\n \ndef remove_ignored_patterns(files,pattern):\n from fnmatch import fnmatch\n good_files = []\n for file in files:\n if not fnmatch(file,pattern):\n good_files.append(file)\n return good_files\n\ndef remove_ignored_files(original,ignored_files,cur_dir):\n \"\"\" This is actually expanded to do pattern matching.\n\n \"\"\"\n if not ignored_files: ignored_files = []\n ignored_modules = map(lambda x: x+'.py',ignored_files)\n ignored_packages = ignored_files[:]\n # always ignore setup.py and __init__.py files\n ignored_files = ['setup.py','setup_*.py','__init__.py']\n ignored_files += ignored_modules + ignored_packages\n ignored_files = map(lambda x,cur_dir=cur_dir: os.path.join(cur_dir,x),\n ignored_files)\n #print 'ignored:', ignored_files\n #good_files = filter(lambda x,ignored = ignored_files: x not in ignored,\n # original)\n good_files = original\n for pattern in ignored_files:\n good_files = remove_ignored_patterns(good_files,pattern)\n\n return good_files\n\n__all__.append('harvest_modules')\ndef harvest_modules(package,ignore=None):\n \"\"\"* Retreive a list of all modules that live within a package.\n\n Only retreive files that are immediate children of the\n package -- do not recurse through child packages or\n directories. The returned list contains actual modules, not\n just their names.\n *\"\"\"\n d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\n common_dir = os.path.join(d,'*.py')\n py_files = glob.glob(common_dir)\n #py_files.remove(os.path.join(d,'__init__.py'))\n #py_files.remove(os.path.join(d,'setup.py'))\n\n py_files = remove_ignored_files(py_files,ignore,d)\n #print 'py_files:', py_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n\n all_modules = []\n for file in py_files:\n d,f = os.path.split(file)\n base,ext = os.path.splitext(f)\n mod = prefix + '.' + base\n #print 'module: import ' + mod\n try:\n exec ('import ' + mod)\n all_modules.append(eval(mod))\n except:\n print 'FAILURE to import ' + mod\n output_exception()\n\n return all_modules\n\n__all__.append('harvest_packages')\ndef harvest_packages(package,ignore = None):\n \"\"\" Retreive a list of all sub-packages that live within a package.\n\n Only retreive packages that are immediate children of this\n package -- do not recurse through child packages or\n directories. The returned list contains actual package objects, not\n just their names.\n \"\"\"\n join = os.path.join\n\n d,f = os.path.split(package.__file__)\n\n common_dir = os.path.abspath(d)\n all_files = os.listdir(d)\n\n all_files = remove_ignored_files(all_files,ignore,'')\n #print 'all_files:', all_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n all_packages = []\n for directory in all_files:\n path = join(common_dir,directory)\n if os.path.isdir(path) and \\\n os.path.exists(join(path,'__init__.py')):\n sub_package = prefix + '.' + directory\n #print 'sub-package import ' + sub_package\n try:\n exec ('import ' + sub_package)\n all_packages.append(eval(sub_package))\n except:\n print 'FAILURE to import ' + sub_package\n output_exception()\n return all_packages\n\n__all__.append('harvest_modules_and_packages')\ndef harvest_modules_and_packages(package,ignore=None):\n \"\"\" Retreive list of all packages and modules that live within a package.\n\n See harvest_packages() and harvest_modules()\n \"\"\"\n all = harvest_modules(package,ignore) + harvest_packages(package,ignore)\n return all\n\n__all__.append('harvest_test_suites')\ndef harvest_test_suites(package,ignore = None,level=10):\n \"\"\"\n package -- the module to test. This is an actual module object\n (not a string)\n ignore -- a list of module names to omit from the tests\n level -- a value between 1 and 10. 1 will run the minimum number\n of tests. This is a fast \"smoke test\". Tests that take\n longer to run should have higher numbers ranging up to 10.\n \"\"\"\n suites=[]\n test_modules = harvest_modules_and_packages(package,ignore)\n #for i in test_modules:\n # print i.__name__\n for module in test_modules:\n if hasattr(module,'test_suite'):\n try:\n suite = module.test_suite(level=level)\n if suite:\n suites.append(suite)\n else:\n print \" !! FAILURE without error - shouldn't happen\",\n print module.__name__\n except:\n print ' !! FAILURE building test for ', module.__name__\n print ' ',\n output_exception()\n else:\n try:\n print 'No test suite found for ', module.__name__\n except AttributeError:\n # __version__.py getting replaced by a string throws a kink\n # in checking for modules, so we think is a module has\n # actually been overwritten\n print 'No test suite found for ', str(module)\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\n__all__.append('module_test')\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);%s.test(%d)' % \\\n ((test_module,)*3 + (level,))\n\n # This would be better cause it forces a reload of the orginal\n # module. It doesn't behave with packages however.\n #test_string = 'reload(%s);import %s;reload(%s);%s.test(%d)' % \\\n # ((mod_name,) + (test_module,)*3)\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n\n__all__.append('module_test_suite')\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);suite = %s.test_suite(%d)' % \\\n ((test_module,)*3+(level,))\n #print test_string\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n return suite\n #except:\n # print ' !! FAILURE loading test suite from', test_module, ':'\n # print ' ',\n # output_exception()\n\n\n# Utility function to facilitate testing.\n\n__all__.append('assert_equal')\ndef assert_equal(actual,desired,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n if isinstance(actual, ArrayType) or isinstance(desired, ArrayType):\n return assert_array_equal(actual, desired, err_msg)\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert desired == actual, msg\n\n__all__.append('assert_almost_equal')\ndef assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n if isinstance(actual, ArrayType) or isinstance(desired, ArrayType):\n return assert_array_almost_equal(actual, desired, decimal, err_msg)\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert round(abs(desired - actual),decimal) == 0, msg\n\n__all__.append('assert_approx_equal')\ndef assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n Approximately equal is defined as the number of significant digits\n correct\n \"\"\"\n msg = '\\nItems are not equal to %d significant digits:\\n' % significant\n msg += err_msg\n actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n scale = pow(10,math.floor(math.log10(0.5*(abs(desired)+abs(actual)))))\n try:\n sc_desired = desired/scale\n except ZeroDivisionError:\n sc_desired = 0.0\n try:\n sc_actual = actual/scale\n except ZeroDivisionError:\n sc_actual = 0.0\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n\n\n__all__.append('assert_array_equal')\ndef assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not equal'\n try:\n assert 0 in [len(shape(x)),len(shape(y))] \\\n or (len(shape(x))==len(shape(y)) and \\\n alltrue(equal(shape(x),shape(y)))),\\\n msg + ' (shapes %s, %s mismatch):\\n\\t' \\\n % (shape(x),shape(y)) + err_msg\n reduced = ravel(equal(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n raise ValueError, msg\n\n__all__.append('assert_array_almost_equal')\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n x = asarray(x)\n y = asarray(y)\n msg = '\\nArrays are not almost equal'\n try:\n cond = alltrue(equal(shape(x),shape(y)))\n if not cond:\n msg = msg + ' (shapes mismatch):\\n\\t'\\\n 'Shape of array 1: %s\\n\\tShape of array 2: %s' % (shape(x),shape(y))\n assert cond, msg + '\\n\\t' + err_msg\n reduced = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print sys.exc_value\n print shape(x),shape(y)\n print x, y\n raise ValueError, 'arrays are not almost equal'\n\n__all__.append('assert_array_less')\ndef assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not less-ordered'\n\n__all__.append('rand')\ndef rand(*args):\n \"\"\"Returns an array of random numbers with the given shape.\n \n This only uses the standard library, so it is useful for testing purposes. \n \"\"\"\n import random\n results = zeros(args,Float64)\n f = results.flat\n for i in range(len(f)):\n f[i] = random.random()\n return results\n\ndef output_exception():\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 \"%s:%d: %s: %s (in %s)\" %\\\n (filename, lineno, type.__name__, str(value), function)\n finally:\n type = value = tb = None # clean up\n\nfrom scipy.base import alltrue, equal, shape, ravel, around, zeros,\\\n Float64, asarray, less_equal, array2string, less, ArrayType\n\ntry:\n from scipy.base import math\nexcept ImportError,msg:\n print msg\n import math\n", "methods": [ { "name": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 148, "parameters": [ "level" ], "start_line": 44, "end_line": 75, "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": "testing.py", "nloc": 11, "complexity": 3, "token_count": 99, "parameters": [ "reldir", "level" ], "start_line": 78, "end_line": 94, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [], "start_line": 97, "end_line": 100, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "jiffies", "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "_proc_pid_stat" ], "start_line": 104, "end_line": 105, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 10, "complexity": 2, "token_count": 54, "parameters": [ "_proc_pid_stat" ], "start_line": 116, "end_line": 125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "jiffies", "long_name": "jiffies( _load_time = time . time ( )", "filename": "testing.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "_load_time" ], "start_line": 130, "end_line": 133, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [], "start_line": 135, "end_line": 137, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "measure", "long_name": "measure( self , code_str , times = 1 )", "filename": "testing.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "code_str", "times" ], "start_line": 142, "end_line": 157, "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": "testing.py", "nloc": 24, "complexity": 6, "token_count": 224, "parameters": [ "self", "result" ], "start_line": 159, "end_line": 183, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , stream )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "self", "stream" ], "start_line": 186, "end_line": 188, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "write", "long_name": "write( self , message )", "filename": "testing.py", "nloc": 6, "complexity": 3, "token_count": 47, "parameters": [ "self", "message" ], "start_line": 189, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "writeln", "long_name": "writeln( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "message" ], "start_line": 195, "end_line": 196, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_get_all_method_names", "long_name": "_get_all_method_names( cls )", "filename": "testing.py", "nloc": 8, "complexity": 5, "token_count": 56, "parameters": [ "cls" ], "start_line": 204, "end_line": 211, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , package = '__main__' )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "package" ], "start_line": 235, "end_line": 236, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_module_str", "long_name": "_module_str( self , module )", "filename": "testing.py", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "self", "module" ], "start_line": 238, "end_line": 242, "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": "testing.py", "nloc": 22, "complexity": 11, "token_count": 142, "parameters": [ "self", "clsobj", "level" ], "start_line": 244, "end_line": 265, "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": "testing.py", "nloc": 48, "complexity": 15, "token_count": 437, "parameters": [ "self", "module", "level", "verbosity" ], "start_line": 267, "end_line": 320, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 24, "complexity": 9, "token_count": 168, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 322, "end_line": 346, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 18, "complexity": 6, "token_count": 162, "parameters": [ "self", "level", "verbosity" ], "start_line": 348, "end_line": 371, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "testing.py", "nloc": 20, "complexity": 2, "token_count": 104, "parameters": [ "self" ], "start_line": 373, "end_line": 395, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "testing.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 399, "end_line": 405, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "remove_ignored_files", "long_name": "remove_ignored_files( original , ignored_files , cur_dir )", "filename": "testing.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 407, "end_line": 426, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "harvest_modules", "long_name": "harvest_modules( package , ignore = None )", "filename": "testing.py", "nloc": 21, "complexity": 4, "token_count": 134, "parameters": [ "package", "ignore" ], "start_line": 429, "end_line": 465, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 148, "parameters": [ "package", "ignore" ], "start_line": 468, "end_line": 502, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 505, "end_line": 511, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "harvest_test_suites", "long_name": "harvest_test_suites( package , ignore = None , level = 10 )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 113, "parameters": [ "package", "ignore", "level" ], "start_line": 514, "end_line": 549, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 10, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 552, "end_line": 579, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 12, "complexity": 1, "token_count": 103, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 582, "end_line": 604, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_equal", "long_name": "assert_equal( actual , desired , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 14, "complexity": 7, "token_count": 116, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 614, "end_line": 630, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "assert_almost_equal", "long_name": "assert_almost_equal( actual , desired , decimal = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 14, "complexity": 7, "token_count": 132, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 633, "end_line": 649, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "assert_approx_equal", "long_name": "assert_approx_equal( actual , desired , significant = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 23, "complexity": 7, "token_count": 194, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 652, "end_line": 680, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 22, "complexity": 7, "token_count": 232, "parameters": [ "x", "y", "err_msg" ], "start_line": 684, "end_line": 705, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 26, "complexity": 6, "token_count": 251, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 708, "end_line": 733, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 736, "end_line": 755, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "rand", "long_name": "rand( * args )", "filename": "testing.py", "nloc": 7, "complexity": 2, "token_count": 45, "parameters": [ "args" ], "start_line": 758, "end_line": 768, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 770, "end_line": 780, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "methods_before": [ { "name": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 148, "parameters": [ "level" ], "start_line": 44, "end_line": 75, "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": "testing.py", "nloc": 11, "complexity": 3, "token_count": 99, "parameters": [ "reldir", "level" ], "start_line": 78, "end_line": 94, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [], "start_line": 97, "end_line": 100, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "jiffies", "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "_proc_pid_stat" ], "start_line": 104, "end_line": 105, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 10, "complexity": 2, "token_count": 54, "parameters": [ "_proc_pid_stat" ], "start_line": 116, "end_line": 125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "jiffies", "long_name": "jiffies( _load_time = time . time ( )", "filename": "testing.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "_load_time" ], "start_line": 130, "end_line": 133, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [], "start_line": 135, "end_line": 137, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "measure", "long_name": "measure( self , code_str , times = 1 )", "filename": "testing.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "code_str", "times" ], "start_line": 142, "end_line": 157, "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": "testing.py", "nloc": 24, "complexity": 6, "token_count": 224, "parameters": [ "self", "result" ], "start_line": 159, "end_line": 183, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , stream )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "self", "stream" ], "start_line": 186, "end_line": 188, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "write", "long_name": "write( self , message )", "filename": "testing.py", "nloc": 6, "complexity": 3, "token_count": 47, "parameters": [ "self", "message" ], "start_line": 189, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "writeln", "long_name": "writeln( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "message" ], "start_line": 195, "end_line": 196, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_get_all_method_names", "long_name": "_get_all_method_names( cls )", "filename": "testing.py", "nloc": 8, "complexity": 5, "token_count": 56, "parameters": [ "cls" ], "start_line": 204, "end_line": 211, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , package = '__main__' )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "package" ], "start_line": 235, "end_line": 236, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_module_str", "long_name": "_module_str( self , module )", "filename": "testing.py", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "self", "module" ], "start_line": 238, "end_line": 242, "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": "testing.py", "nloc": 22, "complexity": 11, "token_count": 142, "parameters": [ "self", "clsobj", "level" ], "start_line": 244, "end_line": 265, "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": "testing.py", "nloc": 48, "complexity": 15, "token_count": 437, "parameters": [ "self", "module", "level", "verbosity" ], "start_line": 267, "end_line": 320, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 24, "complexity": 9, "token_count": 168, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 322, "end_line": 346, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 18, "complexity": 6, "token_count": 162, "parameters": [ "self", "level", "verbosity" ], "start_line": 348, "end_line": 371, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "testing.py", "nloc": 20, "complexity": 2, "token_count": 104, "parameters": [ "self" ], "start_line": 373, "end_line": 395, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "testing.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 399, "end_line": 405, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "remove_ignored_files", "long_name": "remove_ignored_files( original , ignored_files , cur_dir )", "filename": "testing.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 407, "end_line": 426, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "harvest_modules", "long_name": "harvest_modules( package , ignore = None )", "filename": "testing.py", "nloc": 21, "complexity": 4, "token_count": 134, "parameters": [ "package", "ignore" ], "start_line": 429, "end_line": 465, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 148, "parameters": [ "package", "ignore" ], "start_line": 468, "end_line": 502, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 505, "end_line": 511, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "harvest_test_suites", "long_name": "harvest_test_suites( package , ignore = None , level = 10 )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 113, "parameters": [ "package", "ignore", "level" ], "start_line": 514, "end_line": 549, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 10, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 552, "end_line": 579, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 12, "complexity": 1, "token_count": 103, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 582, "end_line": 604, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_equal", "long_name": "assert_equal( actual , desired , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 14, "complexity": 7, "token_count": 116, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 614, "end_line": 630, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "assert_almost_equal", "long_name": "assert_almost_equal( actual , desired , decimal = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 14, "complexity": 7, "token_count": 132, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 633, "end_line": 649, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "assert_approx_equal", "long_name": "assert_approx_equal( actual , desired , significant = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 23, "complexity": 7, "token_count": 191, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 652, "end_line": 680, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 22, "complexity": 7, "token_count": 232, "parameters": [ "x", "y", "err_msg" ], "start_line": 684, "end_line": 705, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 26, "complexity": 6, "token_count": 251, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 708, "end_line": 733, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 736, "end_line": 755, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "rand", "long_name": "rand( * args )", "filename": "testing.py", "nloc": 7, "complexity": 2, "token_count": 45, "parameters": [ "args" ], "start_line": 758, "end_line": 768, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 770, "end_line": 780, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "assert_approx_equal", "long_name": "assert_approx_equal( actual , desired , significant = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 23, "complexity": 7, "token_count": 194, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 652, "end_line": 680, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 } ], "nloc": 586, "complexity": 146, "token_count": 4193, "diff_parsed": { "added": [ " scale = float(pow(10,math.floor(math.log10(0.5*(abs(desired)+abs(actual))))))" ], "deleted": [ " scale = pow(10,math.floor(math.log10(0.5*(abs(desired)+abs(actual)))))" ] } } ] }, { "hash": "a25e5da35747e2a4cacc326f2709b0fb278c1d29", "msg": "Made ScalarType tuple so that it could be 2nd argument to isinstance.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2005-10-27T09:08:19+00:00", "author_timezone": 0, "committer_date": "2005-10-27T09:08:19+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "80a598c2820e332e26f758206eaa71133b6b84c1" ], "project_name": "repo_copy", "project_path": "/tmp/tmpn4cqam_6/repo_copy", "deletions": 0, "insertions": 1, "lines": 1, "files": 1, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "scipy/base/numerictypes.py", "new_path": "scipy/base/numerictypes.py", "filename": "numerictypes.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -337,6 +337,7 @@ def __getitem__(self, obj):\n _types.ComplexType, _types.LongType, _types.BooleanType,\n _types.StringType, _types.UnicodeType, _types.BufferType]\n ScalarType.extend(_dtype2char_dict.keys())\n+ScalarType = tuple(ScalarType)\n for key in _dtype2char_dict.keys():\n cast[key] = lambda x, k=key : array(x,copy=False).astype(k)\n \n", "added_lines": 1, "deleted_lines": 0, "source_code": "# Borrowed and adapted from numarray\n\n\"\"\"numerictypes: Define the numeric type objects\n\nThis module is designed so 'from numeric3types import *' is safe.\nExported symbols include:\n\n Dictionary with all registered number types (including aliases):\n typeDict\n\n Type objects (not all will be available, depends on platform):\n see variable arraytypes for which ones you have\n\n Bit-width names\n \n int8 int16 int32 int64 int128\n uint8 uint16 uint32 uint64 uint128\n float16 float32 float64 float96 float128 float256\n complex32 complex64 complex128 complex192 complex256 complex512\n\n c-based names \n\n bool_\n\n object_\n\n void, str_, unicode_\n\n byte, ubyte,\n short, ushort\n intc, uintc,\n intp, uintp,\n int_, uint,\n longlong, ulonglong,\n\n single, csingle,\n float_, complex_,\n longfloat, clongfloat,\n\n As part of the type-hierarchy: xx -- is bit-width\n \n generic\n bool_\n numeric\n integer\n signedinteger (intxx)\n byte\n short\n intc\n intp int0\n int_\n longlong\n unsignedinteger (uintxx)\n ubyte\n ushort\n uintc\n uintp uint0\n uint_\n ulonglong\n floating (floatxx)\n single \n float_ (double)\n longfloat\n complexfloating (complexxx)\n csingle \n complex_ (cfloat, cdouble)\n clongfloat\n \n flexible\n character\n str_ (string)\n unicode_ \n void\n \n object_\n\n$Id: numerictypes.py,v 1.17 2005/09/09 22:20:06 teoliphant Exp $\n\"\"\"\n\nimport multiarray\ntypeinfo = multiarray.typeinfo\nndarray = multiarray.ndarray\narray = multiarray.array\n_I = typeinfo\n\npybool = bool\npyint = int\npyfloat = float\npylong = long\npycomplex = complex\npyobject = object\npyunicode = unicode\n\nimport types as _types\n\ntypeDict = {} # Contains all leaf-node numeric types with aliases\n\n\ndef _evalname(name):\n k = 0\n for ch in name:\n if ch in '0123456789':\n break\n k+=1\n try:\n bits = pyint(name[k:])\n except ValueError:\n bits = 0\n base = name[:k]\n return base, bits\n\ndef bitname(obj):\n \"\"\"Return a bit-width name for a given type object\"\"\"\n name = obj.__name__[:-8]\n base = ''\n char = ''\n try:\n info = _I[name.upper()]\n assert(info[-1] == obj) # sanity check\n bits = info[2]\n \n except KeyError: # bit-width name\n base, bits = _evalname(name)\n char = base[0]\n\n if name=='bool':\n char = 'b'\n elif name=='string':\n char = 'S'\n base = 'string'\n elif name=='unicode':\n char = 'U'\n base = 'unicode'\n elif name=='void':\n char = 'V'\n base = 'void'\n elif name=='object':\n char = 'O'\n base = 'object'\n bits = 0\n\n bytes = bits / 8 \n\n if char != '' and bytes != 0:\n char = \"%s%d\" % (char, bytes)\n\n return base, bits, char \n\nrevdict = {}\n_tocheck = _I.keys()\n_thisdict = globals() # this will insert into module name space\n\nfor a in _tocheck:\n name = a.lower()\n if isinstance(_I[a],type(())):\n typeobj = _I[a][-1]\n # define C-name and insert typenum and typechar references also\n _thisdict[name] = typeobj\n typeDict[name] = typeobj\n typeDict[_I[a][0]] = typeobj\n typeDict[_I[a][1]] = typeobj\n\n # insert bit-width version for this class (if relevant)\n base, bit, char = bitname(typeobj)\n revdict[typeobj] = (_I[a][:-1], (base, bit, char), a)\n if base != '':\n _thisdict[\"%s%d\" % (base, bit)] = typeobj\n typeDict[\"%s%d\" % (base, bit)] = typeobj\n if char != '':\n typeDict[char] = typeobj\n \n else: # generic class\n _thisdict[name] = _I[a]\n\n#\n# Rework the Python names (so that float and complex and int are consistent\n# with Python usage)\n#\ncomplex_ = cdouble\nint0 = intp\nuint0 = uintp\nsingle = float\ncsingle = cfloat\nfloat_ = double\nintc = int\nuintc = uint\nint_ = long\nuint = ulong\ncfloat = cdouble\nlongfloat = longdouble\nclongfloat = clongdouble\n\nbool_ = bool\nunicode_ = unicode\nstr_ = string\nobject_ = object\n\nobject = pyobject\nunicode = pyunicode\nint = pyint\nlong = pylong\nfloat = pyfloat\ncomplex = pycomplex\nbool = pybool\n\ndel ulong, pyobject, pyunicode, pyint, pylong, pyfloat, pycomplex, pybool\n\ndel _thisdict, _tocheck, a, name, typeobj\ndel base, bit, char\n\n\n# Now, construct dictionary to lookup character codes from types\n\n_dtype2char_dict = {}\nfor name in typeinfo.keys():\n tup = typeinfo[name]\n if isinstance(tup,type(())):\n _dtype2char_dict[tup[-1]] = tup[0]\n\narraytypes = {'int': [],\n 'uint':[],\n 'float':[],\n 'complex':[],\n 'others':[bool_,object_,str_,unicode_,void]}\n\n_ibytes = [1,2,4,8,16,32,64]\n_fbytes = [2,4,8,10,12,16,32,64]\n \nfor bytes in _ibytes:\n bits = 8*bytes\n try:\n arraytypes['int'].append(eval(\"int%d\" % bits))\n except NameError:\n pass\n try:\n arraytypes['uint'].append(eval(\"uint%d\" % bits))\n except NameError:\n pass\n\nfor bytes in _fbytes:\n bits = 8*bytes\n try:\n arraytypes['float'].append(eval(\"float%d\" % bits))\n except NameError:\n pass\n try:\n arraytypes['complex'].append(eval(\"complex%d\" % (2*bits,)))\n except NameError:\n pass\n\ndel bytes, bits\n\ngenericTypeRank = ['bool','int8','uint8','int16','uint16',\n 'int32', 'uint32', 'int64', 'uint64', 'int128',\n 'uint128','float16',\n 'float32','float64', 'float80', 'float96', 'float128',\n 'float256'\n 'complex32', 'complex64', 'complex128', 'complex160',\n 'complex192', 'complex256', 'complex512', 'object']\n\ndef maximum_dtype(t):\n \"\"\"returns the type of highest precision of the same general kind as 't'\"\"\"\n g = obj2dtype(t)\n if g is None:\n return t\n t = g\n name = t.__name__[:-8]\n base, bits = _evalname(name)\n if bits == 0:\n return t\n else:\n return arraytypes[base][-1]\n\ndef _python_type(t):\n \"\"\"returns the type corresponding to a certain Python type\"\"\"\n if not isinstance(t, _types.TypeType):\n t = type(t)\n if t == _types.IntType:\n return int_\n elif t == _types.FloatType:\n return float_\n elif t == _types.ComplexType:\n return complex_\n elif t == _types.BooleanType:\n return bool_\n elif t == _types.StringType:\n return str_\n elif t == _types.UnicodeType:\n return unicode_\n elif t == _types.BufferType:\n return void\n else:\n return object_\n\ndef isdtype(rep):\n \"\"\"Determines whether the given object represents\n a numeric array type.\"\"\"\n try:\n char = dtype2char(rep)\n return True\n except (KeyError, ValueError):\n return False\n \ndef obj2dtype(rep, default=None):\n try:\n if issubclass(rep, generic):\n return rep\n except TypeError:\n pass\n \n if isinstance(rep, type):\n return _python_type(rep)\n if isinstance(rep, ndarray):\n return rep.dtype \n res = typeDict.get(rep, default)\n return res\n\ndef dtype2char(dtype):\n dtype = obj2dtype(dtype)\n if dtype is None:\n raise ValueError, \"unrecognized type\"\n return _dtype2char_dict[dtype]\n\n\ndel _ibytes, _fbytes, multiarray\n\n# Create dictionary of casting functions that wrap sequences\n# indexed by type or type character\n\n# This dictionary allows look up based on any alias for a type\nclass _castdict(dict):\n def __getitem__(self, obj):\n return dict.__getitem__(self, obj2dtype(obj))\n\ncast = _castdict()\nScalarType = [_types.IntType, _types.FloatType,\n _types.ComplexType, _types.LongType, _types.BooleanType,\n _types.StringType, _types.UnicodeType, _types.BufferType]\nScalarType.extend(_dtype2char_dict.keys())\nScalarType = tuple(ScalarType)\nfor key in _dtype2char_dict.keys():\n cast[key] = lambda x, k=key : array(x,copy=False).astype(k)\n\ndel key\n\n\n\n\n", "source_code_before": "# Borrowed and adapted from numarray\n\n\"\"\"numerictypes: Define the numeric type objects\n\nThis module is designed so 'from numeric3types import *' is safe.\nExported symbols include:\n\n Dictionary with all registered number types (including aliases):\n typeDict\n\n Type objects (not all will be available, depends on platform):\n see variable arraytypes for which ones you have\n\n Bit-width names\n \n int8 int16 int32 int64 int128\n uint8 uint16 uint32 uint64 uint128\n float16 float32 float64 float96 float128 float256\n complex32 complex64 complex128 complex192 complex256 complex512\n\n c-based names \n\n bool_\n\n object_\n\n void, str_, unicode_\n\n byte, ubyte,\n short, ushort\n intc, uintc,\n intp, uintp,\n int_, uint,\n longlong, ulonglong,\n\n single, csingle,\n float_, complex_,\n longfloat, clongfloat,\n\n As part of the type-hierarchy: xx -- is bit-width\n \n generic\n bool_\n numeric\n integer\n signedinteger (intxx)\n byte\n short\n intc\n intp int0\n int_\n longlong\n unsignedinteger (uintxx)\n ubyte\n ushort\n uintc\n uintp uint0\n uint_\n ulonglong\n floating (floatxx)\n single \n float_ (double)\n longfloat\n complexfloating (complexxx)\n csingle \n complex_ (cfloat, cdouble)\n clongfloat\n \n flexible\n character\n str_ (string)\n unicode_ \n void\n \n object_\n\n$Id: numerictypes.py,v 1.17 2005/09/09 22:20:06 teoliphant Exp $\n\"\"\"\n\nimport multiarray\ntypeinfo = multiarray.typeinfo\nndarray = multiarray.ndarray\narray = multiarray.array\n_I = typeinfo\n\npybool = bool\npyint = int\npyfloat = float\npylong = long\npycomplex = complex\npyobject = object\npyunicode = unicode\n\nimport types as _types\n\ntypeDict = {} # Contains all leaf-node numeric types with aliases\n\n\ndef _evalname(name):\n k = 0\n for ch in name:\n if ch in '0123456789':\n break\n k+=1\n try:\n bits = pyint(name[k:])\n except ValueError:\n bits = 0\n base = name[:k]\n return base, bits\n\ndef bitname(obj):\n \"\"\"Return a bit-width name for a given type object\"\"\"\n name = obj.__name__[:-8]\n base = ''\n char = ''\n try:\n info = _I[name.upper()]\n assert(info[-1] == obj) # sanity check\n bits = info[2]\n \n except KeyError: # bit-width name\n base, bits = _evalname(name)\n char = base[0]\n\n if name=='bool':\n char = 'b'\n elif name=='string':\n char = 'S'\n base = 'string'\n elif name=='unicode':\n char = 'U'\n base = 'unicode'\n elif name=='void':\n char = 'V'\n base = 'void'\n elif name=='object':\n char = 'O'\n base = 'object'\n bits = 0\n\n bytes = bits / 8 \n\n if char != '' and bytes != 0:\n char = \"%s%d\" % (char, bytes)\n\n return base, bits, char \n\nrevdict = {}\n_tocheck = _I.keys()\n_thisdict = globals() # this will insert into module name space\n\nfor a in _tocheck:\n name = a.lower()\n if isinstance(_I[a],type(())):\n typeobj = _I[a][-1]\n # define C-name and insert typenum and typechar references also\n _thisdict[name] = typeobj\n typeDict[name] = typeobj\n typeDict[_I[a][0]] = typeobj\n typeDict[_I[a][1]] = typeobj\n\n # insert bit-width version for this class (if relevant)\n base, bit, char = bitname(typeobj)\n revdict[typeobj] = (_I[a][:-1], (base, bit, char), a)\n if base != '':\n _thisdict[\"%s%d\" % (base, bit)] = typeobj\n typeDict[\"%s%d\" % (base, bit)] = typeobj\n if char != '':\n typeDict[char] = typeobj\n \n else: # generic class\n _thisdict[name] = _I[a]\n\n#\n# Rework the Python names (so that float and complex and int are consistent\n# with Python usage)\n#\ncomplex_ = cdouble\nint0 = intp\nuint0 = uintp\nsingle = float\ncsingle = cfloat\nfloat_ = double\nintc = int\nuintc = uint\nint_ = long\nuint = ulong\ncfloat = cdouble\nlongfloat = longdouble\nclongfloat = clongdouble\n\nbool_ = bool\nunicode_ = unicode\nstr_ = string\nobject_ = object\n\nobject = pyobject\nunicode = pyunicode\nint = pyint\nlong = pylong\nfloat = pyfloat\ncomplex = pycomplex\nbool = pybool\n\ndel ulong, pyobject, pyunicode, pyint, pylong, pyfloat, pycomplex, pybool\n\ndel _thisdict, _tocheck, a, name, typeobj\ndel base, bit, char\n\n\n# Now, construct dictionary to lookup character codes from types\n\n_dtype2char_dict = {}\nfor name in typeinfo.keys():\n tup = typeinfo[name]\n if isinstance(tup,type(())):\n _dtype2char_dict[tup[-1]] = tup[0]\n\narraytypes = {'int': [],\n 'uint':[],\n 'float':[],\n 'complex':[],\n 'others':[bool_,object_,str_,unicode_,void]}\n\n_ibytes = [1,2,4,8,16,32,64]\n_fbytes = [2,4,8,10,12,16,32,64]\n \nfor bytes in _ibytes:\n bits = 8*bytes\n try:\n arraytypes['int'].append(eval(\"int%d\" % bits))\n except NameError:\n pass\n try:\n arraytypes['uint'].append(eval(\"uint%d\" % bits))\n except NameError:\n pass\n\nfor bytes in _fbytes:\n bits = 8*bytes\n try:\n arraytypes['float'].append(eval(\"float%d\" % bits))\n except NameError:\n pass\n try:\n arraytypes['complex'].append(eval(\"complex%d\" % (2*bits,)))\n except NameError:\n pass\n\ndel bytes, bits\n\ngenericTypeRank = ['bool','int8','uint8','int16','uint16',\n 'int32', 'uint32', 'int64', 'uint64', 'int128',\n 'uint128','float16',\n 'float32','float64', 'float80', 'float96', 'float128',\n 'float256'\n 'complex32', 'complex64', 'complex128', 'complex160',\n 'complex192', 'complex256', 'complex512', 'object']\n\ndef maximum_dtype(t):\n \"\"\"returns the type of highest precision of the same general kind as 't'\"\"\"\n g = obj2dtype(t)\n if g is None:\n return t\n t = g\n name = t.__name__[:-8]\n base, bits = _evalname(name)\n if bits == 0:\n return t\n else:\n return arraytypes[base][-1]\n\ndef _python_type(t):\n \"\"\"returns the type corresponding to a certain Python type\"\"\"\n if not isinstance(t, _types.TypeType):\n t = type(t)\n if t == _types.IntType:\n return int_\n elif t == _types.FloatType:\n return float_\n elif t == _types.ComplexType:\n return complex_\n elif t == _types.BooleanType:\n return bool_\n elif t == _types.StringType:\n return str_\n elif t == _types.UnicodeType:\n return unicode_\n elif t == _types.BufferType:\n return void\n else:\n return object_\n\ndef isdtype(rep):\n \"\"\"Determines whether the given object represents\n a numeric array type.\"\"\"\n try:\n char = dtype2char(rep)\n return True\n except (KeyError, ValueError):\n return False\n \ndef obj2dtype(rep, default=None):\n try:\n if issubclass(rep, generic):\n return rep\n except TypeError:\n pass\n \n if isinstance(rep, type):\n return _python_type(rep)\n if isinstance(rep, ndarray):\n return rep.dtype \n res = typeDict.get(rep, default)\n return res\n\ndef dtype2char(dtype):\n dtype = obj2dtype(dtype)\n if dtype is None:\n raise ValueError, \"unrecognized type\"\n return _dtype2char_dict[dtype]\n\n\ndel _ibytes, _fbytes, multiarray\n\n# Create dictionary of casting functions that wrap sequences\n# indexed by type or type character\n\n# This dictionary allows look up based on any alias for a type\nclass _castdict(dict):\n def __getitem__(self, obj):\n return dict.__getitem__(self, obj2dtype(obj))\n\ncast = _castdict()\nScalarType = [_types.IntType, _types.FloatType,\n _types.ComplexType, _types.LongType, _types.BooleanType,\n _types.StringType, _types.UnicodeType, _types.BufferType]\nScalarType.extend(_dtype2char_dict.keys())\nfor key in _dtype2char_dict.keys():\n cast[key] = lambda x, k=key : array(x,copy=False).astype(k)\n\ndel key\n\n\n\n\n", "methods": [ { "name": "_evalname", "long_name": "_evalname( name )", "filename": "numerictypes.py", "nloc": 12, "complexity": 4, "token_count": 51, "parameters": [ "name" ], "start_line": 99, "end_line": 110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "bitname", "long_name": "bitname( obj )", "filename": "numerictypes.py", "nloc": 30, "complexity": 9, "token_count": 151, "parameters": [ "obj" ], "start_line": 112, "end_line": 147, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "maximum_dtype", "long_name": "maximum_dtype( t )", "filename": "numerictypes.py", "nloc": 11, "complexity": 3, "token_count": 58, "parameters": [ "t" ], "start_line": 261, "end_line": 272, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "_python_type", "long_name": "_python_type( t )", "filename": "numerictypes.py", "nloc": 19, "complexity": 9, "token_count": 90, "parameters": [ "t" ], "start_line": 274, "end_line": 293, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "isdtype", "long_name": "isdtype( rep )", "filename": "numerictypes.py", "nloc": 6, "complexity": 2, "token_count": 25, "parameters": [ "rep" ], "start_line": 295, "end_line": 302, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "obj2dtype", "long_name": "obj2dtype( rep , default = None )", "filename": "numerictypes.py", "nloc": 12, "complexity": 5, "token_count": 62, "parameters": [ "rep", "default" ], "start_line": 304, "end_line": 316, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "dtype2char", "long_name": "dtype2char( dtype )", "filename": "numerictypes.py", "nloc": 5, "complexity": 2, "token_count": 25, "parameters": [ "dtype" ], "start_line": 318, "end_line": 322, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "__getitem__", "long_name": "__getitem__( self , obj )", "filename": "numerictypes.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self", "obj" ], "start_line": 332, "end_line": 333, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 } ], "methods_before": [ { "name": "_evalname", "long_name": "_evalname( name )", "filename": "numerictypes.py", "nloc": 12, "complexity": 4, "token_count": 51, "parameters": [ "name" ], "start_line": 99, "end_line": 110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "bitname", "long_name": "bitname( obj )", "filename": "numerictypes.py", "nloc": 30, "complexity": 9, "token_count": 151, "parameters": [ "obj" ], "start_line": 112, "end_line": 147, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "maximum_dtype", "long_name": "maximum_dtype( t )", "filename": "numerictypes.py", "nloc": 11, "complexity": 3, "token_count": 58, "parameters": [ "t" ], "start_line": 261, "end_line": 272, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "_python_type", "long_name": "_python_type( t )", "filename": "numerictypes.py", "nloc": 19, "complexity": 9, "token_count": 90, "parameters": [ "t" ], "start_line": 274, "end_line": 293, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "isdtype", "long_name": "isdtype( rep )", "filename": "numerictypes.py", "nloc": 6, "complexity": 2, "token_count": 25, "parameters": [ "rep" ], "start_line": 295, "end_line": 302, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "obj2dtype", "long_name": "obj2dtype( rep , default = None )", "filename": "numerictypes.py", "nloc": 12, "complexity": 5, "token_count": 62, "parameters": [ "rep", "default" ], "start_line": 304, "end_line": 316, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "dtype2char", "long_name": "dtype2char( dtype )", "filename": "numerictypes.py", "nloc": 5, "complexity": 2, "token_count": 25, "parameters": [ "dtype" ], "start_line": 318, "end_line": 322, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "__getitem__", "long_name": "__getitem__( self , obj )", "filename": "numerictypes.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self", "obj" ], "start_line": 332, "end_line": 333, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 } ], "changed_methods": [], "nloc": 285, "complexity": 35, "token_count": 1203, "diff_parsed": { "added": [ "ScalarType = tuple(ScalarType)" ], "deleted": [] } } ] }, { "hash": "8386582770a3fc9f9b315fd54a5047228b736cb4", "msg": "Fixed get_lib_source_files bug.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2005-10-27T11:52:55+00:00", "author_timezone": 0, "committer_date": "2005-10-27T11:52:55+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "a25e5da35747e2a4cacc326f2709b0fb278c1d29" ], "project_name": "repo_copy", "project_path": "/tmp/tmpn4cqam_6/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": "scipy/distutils/misc_util.py", "new_path": "scipy/distutils/misc_util.py", "filename": "misc_util.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -224,7 +224,7 @@ def get_lib_source_files(lib):\n sources = filter(lambda s:type(s) is types.StringType,sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n- depends = build_info.get('depends',[])\n+ depends = lib[1].get('depends',[])\n for d in depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n", "added_lines": 1, "deleted_lines": 1, "source_code": "import os\nimport re\nimport sys\nimport imp\nimport copy\nimport types\nimport glob\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__':\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 file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\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 all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return False\n return True\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 dir in directory_list:\n head = glob.glob(os.path.join(dir,\"*.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 file in list_of_sources:\n dir = os.path.split(file)\n if dir[0] != '' and not dir[0] in direcs:\n direcs.append(dir[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 type(directory) is not type(''):\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 _gsf_visit_func(filenames,dirname,names):\n if os.path.basename(dirname) in ['CVS','.svn','build']:\n names[:] = []\n return\n for name in names:\n if name[-1] in \"~#\":\n continue\n fullname = os.path.join(dirname,name)\n ext = os.path.splitext(fullname)[1]\n if ext and ext in ['.pyc','.o']:\n continue\n if os.path.isfile(fullname):\n filenames.append(fullname)\n\ndef get_ext_source_files(ext):\n # Get sources and any include files in the same directory.\n filenames = []\n sources = filter(lambda s:type(s) is types.StringType,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 os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_script_files(scripts):\n scripts = filter(lambda s:type(s) is types.StringType,scripts)\n return scripts\n\ndef get_lib_source_files(lib):\n filenames = []\n sources = lib[1].get('sources',[])\n sources = filter(lambda s:type(s) is types.StringType,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 os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_data_files(data):\n if type(data) is types.StringType:\n return [data]\n sources = data[1]\n filenames = []\n for s in sources:\n if callable(s):\n s = s()\n if s is None:\n continue\n if is_local_src_dir(s):\n os.path.walk(s,_gsf_visit_func,filenames)\n elif type(s) is type(''):\n if os.path.isfile(s):\n filenames.append(s)\n else:\n print 'Not existing data file:',s\n else:\n raise TypeError,`s`\n return filenames\n\ndef dot_join(*args):\n return '.'.join(filter(None,args))\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 i in range(level+1):\n frame = frame.f_back\n return frame\n\n######################\n\nclass Configuration:\n\n _list_keys = ['packages','ext_modules','data_files','include_dirs',\n 'libraries','headers','scripts']\n _dict_keys = ['package_dir']\n\n scipy_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 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(os.path.join(self.local_path,package_path)):\n package_path = os.path.join(self.local_path,package_path)\n assert os.path.isdir(package_path),`package_path`\n self.top_path = top_path\n\n self.list_keys = copy.copy(self._list_keys)\n self.dict_keys = copy.copy(self._dict_keys)\n\n for n in self.list_keys:\n setattr(self,n,copy.copy(attrs.get(n,[])))\n\n for n in self.dict_keys:\n setattr(self,n,copy.copy(attrs.get(n,{})))\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 type(a) is types.ListType:\n self.list_keys.append(n)\n elif type(a) is types.DictType:\n self.dict_keys.append(n)\n else:\n self.extra_keys.append(n)\n\n if os.path.exists(os.path.join(package_path,'__init__.py')):\n self.packages.append(self.name)\n self.package_dir[self.name] = package_path \n return\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 __dict__(self):\n return self.todict()\n\n def get_distribution(self):\n import distutils.core\n dist = distutils.core._setup_distribution \n return dist\n\n def get_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Return subpackage configuration.\n \"\"\"\n if subpackage_name is None:\n assert subpackage_path is not None\n subpackage_name = os.path.basename(subpackage_path)\n assert '.' not in subpackage_name,`subpackage_name`\n if subpackage_path is None:\n subpackage_path = os.path.join(self.local_path,subpackage_name)\n else:\n subpackage_path = self._fix_paths([subpackage_path])[0]\n\n setup_py = os.path.join(subpackage_path,'setup_%s.py' % (subpackage_name))\n if not os.path.isfile(setup_py):\n setup_py = os.path.join(subpackage_path,'setup.py')\n if not os.path.isfile(setup_py):\n print '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 # In case setup_py imports local modules:\n sys.path.insert(0,os.path.dirname(setup_py))\n try:\n info = (open(setup_py),setup_py,('.py','U',1))\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('.')),*info)\n\n if not hasattr(setup_module,'configuration'):\n print 'Assuming default configuration '\\\n '(%s does not define configuration())' % (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\n finally:\n del sys.path[0]\n\n return config\n\n def add_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Add subpackage to configuration.\n \"\"\"\n config = self.get_subpackage(subpackage_name,subpackage_path)\n\n if not config:\n print 'No configuration returned, assuming unavailable.'\n else:\n\n if isinstance(config,Configuration):\n print 'Appending %s configuration to %s' % (config.name,self.name)\n self.dict_append(**config.todict())\n else:\n print 'Appending %s configuration to %s' % (config.get('name'),self.name)\n self.dict_append(**config)\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, 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 type(data_path) is type(()):\n assert len(data_path)==2,`data_path`\n d,data_path = data_path\n else:\n d = None\n assert type(data_path) is type(''),`data_path`\n for path in self.paths(data_path):\n if not os.path.exists(path):\n print 'Not existing data path',path\n continue\n filenames = []\n os.path.walk(path, _gsf_visit_func,filenames)\n if not os.path.isabs(path):\n if d is None:\n ds = os.path.join(*(self.name.split('.')+[data_path]))\n else:\n ds = os.path.join(d,data_path)\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 type(p) is not type(()):\n d = os.path.join(*(self.name.split('.')))\n if type(p) is type('') and not os.path.isabs(p):\n d = appendpath(d,os.path.dirname(p))\n p = (d,p)\n new_files.append(p)\n files = []\n for prefix,filepattern in new_files:\n if type(filepattern) is type(''):\n file_list = self.paths(filepattern)\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 type(f) is type('')]\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 type(f) is type(''):\n extra_path_components = f.split(os.sep)[min_path_components:-1]\n p = os.path.join(*([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 return \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 type(path) is type(''):\n [headers.append((self.name,p)) for p in self.paths(path)]\n else:\n assert type(path) in [type(()),type([])] and len(path)==2,`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):\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(os.path.join(self.local_path,n))\n if p2:\n new_paths.extend(p2)\n elif p:\n new_paths.extend(p)\n else:\n new_paths.append(n)\n else:\n n2 = os.path.join(self.local_path,n)\n if os.path.exists(n2):\n new_paths.append(n2)\n else:\n new_paths.append(n)\n else:\n new_paths.append(n)\n return new_paths\n\n def paths(self,*paths):\n \"\"\" Apply glob to paths and prepend local_path if needed.\n \"\"\"\n return self._fix_paths(paths)\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 type(extra_info) is type({}):\n extra_info = [extra_info]\n for info in extra_info:\n assert type(info) is type({}),`info`\n dict_append(ext_args,**info)\n\n for k in ext_args.keys():\n v = ext_args[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n ext_args[k] = new_v\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 '@' in libname:\n lname,lpath = libname.split('@',1)\n lpath = os.path.abspath(os.path.join(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 scipy.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 print 'distutils distribution has been initialized, 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 for k in build_info.keys():\n v = build_info[k]\n if k in ['sources','depends']:\n new_v = self._fix_paths(v)\n build_info[k] = new_v\n self.libraries.append((name,build_info))\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, 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 print '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 type(extlib) is type(()):\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 scipy.distutils.core import Extension\n assert isinstance(extlib,Extension),`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 = os.path.join(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 = os.path.join(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 print 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 = os.path.join(self.local_path,'__svn_version__.py')\n if os.path.isfile(target):\n return\n\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 print '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):\n try: os.remove(f); print 'removed',f\n except OSError: pass\n try: os.remove(f+'c'); print 'removed',f+'c'\n except OSError: pass\n atexit.register(rm_file)\n\n return target\n\n d = os.path.join(*(self.name.split('.')))\n self.add_data_files((d,generate_svn_version_py()))\n return\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.add_extension(name,[generate_config_py])\n return\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_scipy_include_dirs():\n include_dirs = Configuration.scipy_include_dirs[:]\n if not include_dirs:\n import scipy.base as base\n include_dirs.append(os.path.join(os.path.dirname(base.__file__),'include'))\n #from distutils.sysconfig import get_python_inc\n #prefix = []\n #for name in scipy.__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 return include_dirs\n\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.isabs(path):\n absprefix = os.path.abspath(prefix)\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(os.path.join(prefix, subpath))\n\ndef generate_config_py(extension, build_dir):\n \"\"\" Generate /config.py file containing system_info\n information used during building the package.\n\n Usage:\\\n ext = Extension(dot_join(config['name'],'config'),\n sources=[generate_config_py])\n config['ext_modules'].append(ext)\n \"\"\"\n from scipy.distutils.system_info import system_info\n from distutils.dir_util import mkpath\n target = os.path.join(*([build_dir]+extension.name.split('.'))) + '.py'\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\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n \n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = os.path.join(build_dir, '__svn_version__.py')\n entries = os.path.join(local_path,'.svn','entries')\n if os.path.isfile(entries):\n if not dep_util.newer(entries, target):\n return target\n elif os.path.isfile(target):\n return target\n\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n", "source_code_before": "import os\nimport re\nimport sys\nimport imp\nimport copy\nimport types\nimport glob\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__':\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 file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\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 all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return False\n return True\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 dir in directory_list:\n head = glob.glob(os.path.join(dir,\"*.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 file in list_of_sources:\n dir = os.path.split(file)\n if dir[0] != '' and not dir[0] in direcs:\n direcs.append(dir[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 type(directory) is not type(''):\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 _gsf_visit_func(filenames,dirname,names):\n if os.path.basename(dirname) in ['CVS','.svn','build']:\n names[:] = []\n return\n for name in names:\n if name[-1] in \"~#\":\n continue\n fullname = os.path.join(dirname,name)\n ext = os.path.splitext(fullname)[1]\n if ext and ext in ['.pyc','.o']:\n continue\n if os.path.isfile(fullname):\n filenames.append(fullname)\n\ndef get_ext_source_files(ext):\n # Get sources and any include files in the same directory.\n filenames = []\n sources = filter(lambda s:type(s) is types.StringType,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 os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_script_files(scripts):\n scripts = filter(lambda s:type(s) is types.StringType,scripts)\n return scripts\n\ndef get_lib_source_files(lib):\n filenames = []\n sources = lib[1].get('sources',[])\n sources = filter(lambda s:type(s) is types.StringType,sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n depends = build_info.get('depends',[])\n for d in depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_data_files(data):\n if type(data) is types.StringType:\n return [data]\n sources = data[1]\n filenames = []\n for s in sources:\n if callable(s):\n s = s()\n if s is None:\n continue\n if is_local_src_dir(s):\n os.path.walk(s,_gsf_visit_func,filenames)\n elif type(s) is type(''):\n if os.path.isfile(s):\n filenames.append(s)\n else:\n print 'Not existing data file:',s\n else:\n raise TypeError,`s`\n return filenames\n\ndef dot_join(*args):\n return '.'.join(filter(None,args))\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 i in range(level+1):\n frame = frame.f_back\n return frame\n\n######################\n\nclass Configuration:\n\n _list_keys = ['packages','ext_modules','data_files','include_dirs',\n 'libraries','headers','scripts']\n _dict_keys = ['package_dir']\n\n scipy_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 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(os.path.join(self.local_path,package_path)):\n package_path = os.path.join(self.local_path,package_path)\n assert os.path.isdir(package_path),`package_path`\n self.top_path = top_path\n\n self.list_keys = copy.copy(self._list_keys)\n self.dict_keys = copy.copy(self._dict_keys)\n\n for n in self.list_keys:\n setattr(self,n,copy.copy(attrs.get(n,[])))\n\n for n in self.dict_keys:\n setattr(self,n,copy.copy(attrs.get(n,{})))\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 type(a) is types.ListType:\n self.list_keys.append(n)\n elif type(a) is types.DictType:\n self.dict_keys.append(n)\n else:\n self.extra_keys.append(n)\n\n if os.path.exists(os.path.join(package_path,'__init__.py')):\n self.packages.append(self.name)\n self.package_dir[self.name] = package_path \n return\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 __dict__(self):\n return self.todict()\n\n def get_distribution(self):\n import distutils.core\n dist = distutils.core._setup_distribution \n return dist\n\n def get_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Return subpackage configuration.\n \"\"\"\n if subpackage_name is None:\n assert subpackage_path is not None\n subpackage_name = os.path.basename(subpackage_path)\n assert '.' not in subpackage_name,`subpackage_name`\n if subpackage_path is None:\n subpackage_path = os.path.join(self.local_path,subpackage_name)\n else:\n subpackage_path = self._fix_paths([subpackage_path])[0]\n\n setup_py = os.path.join(subpackage_path,'setup_%s.py' % (subpackage_name))\n if not os.path.isfile(setup_py):\n setup_py = os.path.join(subpackage_path,'setup.py')\n if not os.path.isfile(setup_py):\n print '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 # In case setup_py imports local modules:\n sys.path.insert(0,os.path.dirname(setup_py))\n try:\n info = (open(setup_py),setup_py,('.py','U',1))\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('.')),*info)\n\n if not hasattr(setup_module,'configuration'):\n print 'Assuming default configuration '\\\n '(%s does not define configuration())' % (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\n finally:\n del sys.path[0]\n\n return config\n\n def add_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Add subpackage to configuration.\n \"\"\"\n config = self.get_subpackage(subpackage_name,subpackage_path)\n\n if not config:\n print 'No configuration returned, assuming unavailable.'\n else:\n\n if isinstance(config,Configuration):\n print 'Appending %s configuration to %s' % (config.name,self.name)\n self.dict_append(**config.todict())\n else:\n print 'Appending %s configuration to %s' % (config.get('name'),self.name)\n self.dict_append(**config)\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, 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 type(data_path) is type(()):\n assert len(data_path)==2,`data_path`\n d,data_path = data_path\n else:\n d = None\n assert type(data_path) is type(''),`data_path`\n for path in self.paths(data_path):\n if not os.path.exists(path):\n print 'Not existing data path',path\n continue\n filenames = []\n os.path.walk(path, _gsf_visit_func,filenames)\n if not os.path.isabs(path):\n if d is None:\n ds = os.path.join(*(self.name.split('.')+[data_path]))\n else:\n ds = os.path.join(d,data_path)\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 type(p) is not type(()):\n d = os.path.join(*(self.name.split('.')))\n if type(p) is type('') and not os.path.isabs(p):\n d = appendpath(d,os.path.dirname(p))\n p = (d,p)\n new_files.append(p)\n files = []\n for prefix,filepattern in new_files:\n if type(filepattern) is type(''):\n file_list = self.paths(filepattern)\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 type(f) is type('')]\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 type(f) is type(''):\n extra_path_components = f.split(os.sep)[min_path_components:-1]\n p = os.path.join(*([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 return \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 type(path) is type(''):\n [headers.append((self.name,p)) for p in self.paths(path)]\n else:\n assert type(path) in [type(()),type([])] and len(path)==2,`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):\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(os.path.join(self.local_path,n))\n if p2:\n new_paths.extend(p2)\n elif p:\n new_paths.extend(p)\n else:\n new_paths.append(n)\n else:\n n2 = os.path.join(self.local_path,n)\n if os.path.exists(n2):\n new_paths.append(n2)\n else:\n new_paths.append(n)\n else:\n new_paths.append(n)\n return new_paths\n\n def paths(self,*paths):\n \"\"\" Apply glob to paths and prepend local_path if needed.\n \"\"\"\n return self._fix_paths(paths)\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 type(extra_info) is type({}):\n extra_info = [extra_info]\n for info in extra_info:\n assert type(info) is type({}),`info`\n dict_append(ext_args,**info)\n\n for k in ext_args.keys():\n v = ext_args[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n ext_args[k] = new_v\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 '@' in libname:\n lname,lpath = libname.split('@',1)\n lpath = os.path.abspath(os.path.join(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 scipy.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 print 'distutils distribution has been initialized, 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 for k in build_info.keys():\n v = build_info[k]\n if k in ['sources','depends']:\n new_v = self._fix_paths(v)\n build_info[k] = new_v\n self.libraries.append((name,build_info))\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, 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 print '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 type(extlib) is type(()):\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 scipy.distutils.core import Extension\n assert isinstance(extlib,Extension),`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 = os.path.join(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 = os.path.join(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 print 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 = os.path.join(self.local_path,'__svn_version__.py')\n if os.path.isfile(target):\n return\n\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 print '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):\n try: os.remove(f); print 'removed',f\n except OSError: pass\n try: os.remove(f+'c'); print 'removed',f+'c'\n except OSError: pass\n atexit.register(rm_file)\n\n return target\n\n d = os.path.join(*(self.name.split('.')))\n self.add_data_files((d,generate_svn_version_py()))\n return\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.add_extension(name,[generate_config_py])\n return\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_scipy_include_dirs():\n include_dirs = Configuration.scipy_include_dirs[:]\n if not include_dirs:\n import scipy.base as base\n include_dirs.append(os.path.join(os.path.dirname(base.__file__),'include'))\n #from distutils.sysconfig import get_python_inc\n #prefix = []\n #for name in scipy.__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 return include_dirs\n\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.isabs(path):\n absprefix = os.path.abspath(prefix)\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(os.path.join(prefix, subpath))\n\ndef generate_config_py(extension, build_dir):\n \"\"\" Generate /config.py file containing system_info\n information used during building the package.\n\n Usage:\\\n ext = Extension(dot_join(config['name'],'config'),\n sources=[generate_config_py])\n config['ext_modules'].append(ext)\n \"\"\"\n from scipy.distutils.system_info import system_info\n from distutils.dir_util import mkpath\n target = os.path.join(*([build_dir]+extension.name.split('.'))) + '.py'\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\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n \n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = os.path.join(build_dir, '__svn_version__.py')\n entries = os.path.join(local_path,'.svn','entries')\n if os.path.isfile(entries):\n if not dep_util.newer(entries, target):\n return target\n elif os.path.isfile(target):\n return target\n\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\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": 9, "end_line": 12, "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": 6, "token_count": 129, "parameters": [ "mod_name", "parent_path" ], "start_line": 14, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "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": 38, "end_line": 63, "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": 80, "end_line": 83, "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": 92, "end_line": 108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "all_strings", "long_name": "all_strings( lst )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 26, "parameters": [ "lst" ], "start_line": 110, "end_line": 115, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "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": 117, "end_line": 122, "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": 124, "end_line": 129, "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": 131, "end_line": 151, "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": 154, "end_line": 160, "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": 162, "end_line": 169, "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": 171, "end_line": 173, "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": 112, "parameters": [ "directory" ], "start_line": 175, "end_line": 188, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "_gsf_visit_func", "long_name": "_gsf_visit_func( filenames , dirname , names )", "filename": "misc_util.py", "nloc": 13, "complexity": 7, "token_count": 103, "parameters": [ "filenames", "dirname", "names" ], "start_line": 190, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 87, "parameters": [ "ext" ], "start_line": 204, "end_line": 215, "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": 25, "parameters": [ "scripts" ], "start_line": 217, "end_line": 219, "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": 111, "parameters": [ "lib" ], "start_line": 221, "end_line": 233, "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": 20, "complexity": 8, "token_count": 112, "parameters": [ "data" ], "start_line": 235, "end_line": 254, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "dot_join", "long_name": "dot_join( * args )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "args" ], "start_line": 256, "end_line": 257, "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": 259, "end_line": 266, "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": 41, "complexity": 11, "token_count": 348, "parameters": [ "self", "package_name", "parent_name", "top_path", "package_path", "attrs" ], "start_line": 278, "end_line": 327, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "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": 329, "end_line": 340, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "__dict__", "long_name": "__dict__( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 342, "end_line": 343, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "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": 345, "end_line": 348, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "get_subpackage", "long_name": "get_subpackage( self , subpackage_name , subpackage_path = None )", "filename": "misc_util.py", "nloc": 38, "complexity": 8, "token_count": 333, "parameters": [ "self", "subpackage_name", "subpackage_path" ], "start_line": 350, "end_line": 394, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 45, "top_nesting_level": 1 }, { "name": "add_subpackage", "long_name": "add_subpackage( self , subpackage_name , subpackage_path = None )", "filename": "misc_util.py", "nloc": 15, "complexity": 4, "token_count": 103, "parameters": [ "self", "subpackage_name", "subpackage_path" ], "start_line": 396, "end_line": 415, "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": 7, "token_count": 188, "parameters": [ "self", "data_path" ], "start_line": 417, "end_line": 449, "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": 40, "complexity": 15, "token_count": 324, "parameters": [ "self", "files" ], "start_line": 451, "end_line": 501, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 51, "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": 503, "end_line": 512, "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": 14, "complexity": 7, "token_count": 143, "parameters": [ "self", "files" ], "start_line": 514, "end_line": 533, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "_fix_paths", "long_name": "_fix_paths( self , paths )", "filename": "misc_util.py", "nloc": 22, "complexity": 8, "token_count": 136, "parameters": [ "self", "paths" ], "start_line": 535, "end_line": 556, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "paths", "long_name": "paths( self , * paths )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "paths" ], "start_line": 558, "end_line": 561, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "add_extension", "long_name": "add_extension( self , name , sources , ** kw )", "filename": "misc_util.py", "nloc": 45, "complexity": 14, "token_count": 365, "parameters": [ "self", "name", "sources", "kw" ], "start_line": 563, "end_line": 625, "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": 14, "complexity": 4, "token_count": 98, "parameters": [ "self", "name", "sources", "build_info" ], "start_line": 627, "end_line": 651, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "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": 653, "end_line": 662, "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": 15, "complexity": 6, "token_count": 138, "parameters": [ "self", "dict" ], "start_line": 664, "end_line": 678, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "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": 680, "end_line": 689, "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": 691, "end_line": 700, "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": 702, "end_line": 705, "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": 707, "end_line": 718, "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": 720, "end_line": 731, "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": 83, "parameters": [ "self", "extlib" ], "start_line": 733, "end_line": 746, "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": 77, "parameters": [ "self", "path" ], "start_line": 748, "end_line": 759, "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": 257, "parameters": [ "self" ], "start_line": 761, "end_line": 807, "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 )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 45, "parameters": [ "f" ], "start_line": 831, "end_line": 835, "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": 81, "parameters": [], "start_line": 820, "end_line": 838, "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": 8, "complexity": 2, "token_count": 66, "parameters": [ "self" ], "start_line": 809, "end_line": 842, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "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": 21, "parameters": [ "self", "name" ], "start_line": 844, "end_line": 849, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "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": 851, "end_line": 861, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "get_scipy_include_dirs", "long_name": "get_scipy_include_dirs( )", "filename": "misc_util.py", "nloc": 6, "complexity": 2, "token_count": 48, "parameters": [], "start_line": 863, "end_line": 875, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 879, "end_line": 884, "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": 13, "complexity": 5, "token_count": 157, "parameters": [ "prefix", "path" ], "start_line": 886, "end_line": 899, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "generate_config_py", "long_name": "generate_config_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 28, "complexity": 2, "token_count": 145, "parameters": [ "extension", "build_dir" ], "start_line": 901, "end_line": 937, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "generate_svn_version_py", "long_name": "generate_svn_version_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 15, "complexity": 4, "token_count": 109, "parameters": [ "extension", "build_dir" ], "start_line": 939, "end_line": 966, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "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": 9, "end_line": 12, "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": 6, "token_count": 129, "parameters": [ "mod_name", "parent_path" ], "start_line": 14, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "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": 38, "end_line": 63, "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": 80, "end_line": 83, "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": 92, "end_line": 108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "all_strings", "long_name": "all_strings( lst )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 26, "parameters": [ "lst" ], "start_line": 110, "end_line": 115, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "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": 117, "end_line": 122, "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": 124, "end_line": 129, "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": 131, "end_line": 151, "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": 154, "end_line": 160, "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": 162, "end_line": 169, "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": 171, "end_line": 173, "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": 112, "parameters": [ "directory" ], "start_line": 175, "end_line": 188, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "_gsf_visit_func", "long_name": "_gsf_visit_func( filenames , dirname , names )", "filename": "misc_util.py", "nloc": 13, "complexity": 7, "token_count": 103, "parameters": [ "filenames", "dirname", "names" ], "start_line": 190, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 87, "parameters": [ "ext" ], "start_line": 204, "end_line": 215, "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": 25, "parameters": [ "scripts" ], "start_line": 217, "end_line": 219, "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": 108, "parameters": [ "lib" ], "start_line": 221, "end_line": 233, "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": 20, "complexity": 8, "token_count": 112, "parameters": [ "data" ], "start_line": 235, "end_line": 254, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "dot_join", "long_name": "dot_join( * args )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "args" ], "start_line": 256, "end_line": 257, "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": 259, "end_line": 266, "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": 41, "complexity": 11, "token_count": 348, "parameters": [ "self", "package_name", "parent_name", "top_path", "package_path", "attrs" ], "start_line": 278, "end_line": 327, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "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": 329, "end_line": 340, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "__dict__", "long_name": "__dict__( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 342, "end_line": 343, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "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": 345, "end_line": 348, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "get_subpackage", "long_name": "get_subpackage( self , subpackage_name , subpackage_path = None )", "filename": "misc_util.py", "nloc": 38, "complexity": 8, "token_count": 333, "parameters": [ "self", "subpackage_name", "subpackage_path" ], "start_line": 350, "end_line": 394, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 45, "top_nesting_level": 1 }, { "name": "add_subpackage", "long_name": "add_subpackage( self , subpackage_name , subpackage_path = None )", "filename": "misc_util.py", "nloc": 15, "complexity": 4, "token_count": 103, "parameters": [ "self", "subpackage_name", "subpackage_path" ], "start_line": 396, "end_line": 415, "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": 7, "token_count": 188, "parameters": [ "self", "data_path" ], "start_line": 417, "end_line": 449, "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": 40, "complexity": 15, "token_count": 324, "parameters": [ "self", "files" ], "start_line": 451, "end_line": 501, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 51, "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": 503, "end_line": 512, "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": 14, "complexity": 7, "token_count": 143, "parameters": [ "self", "files" ], "start_line": 514, "end_line": 533, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "_fix_paths", "long_name": "_fix_paths( self , paths )", "filename": "misc_util.py", "nloc": 22, "complexity": 8, "token_count": 136, "parameters": [ "self", "paths" ], "start_line": 535, "end_line": 556, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "paths", "long_name": "paths( self , * paths )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "paths" ], "start_line": 558, "end_line": 561, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "add_extension", "long_name": "add_extension( self , name , sources , ** kw )", "filename": "misc_util.py", "nloc": 45, "complexity": 14, "token_count": 365, "parameters": [ "self", "name", "sources", "kw" ], "start_line": 563, "end_line": 625, "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": 14, "complexity": 4, "token_count": 98, "parameters": [ "self", "name", "sources", "build_info" ], "start_line": 627, "end_line": 651, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "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": 653, "end_line": 662, "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": 15, "complexity": 6, "token_count": 138, "parameters": [ "self", "dict" ], "start_line": 664, "end_line": 678, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "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": 680, "end_line": 689, "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": 691, "end_line": 700, "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": 702, "end_line": 705, "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": 707, "end_line": 718, "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": 720, "end_line": 731, "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": 83, "parameters": [ "self", "extlib" ], "start_line": 733, "end_line": 746, "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": 77, "parameters": [ "self", "path" ], "start_line": 748, "end_line": 759, "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": 257, "parameters": [ "self" ], "start_line": 761, "end_line": 807, "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 )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 45, "parameters": [ "f" ], "start_line": 831, "end_line": 835, "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": 81, "parameters": [], "start_line": 820, "end_line": 838, "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": 8, "complexity": 2, "token_count": 66, "parameters": [ "self" ], "start_line": 809, "end_line": 842, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "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": 21, "parameters": [ "self", "name" ], "start_line": 844, "end_line": 849, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "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": 851, "end_line": 861, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "get_scipy_include_dirs", "long_name": "get_scipy_include_dirs( )", "filename": "misc_util.py", "nloc": 6, "complexity": 2, "token_count": 48, "parameters": [], "start_line": 863, "end_line": 875, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 879, "end_line": 884, "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": 13, "complexity": 5, "token_count": 157, "parameters": [ "prefix", "path" ], "start_line": 886, "end_line": 899, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "generate_config_py", "long_name": "generate_config_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 28, "complexity": 2, "token_count": 145, "parameters": [ "extension", "build_dir" ], "start_line": 901, "end_line": 937, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "generate_svn_version_py", "long_name": "generate_svn_version_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 15, "complexity": 4, "token_count": 109, "parameters": [ "extension", "build_dir" ], "start_line": 939, "end_line": 966, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "get_lib_source_files", "long_name": "get_lib_source_files( lib )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 111, "parameters": [ "lib" ], "start_line": 221, "end_line": 233, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 } ], "nloc": 719, "complexity": 228, "token_count": 5321, "diff_parsed": { "added": [ " depends = lib[1].get('depends',[])" ], "deleted": [ " depends = build_info.get('depends',[])" ] } } ] }, { "hash": "6d634976e0d55422ab4c2bdd771078050fe5744d", "msg": "Improved docstrings:\n * Fuller explanation of default casting behaviour of a.sum(), a.mean(),\n scipy.sum(), and scipy.average()\n * Changed some array variable names from 'x' to 'a' in function_base.py\n for consistency with docstrings in arraymethods.c\n * Other cosmetic fixes to docstrings and code formatting", "author": { "name": "edschofield", "email": "edschofield@localhost" }, "committer": { "name": "edschofield", "email": "edschofield@localhost" }, "author_date": "2005-10-27T13:59:16+00:00", "author_timezone": 0, "committer_date": "2005-10-27T13:59:16+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "8386582770a3fc9f9b315fd54a5047228b736cb4" ], "project_name": "repo_copy", "project_path": "/tmp/tmpn4cqam_6/repo_copy", "deletions": 190, "insertions": 261, "lines": 451, "files": 3, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "scipy/base/function_base.py", "new_path": "scipy/base/function_base.py", "filename": "function_base.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -12,13 +12,13 @@\n from _compiled_base import digitize, bincount, _insert\n from ufunclike import sign\n \n-__all__ = ['logspace','linspace', 'round_',\n- 'select','piecewise','trim_zeros','alen','amax', 'amin', 'ptp',\n- 'copy', 'iterable', 'base_repr', 'binary_repr', \n- 'prod','cumprod', 'diff','gradient','angle','unwrap','sort_complex',\n- 'disp','unique','extract','insert','nansum','nanmax','nanargmax',\n- 'nanargmin','nanmin', 'vectorize','asarray_chkfinite',\n- 'average','histogram','bincount','digitize']\n+__all__ = ['logspace', 'linspace', 'round_',\n+ 'select', 'piecewise', 'trim_zeros', 'alen', 'amax', 'amin', 'ptp',\n+ 'copy', 'iterable', 'base_repr', 'binary_repr', 'prod', 'cumprod',\n+ 'diff', 'gradient', 'angle', 'unwrap', 'sort_complex', 'disp',\n+ 'unique', 'extract', 'insert', 'nansum', 'nanmax', 'nanargmax',\n+ 'nanargmin', 'nanmin', 'vectorize', 'asarray_chkfinite', 'average',\n+ 'histogram', 'bincount', 'digitize']\n \n _lkup = {'0':'000',\n '1':'001',\n@@ -33,7 +33,8 @@\n def binary_repr(num):\n \"\"\"Return the binary representation of the input number as a string.\n \n- This is abuut 25x faster than using base_repr with base 2.\n+ This is equivalent to using base_repr with base 2, but about 25x\n+ faster.\n \"\"\"\n ostr = oct(num)\n bin = ''\n@@ -65,34 +66,33 @@ def base_repr (number, base=2, padding=0):\n \n \n \n-def logspace(start,stop,num=50,endpoint=1):\n- \"\"\" Evenly spaced samples on a logarithmic scale.\n+def logspace(start, stop, num=50, endpoint=True):\n+ \"\"\" Return evenly spaced samples on a logarithmic scale.\n \n- Return num evenly spaced samples from 10**start to 10**stop. If\n- endpoint=1 then last sample is 10**stop.\n+ Return 'num' evenly spaced samples from 10**start to 10**stop.\n+ If 'endpoint' is True then the last sample is 10**stop.\n \"\"\"\n if num <= 0: return array([])\n if endpoint:\n step = (stop-start)/float((num-1))\n- y = _nx.arange(0,num) * step + start\n+ y = _nx.arange(0, num) * step + start\n else:\n step = (stop-start)/float(num)\n- y = _nx.arange(0,num) * step + start\n- return _nx.power(10.0,y)\n+ y = _nx.arange(0, num) * step + start\n+ return _nx.power(10.0, y)\n \n-def linspace(start,stop,num=50,endpoint=1,retstep=False):\n- \"\"\" Evenly spaced samples.\n- \n- Return num evenly spaced samples from start to stop. If endpoint=1 then\n- last sample is stop. If retstep is true then return the step value used.\n+def linspace(start, stop, num=50, endpoint=True, retstep=False):\n+ \"\"\" Return 'num' evenly spaced samples from 'start' to 'stop'. If\n+ 'endpoint' is True, the last sample is 'stop'. If 'retstep' is\n+ True then return the step value used.\n \"\"\"\n if num <= 0: return array([])\n if endpoint:\n step = (stop-start)/float((num-1))\n- y = _nx.arange(0,num) * step + start \n+ y = _nx.arange(0, num) * step + start \n else:\n step = (stop-start)/float(num)\n- y = _nx.arange(0,num) * step + start\n+ y = _nx.arange(0, num) * step + start\n if retstep:\n return y, step\n else:\n@@ -103,46 +103,56 @@ def iterable(y):\n except: return 0\n return 1\n \n-def histogram(x, bins=10, range=None, normed=False):\n- x = asarray(x).ravel()\n+def histogram(a, bins=10, range=None, normed=False):\n+ a = asarray(a).ravel()\n if not iterable(bins):\n if range is None:\n- range = (x.min(), x.max())\n- mn, mx = [x+0.0 for x in range]\n+ range = (a.min(), a.max())\n+ mn, mx = [a+0.0 for a in range]\n if mn == mx:\n mn -= 0.5\n mx += 0.5\n bins = linspace(mn, mx, bins)\n \n- n = x.sort().searchsorted(bins)\n- n = concatenate([n, [len(x)]])\n+ n = a.sort().searchsorted(bins)\n+ n = concatenate([n, [len(a)]])\n n = n[1:]-n[:-1]\n \n if normed:\n db = bins[1] - bins[0]\n- return 1.0/(x.size*db) * n, bins\n+ return 1.0/(a.size*db) * n, bins\n else:\n return n, bins\n \n-def average(a, axis=0, weights=None, returned=0):\n- \"\"\"average(a, axis=0, weights=None)\n- Computes average along indicated axis. \n- If axis is None, average over the entire array.\n- Inputs can be integer or floating types; result is type Float.\n- \n- If weights are given, result is:\n- sum(a*weights)/(sum(weights))\n- weights must have a's shape or be the 1-d with length the size\n- of a in the given axis. Integer weights are converted to Float.\n+def average(a, axis=0, weights=None, returned=False):\n+ \"\"\"average(a, axis=0, weights=None, returned=False)\n+\n+ Compute average over the given axis. If axis is None, average \n+ over all dimensions of the array. Equivalent to a.mean(axis), \n+ but with a default axis of 0 instead of None.\n \n- Not supplying weights is equivalent to supply weights that are\n- all 1.\n+ The average of an integer or floating-point array always has type\n+ Float. \n+ \n+ If an integer axis is given, this equals:\n+ a.sum(axis) * 1.0 / len(a)\n+ \n+ If axis is None, this equals:\n+ a.sum(axis) * 1.0 / product(a.shape)\n \n- If returned, return a tuple: the result and the sum of the weights \n- or count of values. The shape of these two results will be the same.\n+ If weights are given, result is:\n+ sum(a * weights) / sum(weights),\n+ where the weights must have a's shape or be 1D with length the \n+ size of a in the given axis. Integer weights are converted to \n+ Float. Not specifying weights is equivalent to specifying \n+ weights that are all 1.\n+\n+ If 'returned' is True, return a tuple: the result and the sum of\n+ the weights or count of values. The shape of these two results\n+ will be the same.\n \n- raises ZeroDivisionError if appropriate when result is scalar.\n- (The version in MA does not -- it returns masked values).\n+ Raises ZeroDivisionError if appropriate. (The version in MA does\n+ not -- it returns masked values).\n \"\"\"\n if axis is None:\n a = array(a).ravel()\n@@ -151,7 +161,7 @@ def average(a, axis=0, weights=None, returned=0):\n d = len(a) * 1.0\n else:\n w = array(weights).ravel() * 1.0\n- n = add.reduce(multiply(a,w))\n+ n = add.reduce(multiply(a, w))\n d = add.reduce(w) \n else:\n a = array(a)\n@@ -174,16 +184,16 @@ def average(a, axis=0, weights=None, returned=0):\n elif wsh == (ash[axis],):\n ni = ash[axis]\n r = [newaxis]*ni\n- r[axis] = slice(None,None,1)\n+ r[axis] = slice(None, None, 1)\n w1 = eval(\"w[\"+repr(tuple(r))+\"]*ones(ash, Float)\")\n n = add.reduce(a*w1, axis)\n d = add.reduce(w1, axis)\n else:\n- raise ValueError, 'average: weights wrong shape.'\n+ raise ValueError, 'averaging weights have wrong shape'\n \n if not isinstance(d, ArrayType):\n if d == 0.0: \n- raise ZeroDivisionError, 'Numeric.average, zero denominator'\n+ raise ZeroDivisionError, 'zero denominator in average()'\n if returned:\n return n/d, d\n else:\n@@ -195,20 +205,20 @@ def isaltered():\n return 'scipy' in val\n \n \n-def asarray_chkfinite(x):\n- \"\"\"Like asarray except it checks to be sure no NaNs or Infs are present.\n+def asarray_chkfinite(a):\n+ \"\"\"Like asarray, but check that no NaNs or Infs are present.\n \"\"\"\n- x = asarray(x)\n- if (x.dtypechar in _nx.typecodes['AllFloat']) \\\n- and (_nx.isnan(x).any() or _nx.isinf(x).any()):\n- raise ValueError, \"array must not contain infs or nans\"\n- return x \n+ a = asarray(a)\n+ if (a.dtypechar in _nx.typecodes['AllFloat']) \\\n+ and (_nx.isnan(a).any() or _nx.isinf(a).any()):\n+ raise ValueError, \"array must not contain infs or NaNs\"\n+ return a \n \n \n \n \n def piecewise(x, condlist, funclist, *args, **kw):\n- \"\"\"Returns a piecewise-defined function.\n+ \"\"\"Return a piecewise-defined function.\n \n x is the domain\n \n@@ -245,7 +255,7 @@ def piecewise(x, condlist, funclist, *args, **kw):\n n = len(condlist)\n if n == n2-1: # compute the \"otherwise\" condition.\n totlist = condlist[0]\n- for k in range(1,n):\n+ for k in range(1, n):\n totlist |= condlist\n condlist.append(~totlist)\n n += 1\n@@ -261,16 +271,16 @@ def piecewise(x, condlist, funclist, *args, **kw):\n return y\n \n def select(condlist, choicelist, default=0):\n- \"\"\" Returns an array comprised from different elements of choicelist\n+ \"\"\" Return an array composed of different elements of choicelist\n depending on the list of conditions.\n \n condlist is a list of condition arrays containing ones or zeros\n \n choicelist is a list of choice arrays (of the \"same\" size as the\n arrays in condlist). The result array has the \"same\" size as the\n- arrays in choicelist. If condlist is [c0,...,cN-1] then choicelist\n+ arrays in choicelist. If condlist is [c0, ..., cN-1] then choicelist\n must be of length N. The elements of the choicelist can then be\n- represented as [v0,...,vN-1]. The default choice if none of the\n+ represented as [v0, ..., vN-1]. The default choice if none of the\n conditions are met is given as the default argument. \n \n The conditions are tested in order and the first one statisfied is\n@@ -285,17 +295,17 @@ def select(condlist, choicelist, default=0):\n elif cN-1: vN-1\n else: default\n \n- Note, that one of the condition arrays must be large enough to handle\n+ Note that one of the condition arrays must be large enough to handle\n the largest array in the choice list.\n \"\"\"\n n = len(condlist)\n n2 = len(choicelist)\n if n2 != n:\n raise ValueError, \"list of cases must be same length as list of conditions\"\n- choicelist.insert(0,default) \n+ choicelist.insert(0, default) \n S = 0\n pfac = 1\n- for k in range(1,n+1):\n+ for k in range(1, n+1):\n S += k * pfac * asarray(condlist[k-1])\n if k < n:\n pfac *= (1-asarray(condlist[k-1]))\n@@ -308,8 +318,8 @@ def select(condlist, choicelist, default=0):\n S = S*ones(asarray(pfac).shape)\n return choose(S, tuple(choicelist))\n \n-def _asarray1d(arr,copy=False):\n- \"\"\"Ensure 1d array for one array.\n+def _asarray1d(arr, copy=False):\n+ \"\"\"Ensure 1D array for one array.\n \"\"\"\n if copy:\n return asarray(arr).flatten()\n@@ -317,42 +327,42 @@ def _asarray1d(arr,copy=False):\n return asarray(arr).ravel()\n \n def copy(a):\n- \"\"\"Return an array copy of the object.\n+ \"\"\"Return an array copy of the given object.\n \"\"\"\n- return array(a,copy=True)\n+ return array(a, copy=True)\n \n # Basic operations\n-def amax(m,axis=-1): \n- \"\"\"Returns the maximum of m along dimension axis. \n+def amax(a, axis=-1): \n+ \"\"\"Return the maximum of 'a' along dimension axis. \n \"\"\"\n- return asarray(m).max(axis)\n+ return asarray(a).max(axis)\n \n-def amin(m,axis=-1):\n- \"\"\"Returns the minimum of m along dimension axis.\n+def amin(a, axis=-1):\n+ \"\"\"Return the minimum of a along dimension axis.\n \"\"\"\n- return asarray(m).min(axis)\n+ return asarray(a).min(axis)\n \n-def alen(m):\n- \"\"\"Returns the length of a Python object interpreted as an array\n+def alen(a):\n+ \"\"\"Return the length of a Python object interpreted as an array\n \"\"\"\n- return len(asarray(m))\n+ return len(asarray(a))\n \n-def ptp(m,axis=-1):\n- \"\"\"Returns the maximum - minimum along the the given dimension\n+def ptp(a, axis=-1):\n+ \"\"\"Return maximum - minimum along the the given dimension\n \"\"\"\n- return asarray(m).ptp(axis)\n+ return asarray(a).ptp(axis)\n \n-def prod(m,axis=-1):\n- \"\"\"Returns the product of the elements along the given axis\n+def prod(a, axis=-1):\n+ \"\"\"Return the product of the elements along the given axis\n \"\"\"\n- return asarray(m).prod(axis)\n+ return asarray(a).prod(axis)\n \n-def cumprod(m,axis=-1):\n- \"\"\"Returns the cumulative product of the elments along the given axis\n+def cumprod(a, axis=-1):\n+ \"\"\"Return the cumulative product of the elments along the given axis\n \"\"\"\n- return asarray(m).cumprod(axis)\n+ return asarray(a).cumprod(axis)\n \n-def gradient(f,*varargs):\n+def gradient(f, *varargs):\n \"\"\"Calculate the gradient of an N-dimensional scalar function.\n \n Uses central differences on the interior and first differences on boundaries\n@@ -385,32 +395,32 @@ def gradient(f,*varargs):\n print dx\n outvals = []\n \n- # create slice objects --- initially all are [:,:,...,:]\n+ # create slice objects --- initially all are [:, :, ..., :]\n slice1 = [slice(None)]*N\n slice2 = [slice(None)]*N\n slice3 = [slice(None)]*N\n \n otype = f.dtypechar\n- if otype not in ['f','d','F','D']:\n+ if otype not in ['f', 'd', 'F', 'D']:\n otype = 'd'\n \n for axis in range(N):\n # select out appropriate parts for this dimension\n out = zeros(f.shape, f.dtypechar)\n- slice1[axis] = slice(1,-1)\n- slice2[axis] = slice(2,None)\n- slice3[axis] = slice(None,-2)\n- # 1d equivalent -- out[1:-1] = (f[2:] - f[:-2])/2.0\n+ slice1[axis] = slice(1, -1)\n+ slice2[axis] = slice(2, None)\n+ slice3[axis] = slice(None, -2)\n+ # 1D equivalent -- out[1:-1] = (f[2:] - f[:-2])/2.0\n out[slice1] = (f[slice2] - f[slice3])/2.0 \n slice1[axis] = 0\n slice2[axis] = 1\n slice3[axis] = 0\n- # 1d equivalent -- out[0] = (f[1] - f[0])\n+ # 1D equivalent -- out[0] = (f[1] - f[0])\n out[slice1] = (f[slice2] - f[slice3])\n slice1[axis] = -1\n slice2[axis] = -1\n slice3[axis] = -2\n- # 1d equivalent -- out[-1] = (f[-1] - f[-2])\n+ # 1D equivalent -- out[-1] = (f[-1] - f[-2])\n out[slice1] = (f[slice2] - f[slice3])\n \n # divide by step size\n@@ -427,28 +437,29 @@ def gradient(f,*varargs):\n return outvals\n \n \n-def diff(x, n=1,axis=-1):\n- \"\"\"Calculates the nth order, discrete difference along given axis.\n+def diff(a, n=1, axis=-1):\n+ \"\"\"Calculate the nth order discrete difference along given axis.\n \"\"\"\n if n==0:\n- return x\n+ return a\n if n<0:\n- raise ValueError,'Order must be non-negative but got ' + `n`\n- x = asarray(x)\n- nd = len(x.shape)\n+ raise ValueError, 'order must be non-negative but got ' + `n`\n+ a = asarray(a)\n+ nd = len(a.shape)\n slice1 = [slice(None)]*nd\n slice2 = [slice(None)]*nd\n- slice1[axis] = slice(1,None)\n- slice2[axis] = slice(None,-1)\n+ slice1[axis] = slice(1, None)\n+ slice2[axis] = slice(None, -1)\n slice1 = tuple(slice1)\n slice2 = tuple(slice2)\n if n > 1:\n- return diff(x[slice1]-x[slice2], n-1, axis=axis)\n+ return diff(a[slice1]-a[slice2], n-1, axis=axis)\n else:\n- return x[slice1]-x[slice2]\n+ return a[slice1]-a[slice2]\n \n-def angle(z,deg=0):\n- \"\"\"Return the angle of complex argument z.\"\"\"\n+def angle(z, deg=0):\n+ \"\"\"Return the angle of the complex argument z.\n+ \"\"\"\n if deg:\n fact = 180/pi\n else:\n@@ -460,30 +471,30 @@ def angle(z,deg=0):\n else:\n zimag = 0\n zreal = z\n- return arctan2(zimag,zreal) * fact\n+ return arctan2(zimag, zreal) * fact\n \n-def unwrap(p,discont=pi,axis=-1):\n- \"\"\"unwraps radian phase p by changing absolute jumps greater than\n- discont to their 2*pi complement along the given axis.\n+def unwrap(p, discont=pi, axis=-1):\n+ \"\"\"Unwrap radian phase p by changing absolute jumps greater than\n+ 'discont' to their 2*pi complement along the given axis.\n \"\"\"\n p = asarray(p)\n nd = len(p.shape)\n- dd = diff(p,axis=axis)\n- slice1 = [slice(None,None)]*nd # full slices\n- slice1[axis] = slice(1,None)\n- ddmod = mod(dd+pi,2*pi)-pi\n- _nx.putmask(ddmod,(ddmod==-pi) & (dd > 0),pi)\n+ dd = diff(p, axis=axis)\n+ slice1 = [slice(None, None)]*nd # full slices\n+ slice1[axis] = slice(1, None)\n+ ddmod = mod(dd+pi, 2*pi)-pi\n+ _nx.putmask(ddmod, (ddmod==-pi) & (dd > 0), pi)\n ph_correct = ddmod - dd;\n- _nx.putmask(ph_correct,abs(dd)>> import scipy\n- >>> a = array((0,0,0,1,2,3,2,1,0))\n- >>> scipy.trim_zeros(a)\n- array([1, 2, 3, 2, 1])\n+ Example:\n+ >>> import scipy\n+ >>> a = array((0, 0, 0, 1, 2, 3, 2, 1, 0))\n+ >>> scipy.trim_zeros(a)\n+ array([1, 2, 3, 2, 1])\n \"\"\"\n first = 0\n trim = trim.upper()\n@@ -519,7 +530,7 @@ def trim_zeros(filt,trim='fb'):\n return filt[first:last]\n \n def unique(inseq):\n- \"\"\"Returns unique items in 1-dimensional sequence.\n+ \"\"\"Return unique items from a 1-dimensional sequence.\n \"\"\"\n # Dictionary setting is quite fast.\n set = {}\n@@ -528,60 +539,63 @@ def unique(inseq):\n return asarray(set.keys())\n \n def extract(condition, arr):\n- \"\"\"Elements of ravel(arr) where ravel(condition) is true (1-d)\n+ \"\"\"Return the elements of ravel(arr) where ravel(condition) is True\n+ (in 1D).\n \n- Equivalent of compress(ravel(condition), ravel(arr))\n+ Equivalent to compress(ravel(condition), ravel(arr)).\n \"\"\"\n return _nx.take(ravel(arr), nonzero(ravel(condition)))\n \n def insert(arr, mask, vals):\n- \"\"\"Similar to putmask arr[mask] = vals but 1d array vals has the\n- same number of elements as the non-zero values of mask. Inverse of extract.\n+ \"\"\"Similar to putmask arr[mask] = vals but the 1D array vals has the\n+ same number of elements as the non-zero values of mask. Inverse of\n+ extract.\n \"\"\"\n return _nx._insert(arr, mask, vals)\n \n-def nansum(x,axis=-1):\n- \"\"\"Sum the array over the given axis treating nans as 0\n+def nansum(a, axis=-1):\n+ \"\"\"Sum the array over the given axis, treating NaNs as 0.\n \"\"\"\n- y = array(x)\n+ y = array(a)\n if not issubclass(y.dtype, _nx.integer):\n- y[isnan(x)] = 0\n+ y[isnan(a)] = 0\n return y.sum(axis)\n \n-def nanmin(x,axis=-1):\n- \"\"\"Find the minimium over the given axis ignoring nans.\n+def nanmin(a, axis=-1):\n+ \"\"\"Find the minimium over the given axis, ignoring NaNs.\n \"\"\"\n- y = array(x)\n+ y = array(a)\n if not issubclass(y.dtype, _nx.integer):\n- y[isnan(x)] = _nx.inf\n+ y[isnan(a)] = _nx.inf\n return y.min(axis)\n \n-def nanargmin(x,axis=-1):\n- \"\"\"Find the indices of the minimium over the given axis ignoring nans.\n+def nanargmin(a, axis=-1):\n+ \"\"\"Find the indices of the minimium over the given axis ignoring NaNs.\n \"\"\"\n- y = array(x)\n+ y = array(a)\n if not issubclass(y.dtype, _nx.integer):\n- y[isnan(x)] = _nx.inf \n+ y[isnan(a)] = _nx.inf \n return y.argmin(axis) \n \n-def nanmax(x,axis=-1):\n- \"\"\"Find the maximum over the given axis ignoring nans.\n+def nanmax(a, axis=-1):\n+ \"\"\"Find the maximum over the given axis ignoring NaNs.\n \"\"\"\n- y = array(x)\n+ y = array(a)\n if not issubclass(y.dtype, _nx.integer):\n- y[isnan(x)] = -_nx.inf \n+ y[isnan(a)] = -_nx.inf \n return y.max(axis) \n \n-def nanargmax(x,axis=-1):\n- \"\"\"Find the maximum over the given axis ignoring nans.\n+def nanargmax(a, axis=-1):\n+ \"\"\"Find the maximum over the given axis ignoring NaNs.\n \"\"\"\n- y = array(x)\n+ y = array(a)\n if not issubclass(y.dtype, _nx.integer):\n- y[isnan(x)] = -_nx.inf \n+ y[isnan(a)] = -_nx.inf \n return y.argmax(axis) \n \n-def disp(mesg, device=None, linefeed=1):\n- \"\"\"Display a message to device (default is sys.stdout) with(out) linefeed.\n+def disp(mesg, device=None, linefeed=True):\n+ \"\"\"Display a message to the given device (default is sys.stdout)\n+ with or without a linefeed.\n \"\"\"\n if device is None:\n import sys\n@@ -612,7 +626,7 @@ class vectorize:\n \n Example:\n \n- def myfunc(a,b):\n+ def myfunc(a, b):\n if a > b:\n return a-b\n else\n@@ -620,11 +634,11 @@ def myfunc(a,b):\n \n vfunc = vectorize(myfunc)\n \n- >>> vfunc([1,2,3,4],2)\n- array([3,4,1,2])\n+ >>> vfunc([1, 2, 3, 4], 2)\n+ array([3, 4, 1, 2])\n \n \"\"\"\n- def __init__(self,pyfunc,otypes='',doc=None):\n+ def __init__(self, pyfunc, otypes='', doc=None):\n try:\n fcode = pyfunc.func_code\n except AttributeError:\n@@ -638,7 +652,7 @@ def __init__(self,pyfunc,otypes='',doc=None):\n self.__doc__ = pyfunc.__doc__\n else:\n self.__doc__ = doc\n- if isinstance(otypes,types.StringType):\n+ if isinstance(otypes, types.StringType):\n self.otypes=otypes\n else:\n raise ValueError, \"output types must be a string\"\n@@ -646,7 +660,7 @@ def __init__(self,pyfunc,otypes='',doc=None):\n if char not in typecodes['All']:\n raise ValueError, \"invalid typecode specified\"\n \n- def __call__(self,*args):\n+ def __call__(self, *args):\n # get number of outputs and output types by calling\n # the function on the first entries of args\n if len(args) != self.nin:\n@@ -674,33 +688,33 @@ def __call__(self,*args):\n if self.nout == 1:\n return self.ufunc(*args).astype(self.otypes[0])\n else:\n- return tuple([x.astype(c) for x,c in zip(self.ufunc(*args), self.otypes)])\n+ return tuple([x.astype(c) for x, c in zip(self.ufunc(*args), self.otypes)])\n \n \n-def round_(x, decimals=0):\n- \"\"\"round_(m, decimals=0) Rounds x to decimals places.\n+def round_(a, decimals=0):\n+ \"\"\"Round 'a' to the given number of decimal places. Rounding\n+ behaviour is equivalent to Python.\n \n- Returns x if array is not floating point and rounds both the real\n- and imaginary parts separately if array is complex. Rounds in the\n- same way as standard Python.\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- x = asarray(x)\n- if not issubclass(x.dtype, _nx.inexact):\n- return x\n- if issubclass(x.dtype, _nx.complexfloating):\n- return round_(x.real, decimals) + 1j*round_(x.imag, decimals)\n+ a = asarray(a)\n+ if not issubclass(a.dtype, _nx.inexact):\n+ return a\n+ if issubclass(a.dtype, _nx.complexfloating):\n+ return round_(a.real, decimals) + 1j*round_(a.imag, decimals)\n if decimals is not 0:\n decimals = asarray(decimals)\n- s = sign(x)\n+ s = sign(a)\n if decimals is not 0:\n- x = absolute(multiply(x,10.**decimals))\n+ a = absolute(multiply(a, 10.**decimals))\n else:\n- x = absolute(x)\n- rem = x-asarray(x).astype(_nx.intp)\n- x = _nx.where(_nx.less(rem,0.5), _nx.floor(x), _nx.ceil(x))\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(x,s/(10.**decimals))\n+ return multiply(a, s/(10.**decimals))\n else:\n- return multiply(x,s)\n+ return multiply(a, s)\n \n", "added_lines": 194, "deleted_lines": 180, "source_code": "import types\nimport math, operator\nimport numeric as _nx\nfrom numeric import ones, zeros, arange, concatenate, array, asarray, empty\nfrom numeric import ScalarType\nfrom umath import pi, multiply, add, arctan2, maximum, minimum, frompyfunc, \\\n isnan, absolute\nfrom oldnumeric import ravel, nonzero, choose, \\\n sometrue, alltrue, reshape, any, all, typecodes, ArrayType\nfrom type_check import ScalarType, isscalar\nfrom shape_base import squeeze, atleast_1d\nfrom _compiled_base import digitize, bincount, _insert\nfrom ufunclike import sign\n\n__all__ = ['logspace', 'linspace', 'round_',\n 'select', 'piecewise', 'trim_zeros', 'alen', 'amax', 'amin', 'ptp',\n 'copy', 'iterable', 'base_repr', 'binary_repr', 'prod', 'cumprod',\n 'diff', 'gradient', 'angle', 'unwrap', 'sort_complex', 'disp',\n 'unique', 'extract', 'insert', 'nansum', 'nanmax', 'nanargmax',\n 'nanargmin', 'nanmin', 'vectorize', 'asarray_chkfinite', 'average',\n 'histogram', 'bincount', 'digitize']\n\n_lkup = {'0':'000',\n '1':'001',\n '2':'010',\n '3':'011',\n '4':'100',\n '5':'101',\n '6':'110',\n '7':'111',\n 'L':''}\n\ndef binary_repr(num):\n \"\"\"Return the binary representation of the input number as a string.\n\n This is equivalent to using base_repr with base 2, but about 25x\n faster.\n \"\"\"\n ostr = oct(num)\n bin = ''\n for ch in ostr[1:]:\n bin += _lkup[ch]\n ind = 0\n while bin[ind] == '0':\n ind += 1\n return bin[ind:]\n\ndef base_repr (number, base=2, padding=0):\n \"\"\"Return the representation of a number in any given base.\n \"\"\"\n chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'\n\n lnb = math.log(base)\n res = padding*chars[0]\n if number == 0:\n return res + chars[0]\n exponent = int (math.log (number)/lnb)\n while(exponent >= 0):\n term = long(base)**exponent\n lead_digit = int(number / term)\n res += chars[lead_digit]\n number -= term*lead_digit\n exponent -= 1\n return res\n#end Fernando's utilities\n\n\n\ndef logspace(start, stop, num=50, endpoint=True):\n \"\"\" Return evenly spaced samples on a logarithmic scale.\n\n Return 'num' evenly spaced samples from 10**start to 10**stop.\n If 'endpoint' is True then the last sample is 10**stop.\n \"\"\"\n if num <= 0: return array([])\n if endpoint:\n step = (stop-start)/float((num-1))\n y = _nx.arange(0, num) * step + start\n else:\n step = (stop-start)/float(num)\n y = _nx.arange(0, num) * step + start\n return _nx.power(10.0, y)\n\ndef linspace(start, stop, num=50, endpoint=True, retstep=False):\n \"\"\" Return 'num' evenly spaced samples from 'start' to 'stop'. If\n 'endpoint' is True, the last sample is 'stop'. If 'retstep' is\n True then return the step value used.\n \"\"\"\n if num <= 0: return array([])\n if endpoint:\n step = (stop-start)/float((num-1))\n y = _nx.arange(0, num) * step + start \n else:\n step = (stop-start)/float(num)\n y = _nx.arange(0, num) * step + start\n if retstep:\n return y, step\n else:\n return y\n\ndef iterable(y):\n try: iter(y)\n except: return 0\n return 1\n\ndef histogram(a, bins=10, range=None, normed=False):\n a = asarray(a).ravel()\n if not iterable(bins):\n if range is None:\n range = (a.min(), a.max())\n mn, mx = [a+0.0 for a in range]\n if mn == mx:\n mn -= 0.5\n mx += 0.5\n bins = linspace(mn, mx, bins)\n\n n = a.sort().searchsorted(bins)\n n = concatenate([n, [len(a)]])\n n = n[1:]-n[:-1]\n\n if normed:\n db = bins[1] - bins[0]\n return 1.0/(a.size*db) * n, bins\n else:\n return n, bins\n\ndef average(a, axis=0, weights=None, returned=False):\n \"\"\"average(a, axis=0, weights=None, returned=False)\n\n Compute average over the given axis. If axis is None, average \n over all dimensions of the array. Equivalent to a.mean(axis), \n but with a default axis of 0 instead of None.\n\n The average of an integer or floating-point array always has type\n Float. \n \n If an integer axis is given, this equals:\n a.sum(axis) * 1.0 / len(a)\n \n If axis is None, this equals:\n a.sum(axis) * 1.0 / product(a.shape)\n\n If weights are given, result is:\n sum(a * weights) / sum(weights),\n where the weights must have a's shape or be 1D with length the \n size of a in the given axis. Integer weights are converted to \n Float. Not specifying weights is equivalent to specifying \n weights that are all 1.\n\n If 'returned' is True, return a tuple: the result and the sum of\n the weights or count of values. The shape of these two results\n will be the same.\n\n Raises ZeroDivisionError if appropriate. (The version in MA does\n not -- it returns masked values).\n \"\"\"\n if axis is None:\n a = array(a).ravel()\n if weights is None:\n n = add.reduce(a)\n d = len(a) * 1.0\n else:\n w = array(weights).ravel() * 1.0\n n = add.reduce(multiply(a, w))\n d = add.reduce(w) \n else:\n a = array(a)\n ash = a.shape\n if ash == ():\n a.shape = (1,)\n if weights is None:\n n = add.reduce(a, axis) \n d = ash[axis] * 1.0\n if returned:\n d = ones(shape(n)) * d\n else:\n w = array(weights, copy=False) * 1.0\n wsh = w.shape\n if wsh == ():\n wsh = (1,)\n if wsh == ash:\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis) \n elif wsh == (ash[axis],):\n ni = ash[axis]\n r = [newaxis]*ni\n r[axis] = slice(None, None, 1)\n w1 = eval(\"w[\"+repr(tuple(r))+\"]*ones(ash, Float)\")\n n = add.reduce(a*w1, axis)\n d = add.reduce(w1, axis)\n else:\n raise ValueError, 'averaging weights have wrong shape'\n \n if not isinstance(d, ArrayType):\n if d == 0.0: \n raise ZeroDivisionError, 'zero denominator in average()'\n if returned:\n return n/d, d\n else:\n return n/d\n\n\ndef isaltered():\n val = str(type(_nx.array([1])))\n return 'scipy' in val\n\n\ndef asarray_chkfinite(a):\n \"\"\"Like asarray, but check that no NaNs or Infs are present.\n \"\"\"\n a = asarray(a)\n if (a.dtypechar in _nx.typecodes['AllFloat']) \\\n and (_nx.isnan(a).any() or _nx.isinf(a).any()):\n raise ValueError, \"array must not contain infs or NaNs\"\n return a \n\n\n\n\ndef piecewise(x, condlist, funclist, *args, **kw):\n \"\"\"Return a piecewise-defined function.\n\n x is the domain\n\n condlist is a list of boolean arrays or a single boolean array\n The length of the condition list must be n2 or n2-1 where n2\n is the length of the function list. If len(condlist)==n2-1, then\n an 'otherwise' condition is formed by |'ing all the conditions\n and inverting. \n\n funclist is a list of functions to call of length (n2).\n Each function should return an array output for an array input\n Each function can take (the same set) of extra arguments and\n keyword arguments which are passed in after the function list.\n\n The output is the same shape and type as x and is found by\n calling the functions on the appropriate portions of x.\n\n Note: This is similar to choose or select, except\n the the functions are only evaluated on elements of x\n that satisfy the corresponding condition.\n\n The result is\n |--\n | f1(x) for condition1\n y = --| f2(x) for condition2\n | ...\n | fn(x) for conditionn\n |--\n \n \"\"\"\n n2 = len(funclist)\n if not isinstance(condlist, type([])):\n condlist = [condlist]\n n = len(condlist)\n if n == n2-1: # compute the \"otherwise\" condition.\n totlist = condlist[0]\n for k in range(1, n):\n totlist |= condlist\n condlist.append(~totlist)\n n += 1\n if (n != n2):\n raise ValueError, \"function list and condition list must be the same\"\n y = empty(x.shape, x.dtype)\n for k in range(n):\n item = funclist[k]\n if not callable(item):\n y[condlist[k]] = item\n else:\n y[condlist[k]] = item(x[condlist[k]], *args, **kw)\n return y\n\ndef select(condlist, choicelist, default=0):\n \"\"\" Return an array composed of different elements of choicelist\n depending on the list of conditions.\n\n condlist is a list of condition arrays containing ones or zeros\n \n choicelist is a list of choice arrays (of the \"same\" size as the\n arrays in condlist). The result array has the \"same\" size as the\n arrays in choicelist. If condlist is [c0, ..., cN-1] then choicelist\n must be of length N. The elements of the choicelist can then be\n represented as [v0, ..., vN-1]. The default choice if none of the\n conditions are met is given as the default argument. \n \n The conditions are tested in order and the first one statisfied is\n used to select the choice. In other words, the elements of the\n output array are found from the following tree (notice the order of\n the conditions matters):\n \n if c0: v0\n elif c1: v1\n elif c2: v2\n ...\n elif cN-1: vN-1\n else: default\n \n Note that one of the condition arrays must be large enough to handle\n the largest array in the choice list.\n \"\"\"\n n = len(condlist)\n n2 = len(choicelist)\n if n2 != n:\n raise ValueError, \"list of cases must be same length as list of conditions\"\n choicelist.insert(0, default) \n S = 0\n pfac = 1\n for k in range(1, n+1):\n S += k * pfac * asarray(condlist[k-1])\n if k < n:\n pfac *= (1-asarray(condlist[k-1]))\n # handle special case of a 1-element condition but\n # a multi-element choice\n if type(S) in ScalarType or max(asarray(S).shape)==1:\n pfac = asarray(1)\n for k in range(n2+1):\n pfac = pfac + asarray(choicelist[k]) \n S = S*ones(asarray(pfac).shape)\n return choose(S, tuple(choicelist))\n\ndef _asarray1d(arr, copy=False):\n \"\"\"Ensure 1D array for one array.\n \"\"\"\n if copy:\n return asarray(arr).flatten()\n else:\n return asarray(arr).ravel()\n\ndef copy(a):\n \"\"\"Return an array copy of the given object.\n \"\"\"\n return array(a, copy=True)\n \n# Basic operations\ndef amax(a, axis=-1): \n \"\"\"Return the maximum of 'a' along dimension axis. \n \"\"\"\n return asarray(a).max(axis)\n\ndef amin(a, axis=-1):\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 ptp(a, axis=-1):\n \"\"\"Return maximum - minimum along the the given dimension\n \"\"\"\n return asarray(a).ptp(axis)\n\ndef prod(a, axis=-1):\n \"\"\"Return the product of the elements along the given axis\n \"\"\"\n return asarray(a).prod(axis)\n\ndef cumprod(a, axis=-1):\n \"\"\"Return the cumulative product of the elments along the given axis\n \"\"\"\n return asarray(a).cumprod(axis)\n\ndef gradient(f, *varargs):\n \"\"\"Calculate the gradient of an N-dimensional scalar function.\n\n Uses central differences on the interior and first differences on boundaries\n to give the same shape.\n\n Inputs:\n\n f -- An N-dimensional array giving samples of a scalar function\n\n varargs -- 0, 1, or N scalars giving the sample distances in each direction\n\n Outputs:\n\n N arrays of the same shape as f giving the derivative of f with respect\n to each dimension.\n \"\"\"\n N = len(f.shape) # number of dimensions\n n = len(varargs)\n if n==0:\n dx = [1.0]*N\n elif n==1:\n dx = [varargs[0]]*N\n elif n==N:\n dx = list(varargs)\n else:\n raise SyntaxError, \"invalid number of arguments\"\n\n # use central differences on interior and first differences on endpoints\n\n print dx\n outvals = []\n\n # create slice objects --- initially all are [:, :, ..., :]\n slice1 = [slice(None)]*N\n slice2 = [slice(None)]*N\n slice3 = [slice(None)]*N\n\n otype = f.dtypechar\n if otype not in ['f', 'd', 'F', 'D']:\n otype = 'd'\n\n for axis in range(N):\n # select out appropriate parts for this dimension\n out = zeros(f.shape, f.dtypechar)\n slice1[axis] = slice(1, -1)\n slice2[axis] = slice(2, None)\n slice3[axis] = slice(None, -2)\n # 1D equivalent -- out[1:-1] = (f[2:] - f[:-2])/2.0\n out[slice1] = (f[slice2] - f[slice3])/2.0 \n slice1[axis] = 0\n slice2[axis] = 1\n slice3[axis] = 0\n # 1D equivalent -- out[0] = (f[1] - f[0])\n out[slice1] = (f[slice2] - f[slice3])\n slice1[axis] = -1\n slice2[axis] = -1\n slice3[axis] = -2\n # 1D equivalent -- out[-1] = (f[-1] - f[-2])\n out[slice1] = (f[slice2] - f[slice3])\n \n # divide by step size\n outvals.append(out / dx[axis])\n \n # reset the slice object in this dimension to \":\"\n slice1[axis] = slice(None)\n slice2[axis] = slice(None)\n slice3[axis] = slice(None)\n\n if N == 1:\n return outvals[0]\n else:\n return outvals\n \n\ndef diff(a, n=1, axis=-1):\n \"\"\"Calculate the nth order discrete difference along given axis.\n \"\"\"\n if n==0:\n return a\n if n<0:\n raise ValueError, 'order must be non-negative but got ' + `n`\n a = asarray(a)\n nd = len(a.shape)\n slice1 = [slice(None)]*nd\n slice2 = [slice(None)]*nd\n slice1[axis] = slice(1, None)\n slice2[axis] = slice(None, -1)\n slice1 = tuple(slice1)\n slice2 = tuple(slice2)\n if n > 1:\n return diff(a[slice1]-a[slice2], n-1, axis=axis)\n else:\n return a[slice1]-a[slice2]\n \ndef angle(z, deg=0):\n \"\"\"Return the angle of the complex argument z.\n \"\"\"\n if deg:\n fact = 180/pi\n else:\n fact = 1.0\n z = asarray(z)\n if (issubclass(z.dtype, _nx.complexfloating)):\n zimag = z.imag\n zreal = z.real\n else:\n zimag = 0\n zreal = z\n return arctan2(zimag, zreal) * fact\n\ndef unwrap(p, discont=pi, axis=-1):\n \"\"\"Unwrap radian phase p by changing absolute jumps greater than\n 'discont' to their 2*pi complement along the given axis.\n \"\"\"\n p = asarray(p)\n nd = len(p.shape)\n dd = diff(p, axis=axis)\n slice1 = [slice(None, None)]*nd # full slices\n slice1[axis] = slice(1, None)\n ddmod = mod(dd+pi, 2*pi)-pi\n _nx.putmask(ddmod, (ddmod==-pi) & (dd > 0), pi)\n ph_correct = ddmod - dd;\n _nx.putmask(ph_correct, abs(dd)>> import scipy\n >>> a = array((0, 0, 0, 1, 2, 3, 2, 1, 0))\n >>> scipy.trim_zeros(a)\n array([1, 2, 3, 2, 1])\n \"\"\"\n first = 0\n trim = trim.upper()\n if 'F' in trim:\n for i in filt:\n if i != 0.: break\n else: first = first + 1\n last = len(filt)\n if 'B' in trim:\n for i in filt[::-1]:\n if i != 0.: break\n else: last = last - 1\n return filt[first:last]\n\ndef unique(inseq):\n \"\"\"Return unique items from a 1-dimensional sequence.\n \"\"\"\n # Dictionary setting is quite fast.\n set = {}\n for item in inseq:\n set[item] = None\n return asarray(set.keys())\n \ndef extract(condition, arr):\n \"\"\"Return the elements of ravel(arr) where ravel(condition) is True\n (in 1D).\n\n Equivalent to compress(ravel(condition), ravel(arr)).\n \"\"\"\n return _nx.take(ravel(arr), nonzero(ravel(condition)))\n\ndef insert(arr, mask, vals):\n \"\"\"Similar to putmask arr[mask] = vals but the 1D array vals has the\n same number of elements as the non-zero values of mask. Inverse of\n extract.\n \"\"\"\n return _nx._insert(arr, mask, vals)\n\ndef nansum(a, axis=-1):\n \"\"\"Sum the array over the given axis, treating NaNs as 0.\n \"\"\"\n y = array(a)\n if not issubclass(y.dtype, _nx.integer):\n y[isnan(a)] = 0\n return y.sum(axis)\n\ndef nanmin(a, axis=-1):\n \"\"\"Find the minimium over the given axis, ignoring NaNs.\n \"\"\"\n y = array(a)\n if not issubclass(y.dtype, _nx.integer):\n y[isnan(a)] = _nx.inf\n return y.min(axis)\n\ndef nanargmin(a, axis=-1):\n \"\"\"Find the indices of the minimium over the given axis ignoring NaNs.\n \"\"\"\n y = array(a)\n if not issubclass(y.dtype, _nx.integer):\n y[isnan(a)] = _nx.inf \n return y.argmin(axis) \n\ndef nanmax(a, axis=-1):\n \"\"\"Find the maximum over the given axis ignoring NaNs.\n \"\"\"\n y = array(a)\n if not issubclass(y.dtype, _nx.integer):\n y[isnan(a)] = -_nx.inf \n return y.max(axis) \n\ndef nanargmax(a, axis=-1):\n \"\"\"Find the maximum over the given axis ignoring NaNs.\n \"\"\"\n y = array(a)\n if not issubclass(y.dtype, _nx.integer):\n y[isnan(a)] = -_nx.inf \n return y.argmax(axis) \n\ndef disp(mesg, device=None, linefeed=True):\n \"\"\"Display a message to the given device (default is sys.stdout)\n with or without a linefeed.\n \"\"\"\n if device is None:\n import sys\n device = sys.stdout\n if linefeed:\n device.write('%s\\n' % mesg)\n else:\n device.write('%s' % mesg)\n device.flush()\n return\n\nclass vectorize:\n \"\"\"\n vectorize(somefunction, otypes=None, doc=None)\n Generalized Function class.\n\n Description:\n \n Define a vectorized function which takes nested sequence\n objects or scipy arrays as inputs and returns a\n scipy array as output, evaluating the function over successive\n tuples of the input arrays like the python map function except it uses\n the broadcasting rules of scipy. \n\n Input:\n\n somefunction -- a Python function or method\n\n Example:\n\n def myfunc(a, b):\n if a > b:\n return a-b\n else\n return a+b\n\n vfunc = vectorize(myfunc)\n\n >>> vfunc([1, 2, 3, 4], 2)\n array([3, 4, 1, 2])\n\n \"\"\"\n def __init__(self, pyfunc, otypes='', doc=None):\n try:\n fcode = pyfunc.func_code\n except AttributeError:\n raise TypeError, \"object is not a callable Python object\"\n\n self.thefunc = pyfunc\n self.ufunc = None\n self.nin = len(fcode.co_varnames)\n self.nout = None\n if doc is None:\n self.__doc__ = pyfunc.__doc__\n else:\n self.__doc__ = doc\n if isinstance(otypes, types.StringType):\n self.otypes=otypes\n else:\n raise ValueError, \"output types must be a string\"\n for char in self.otypes:\n if char not in typecodes['All']:\n raise ValueError, \"invalid typecode specified\"\n\n def __call__(self, *args):\n # get number of outputs and output types by calling\n # the function on the first entries of args\n if len(args) != self.nin:\n raise ValueError, \"mismatch between python function inputs\"\\\n \" and received arguments\"\n if self.nout is None or self.otypes == '':\n newargs = []\n for arg in args:\n newargs.append(asarray(arg).flat[0])\n theout = self.thefunc(*newargs)\n if isinstance(theout, types.TupleType):\n self.nout = len(theout)\n else:\n self.nout = 1\n theout = (theout,)\n if self.otypes == '':\n otypes = []\n for k in range(self.nout):\n otypes.append(asarray(theout[k]).dtypechar)\n self.otypes = ''.join(otypes)\n\n if self.ufunc is None:\n self.ufunc = frompyfunc(self.thefunc, self.nin, self.nout)\n\n if self.nout == 1:\n return self.ufunc(*args).astype(self.otypes[0])\n else:\n return tuple([x.astype(c) for x, c in zip(self.ufunc(*args), self.otypes)])\n\n\ndef round_(a, decimals=0):\n \"\"\"Round 'a' to the given number of decimal places. Rounding\n behaviour is equivalent to Python.\n\n Return 'a' if the array is not floating point. Round both the real\n and imaginary parts separately if the array is complex.\n \"\"\"\n a = asarray(a)\n if not issubclass(a.dtype, _nx.inexact):\n return a\n if issubclass(a.dtype, _nx.complexfloating):\n return round_(a.real, decimals) + 1j*round_(a.imag, decimals)\n if decimals is not 0:\n decimals = asarray(decimals)\n s = sign(a)\n if decimals is not 0:\n a = absolute(multiply(a, 10.**decimals))\n else:\n a = absolute(a)\n rem = a-asarray(a).astype(_nx.intp)\n a = _nx.where(_nx.less(rem, 0.5), _nx.floor(a), _nx.ceil(a))\n # convert back\n if decimals is not 0:\n return multiply(a, s/(10.**decimals))\n else:\n return multiply(a, s)\n\n", "source_code_before": "import types\nimport math, operator\nimport numeric as _nx\nfrom numeric import ones, zeros, arange, concatenate, array, asarray, empty\nfrom numeric import ScalarType\nfrom umath import pi, multiply, add, arctan2, maximum, minimum, frompyfunc, \\\n isnan, absolute\nfrom oldnumeric import ravel, nonzero, choose, \\\n sometrue, alltrue, reshape, any, all, typecodes, ArrayType\nfrom type_check import ScalarType, isscalar\nfrom shape_base import squeeze, atleast_1d\nfrom _compiled_base import digitize, bincount, _insert\nfrom ufunclike import sign\n\n__all__ = ['logspace','linspace', 'round_',\n 'select','piecewise','trim_zeros','alen','amax', 'amin', 'ptp',\n 'copy', 'iterable', 'base_repr', 'binary_repr', \n 'prod','cumprod', 'diff','gradient','angle','unwrap','sort_complex',\n 'disp','unique','extract','insert','nansum','nanmax','nanargmax',\n 'nanargmin','nanmin', 'vectorize','asarray_chkfinite',\n 'average','histogram','bincount','digitize']\n\n_lkup = {'0':'000',\n '1':'001',\n '2':'010',\n '3':'011',\n '4':'100',\n '5':'101',\n '6':'110',\n '7':'111',\n 'L':''}\n\ndef binary_repr(num):\n \"\"\"Return the binary representation of the input number as a string.\n\n This is abuut 25x faster than using base_repr with base 2.\n \"\"\"\n ostr = oct(num)\n bin = ''\n for ch in ostr[1:]:\n bin += _lkup[ch]\n ind = 0\n while bin[ind] == '0':\n ind += 1\n return bin[ind:]\n\ndef base_repr (number, base=2, padding=0):\n \"\"\"Return the representation of a number in any given base.\n \"\"\"\n chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'\n\n lnb = math.log(base)\n res = padding*chars[0]\n if number == 0:\n return res + chars[0]\n exponent = int (math.log (number)/lnb)\n while(exponent >= 0):\n term = long(base)**exponent\n lead_digit = int(number / term)\n res += chars[lead_digit]\n number -= term*lead_digit\n exponent -= 1\n return res\n#end Fernando's utilities\n\n\n\ndef logspace(start,stop,num=50,endpoint=1):\n \"\"\" Evenly spaced samples on a logarithmic scale.\n\n Return num evenly spaced samples from 10**start to 10**stop. If\n endpoint=1 then last sample is 10**stop.\n \"\"\"\n if num <= 0: return array([])\n if endpoint:\n step = (stop-start)/float((num-1))\n y = _nx.arange(0,num) * step + start\n else:\n step = (stop-start)/float(num)\n y = _nx.arange(0,num) * step + start\n return _nx.power(10.0,y)\n\ndef linspace(start,stop,num=50,endpoint=1,retstep=False):\n \"\"\" Evenly spaced samples.\n \n Return num evenly spaced samples from start to stop. If endpoint=1 then\n last sample is stop. If retstep is true then return the step value used.\n \"\"\"\n if num <= 0: return array([])\n if endpoint:\n step = (stop-start)/float((num-1))\n y = _nx.arange(0,num) * step + start \n else:\n step = (stop-start)/float(num)\n y = _nx.arange(0,num) * step + start\n if retstep:\n return y, step\n else:\n return y\n\ndef iterable(y):\n try: iter(y)\n except: return 0\n return 1\n\ndef histogram(x, bins=10, range=None, normed=False):\n x = asarray(x).ravel()\n if not iterable(bins):\n if range is None:\n range = (x.min(), x.max())\n mn, mx = [x+0.0 for x in range]\n if mn == mx:\n mn -= 0.5\n mx += 0.5\n bins = linspace(mn, mx, bins)\n\n n = x.sort().searchsorted(bins)\n n = concatenate([n, [len(x)]])\n n = n[1:]-n[:-1]\n\n if normed:\n db = bins[1] - bins[0]\n return 1.0/(x.size*db) * n, bins\n else:\n return n, bins\n\ndef average(a, axis=0, weights=None, returned=0):\n \"\"\"average(a, axis=0, weights=None)\n Computes average along indicated axis. \n If axis is None, average over the entire array.\n Inputs can be integer or floating types; result is type Float.\n \n If weights are given, result is:\n sum(a*weights)/(sum(weights))\n weights must have a's shape or be the 1-d with length the size\n of a in the given axis. Integer weights are converted to Float.\n\n Not supplying weights is equivalent to supply weights that are\n all 1.\n\n If returned, return a tuple: the result and the sum of the weights \n or count of values. The shape of these two results will be the same.\n\n raises ZeroDivisionError if appropriate when result is scalar.\n (The version in MA does not -- it returns masked values).\n \"\"\"\n if axis is None:\n a = array(a).ravel()\n if weights is None:\n n = add.reduce(a)\n d = len(a) * 1.0\n else:\n w = array(weights).ravel() * 1.0\n n = add.reduce(multiply(a,w))\n d = add.reduce(w) \n else:\n a = array(a)\n ash = a.shape\n if ash == ():\n a.shape = (1,)\n if weights is None:\n n = add.reduce(a, axis) \n d = ash[axis] * 1.0\n if returned:\n d = ones(shape(n)) * d\n else:\n w = array(weights, copy=False) * 1.0\n wsh = w.shape\n if wsh == ():\n wsh = (1,)\n if wsh == ash:\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis) \n elif wsh == (ash[axis],):\n ni = ash[axis]\n r = [newaxis]*ni\n r[axis] = slice(None,None,1)\n w1 = eval(\"w[\"+repr(tuple(r))+\"]*ones(ash, Float)\")\n n = add.reduce(a*w1, axis)\n d = add.reduce(w1, axis)\n else:\n raise ValueError, 'average: weights wrong shape.'\n \n if not isinstance(d, ArrayType):\n if d == 0.0: \n raise ZeroDivisionError, 'Numeric.average, zero denominator'\n if returned:\n return n/d, d\n else:\n return n/d\n\n\ndef isaltered():\n val = str(type(_nx.array([1])))\n return 'scipy' in val\n\n\ndef asarray_chkfinite(x):\n \"\"\"Like asarray except it checks to be sure no NaNs or Infs are present.\n \"\"\"\n x = asarray(x)\n if (x.dtypechar in _nx.typecodes['AllFloat']) \\\n and (_nx.isnan(x).any() or _nx.isinf(x).any()):\n raise ValueError, \"array must not contain infs or nans\"\n return x \n\n\n\n\ndef piecewise(x, condlist, funclist, *args, **kw):\n \"\"\"Returns a piecewise-defined function.\n\n x is the domain\n\n condlist is a list of boolean arrays or a single boolean array\n The length of the condition list must be n2 or n2-1 where n2\n is the length of the function list. If len(condlist)==n2-1, then\n an 'otherwise' condition is formed by |'ing all the conditions\n and inverting. \n\n funclist is a list of functions to call of length (n2).\n Each function should return an array output for an array input\n Each function can take (the same set) of extra arguments and\n keyword arguments which are passed in after the function list.\n\n The output is the same shape and type as x and is found by\n calling the functions on the appropriate portions of x.\n\n Note: This is similar to choose or select, except\n the the functions are only evaluated on elements of x\n that satisfy the corresponding condition.\n\n The result is\n |--\n | f1(x) for condition1\n y = --| f2(x) for condition2\n | ...\n | fn(x) for conditionn\n |--\n \n \"\"\"\n n2 = len(funclist)\n if not isinstance(condlist, type([])):\n condlist = [condlist]\n n = len(condlist)\n if n == n2-1: # compute the \"otherwise\" condition.\n totlist = condlist[0]\n for k in range(1,n):\n totlist |= condlist\n condlist.append(~totlist)\n n += 1\n if (n != n2):\n raise ValueError, \"function list and condition list must be the same\"\n y = empty(x.shape, x.dtype)\n for k in range(n):\n item = funclist[k]\n if not callable(item):\n y[condlist[k]] = item\n else:\n y[condlist[k]] = item(x[condlist[k]], *args, **kw)\n return y\n\ndef select(condlist, choicelist, default=0):\n \"\"\" Returns an array comprised from different elements of choicelist\n depending on the list of conditions.\n\n condlist is a list of condition arrays containing ones or zeros\n \n choicelist is a list of choice arrays (of the \"same\" size as the\n arrays in condlist). The result array has the \"same\" size as the\n arrays in choicelist. If condlist is [c0,...,cN-1] then choicelist\n must be of length N. The elements of the choicelist can then be\n represented as [v0,...,vN-1]. The default choice if none of the\n conditions are met is given as the default argument. \n \n The conditions are tested in order and the first one statisfied is\n used to select the choice. In other words, the elements of the\n output array are found from the following tree (notice the order of\n the conditions matters):\n \n if c0: v0\n elif c1: v1\n elif c2: v2\n ...\n elif cN-1: vN-1\n else: default\n \n Note, that one of the condition arrays must be large enough to handle\n the largest array in the choice list.\n \"\"\"\n n = len(condlist)\n n2 = len(choicelist)\n if n2 != n:\n raise ValueError, \"list of cases must be same length as list of conditions\"\n choicelist.insert(0,default) \n S = 0\n pfac = 1\n for k in range(1,n+1):\n S += k * pfac * asarray(condlist[k-1])\n if k < n:\n pfac *= (1-asarray(condlist[k-1]))\n # handle special case of a 1-element condition but\n # a multi-element choice\n if type(S) in ScalarType or max(asarray(S).shape)==1:\n pfac = asarray(1)\n for k in range(n2+1):\n pfac = pfac + asarray(choicelist[k]) \n S = S*ones(asarray(pfac).shape)\n return choose(S, tuple(choicelist))\n\ndef _asarray1d(arr,copy=False):\n \"\"\"Ensure 1d array for one array.\n \"\"\"\n if copy:\n return asarray(arr).flatten()\n else:\n return asarray(arr).ravel()\n\ndef copy(a):\n \"\"\"Return an array copy of the object.\n \"\"\"\n return array(a,copy=True)\n \n# Basic operations\ndef amax(m,axis=-1): \n \"\"\"Returns the maximum of m along dimension axis. \n \"\"\"\n return asarray(m).max(axis)\n\ndef amin(m,axis=-1):\n \"\"\"Returns the minimum of m along dimension axis.\n \"\"\"\n return asarray(m).min(axis)\n\ndef alen(m):\n \"\"\"Returns the length of a Python object interpreted as an array\n \"\"\"\n return len(asarray(m))\n\ndef ptp(m,axis=-1):\n \"\"\"Returns the maximum - minimum along the the given dimension\n \"\"\"\n return asarray(m).ptp(axis)\n\ndef prod(m,axis=-1):\n \"\"\"Returns the product of the elements along the given axis\n \"\"\"\n return asarray(m).prod(axis)\n\ndef cumprod(m,axis=-1):\n \"\"\"Returns the cumulative product of the elments along the given axis\n \"\"\"\n return asarray(m).cumprod(axis)\n\ndef gradient(f,*varargs):\n \"\"\"Calculate the gradient of an N-dimensional scalar function.\n\n Uses central differences on the interior and first differences on boundaries\n to give the same shape.\n\n Inputs:\n\n f -- An N-dimensional array giving samples of a scalar function\n\n varargs -- 0, 1, or N scalars giving the sample distances in each direction\n\n Outputs:\n\n N arrays of the same shape as f giving the derivative of f with respect\n to each dimension.\n \"\"\"\n N = len(f.shape) # number of dimensions\n n = len(varargs)\n if n==0:\n dx = [1.0]*N\n elif n==1:\n dx = [varargs[0]]*N\n elif n==N:\n dx = list(varargs)\n else:\n raise SyntaxError, \"invalid number of arguments\"\n\n # use central differences on interior and first differences on endpoints\n\n print dx\n outvals = []\n\n # create slice objects --- initially all are [:,:,...,:]\n slice1 = [slice(None)]*N\n slice2 = [slice(None)]*N\n slice3 = [slice(None)]*N\n\n otype = f.dtypechar\n if otype not in ['f','d','F','D']:\n otype = 'd'\n\n for axis in range(N):\n # select out appropriate parts for this dimension\n out = zeros(f.shape, f.dtypechar)\n slice1[axis] = slice(1,-1)\n slice2[axis] = slice(2,None)\n slice3[axis] = slice(None,-2)\n # 1d equivalent -- out[1:-1] = (f[2:] - f[:-2])/2.0\n out[slice1] = (f[slice2] - f[slice3])/2.0 \n slice1[axis] = 0\n slice2[axis] = 1\n slice3[axis] = 0\n # 1d equivalent -- out[0] = (f[1] - f[0])\n out[slice1] = (f[slice2] - f[slice3])\n slice1[axis] = -1\n slice2[axis] = -1\n slice3[axis] = -2\n # 1d equivalent -- out[-1] = (f[-1] - f[-2])\n out[slice1] = (f[slice2] - f[slice3])\n \n # divide by step size\n outvals.append(out / dx[axis])\n \n # reset the slice object in this dimension to \":\"\n slice1[axis] = slice(None)\n slice2[axis] = slice(None)\n slice3[axis] = slice(None)\n\n if N == 1:\n return outvals[0]\n else:\n return outvals\n \n\ndef diff(x, n=1,axis=-1):\n \"\"\"Calculates the nth order, discrete difference along given axis.\n \"\"\"\n if n==0:\n return x\n if n<0:\n raise ValueError,'Order must be non-negative but got ' + `n`\n x = asarray(x)\n nd = len(x.shape)\n slice1 = [slice(None)]*nd\n slice2 = [slice(None)]*nd\n slice1[axis] = slice(1,None)\n slice2[axis] = slice(None,-1)\n slice1 = tuple(slice1)\n slice2 = tuple(slice2)\n if n > 1:\n return diff(x[slice1]-x[slice2], n-1, axis=axis)\n else:\n return x[slice1]-x[slice2]\n \ndef angle(z,deg=0):\n \"\"\"Return the angle of complex argument z.\"\"\"\n if deg:\n fact = 180/pi\n else:\n fact = 1.0\n z = asarray(z)\n if (issubclass(z.dtype, _nx.complexfloating)):\n zimag = z.imag\n zreal = z.real\n else:\n zimag = 0\n zreal = z\n return arctan2(zimag,zreal) * fact\n\ndef unwrap(p,discont=pi,axis=-1):\n \"\"\"unwraps radian phase p by changing absolute jumps greater than\n discont to their 2*pi complement along the given axis.\n \"\"\"\n p = asarray(p)\n nd = len(p.shape)\n dd = diff(p,axis=axis)\n slice1 = [slice(None,None)]*nd # full slices\n slice1[axis] = slice(1,None)\n ddmod = mod(dd+pi,2*pi)-pi\n _nx.putmask(ddmod,(ddmod==-pi) & (dd > 0),pi)\n ph_correct = ddmod - dd;\n _nx.putmask(ph_correct,abs(dd)>> import scipy\n >>> a = array((0,0,0,1,2,3,2,1,0))\n >>> scipy.trim_zeros(a)\n array([1, 2, 3, 2, 1])\n \"\"\"\n first = 0\n trim = trim.upper()\n if 'F' in trim:\n for i in filt:\n if i != 0.: break\n else: first = first + 1\n last = len(filt)\n if 'B' in trim:\n for i in filt[::-1]:\n if i != 0.: break\n else: last = last - 1\n return filt[first:last]\n\ndef unique(inseq):\n \"\"\"Returns unique items in 1-dimensional sequence.\n \"\"\"\n # Dictionary setting is quite fast.\n set = {}\n for item in inseq:\n set[item] = None\n return asarray(set.keys())\n \ndef extract(condition, arr):\n \"\"\"Elements of ravel(arr) where ravel(condition) is true (1-d)\n\n Equivalent of compress(ravel(condition), ravel(arr))\n \"\"\"\n return _nx.take(ravel(arr), nonzero(ravel(condition)))\n\ndef insert(arr, mask, vals):\n \"\"\"Similar to putmask arr[mask] = vals but 1d array vals has the\n same number of elements as the non-zero values of mask. Inverse of extract.\n \"\"\"\n return _nx._insert(arr, mask, vals)\n\ndef nansum(x,axis=-1):\n \"\"\"Sum the array over the given axis treating nans as 0\n \"\"\"\n y = array(x)\n if not issubclass(y.dtype, _nx.integer):\n y[isnan(x)] = 0\n return y.sum(axis)\n\ndef nanmin(x,axis=-1):\n \"\"\"Find the minimium over the given axis ignoring nans.\n \"\"\"\n y = array(x)\n if not issubclass(y.dtype, _nx.integer):\n y[isnan(x)] = _nx.inf\n return y.min(axis)\n\ndef nanargmin(x,axis=-1):\n \"\"\"Find the indices of the minimium over the given axis ignoring nans.\n \"\"\"\n y = array(x)\n if not issubclass(y.dtype, _nx.integer):\n y[isnan(x)] = _nx.inf \n return y.argmin(axis) \n\ndef nanmax(x,axis=-1):\n \"\"\"Find the maximum over the given axis ignoring nans.\n \"\"\"\n y = array(x)\n if not issubclass(y.dtype, _nx.integer):\n y[isnan(x)] = -_nx.inf \n return y.max(axis) \n\ndef nanargmax(x,axis=-1):\n \"\"\"Find the maximum over the given axis ignoring nans.\n \"\"\"\n y = array(x)\n if not issubclass(y.dtype, _nx.integer):\n y[isnan(x)] = -_nx.inf \n return y.argmax(axis) \n\ndef disp(mesg, device=None, linefeed=1):\n \"\"\"Display a message to device (default is sys.stdout) with(out) linefeed.\n \"\"\"\n if device is None:\n import sys\n device = sys.stdout\n if linefeed:\n device.write('%s\\n' % mesg)\n else:\n device.write('%s' % mesg)\n device.flush()\n return\n\nclass vectorize:\n \"\"\"\n vectorize(somefunction, otypes=None, doc=None)\n Generalized Function class.\n\n Description:\n \n Define a vectorized function which takes nested sequence\n objects or scipy arrays as inputs and returns a\n scipy array as output, evaluating the function over successive\n tuples of the input arrays like the python map function except it uses\n the broadcasting rules of scipy. \n\n Input:\n\n somefunction -- a Python function or method\n\n Example:\n\n def myfunc(a,b):\n if a > b:\n return a-b\n else\n return a+b\n\n vfunc = vectorize(myfunc)\n\n >>> vfunc([1,2,3,4],2)\n array([3,4,1,2])\n\n \"\"\"\n def __init__(self,pyfunc,otypes='',doc=None):\n try:\n fcode = pyfunc.func_code\n except AttributeError:\n raise TypeError, \"object is not a callable Python object\"\n\n self.thefunc = pyfunc\n self.ufunc = None\n self.nin = len(fcode.co_varnames)\n self.nout = None\n if doc is None:\n self.__doc__ = pyfunc.__doc__\n else:\n self.__doc__ = doc\n if isinstance(otypes,types.StringType):\n self.otypes=otypes\n else:\n raise ValueError, \"output types must be a string\"\n for char in self.otypes:\n if char not in typecodes['All']:\n raise ValueError, \"invalid typecode specified\"\n\n def __call__(self,*args):\n # get number of outputs and output types by calling\n # the function on the first entries of args\n if len(args) != self.nin:\n raise ValueError, \"mismatch between python function inputs\"\\\n \" and received arguments\"\n if self.nout is None or self.otypes == '':\n newargs = []\n for arg in args:\n newargs.append(asarray(arg).flat[0])\n theout = self.thefunc(*newargs)\n if isinstance(theout, types.TupleType):\n self.nout = len(theout)\n else:\n self.nout = 1\n theout = (theout,)\n if self.otypes == '':\n otypes = []\n for k in range(self.nout):\n otypes.append(asarray(theout[k]).dtypechar)\n self.otypes = ''.join(otypes)\n\n if self.ufunc is None:\n self.ufunc = frompyfunc(self.thefunc, self.nin, self.nout)\n\n if self.nout == 1:\n return self.ufunc(*args).astype(self.otypes[0])\n else:\n return tuple([x.astype(c) for x,c in zip(self.ufunc(*args), self.otypes)])\n\n\ndef round_(x, decimals=0):\n \"\"\"round_(m, decimals=0) Rounds x to decimals places.\n\n Returns x if array is not floating point and rounds both the real\n and imaginary parts separately if array is complex. Rounds in the\n same way as standard Python.\n \"\"\"\n x = asarray(x)\n if not issubclass(x.dtype, _nx.inexact):\n return x\n if issubclass(x.dtype, _nx.complexfloating):\n return round_(x.real, decimals) + 1j*round_(x.imag, decimals)\n if decimals is not 0:\n decimals = asarray(decimals)\n s = sign(x)\n if decimals is not 0:\n x = absolute(multiply(x,10.**decimals))\n else:\n x = absolute(x)\n rem = x-asarray(x).astype(_nx.intp)\n x = _nx.where(_nx.less(rem,0.5), _nx.floor(x), _nx.ceil(x))\n # convert back\n if decimals is not 0:\n return multiply(x,s/(10.**decimals))\n else:\n return multiply(x,s)\n\n", "methods": [ { "name": "binary_repr", "long_name": "binary_repr( num )", "filename": "function_base.py", "nloc": 9, "complexity": 3, "token_count": 50, "parameters": [ "num" ], "start_line": 33, "end_line": 46, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "base_repr", "long_name": "base_repr( number , base = 2 , padding = 0 )", "filename": "function_base.py", "nloc": 14, "complexity": 3, "token_count": 97, "parameters": [ "number", "base", "padding" ], "start_line": 48, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "logspace", "long_name": "logspace( start , stop , num = 50 , endpoint = True )", "filename": "function_base.py", "nloc": 9, "complexity": 3, "token_count": 99, "parameters": [ "start", "stop", "num", "endpoint" ], "start_line": 69, "end_line": 82, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "linspace", "long_name": "linspace( start , stop , num = 50 , endpoint = True , retstep = False )", "filename": "function_base.py", "nloc": 12, "complexity": 4, "token_count": 103, "parameters": [ "start", "stop", "num", "endpoint", "retstep" ], "start_line": 84, "end_line": 99, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "iterable", "long_name": "iterable( y )", "filename": "function_base.py", "nloc": 4, "complexity": 2, "token_count": 17, "parameters": [ "y" ], "start_line": 101, "end_line": 104, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "histogram", "long_name": "histogram( a , bins = 10 , range = None , normed = False )", "filename": "function_base.py", "nloc": 18, "complexity": 6, "token_count": 171, "parameters": [ "a", "bins", "range", "normed" ], "start_line": 106, "end_line": 125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "average", "long_name": "average( a , axis = 0 , weights = None , returned = False )", "filename": "function_base.py", "nloc": 44, "complexity": 12, "token_count": 335, "parameters": [ "a", "axis", "weights", "returned" ], "start_line": 127, "end_line": 200, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 74, "top_nesting_level": 0 }, { "name": "isaltered", "long_name": "isaltered( )", "filename": "function_base.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 203, "end_line": 205, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "asarray_chkfinite", "long_name": "asarray_chkfinite( a )", "filename": "function_base.py", "nloc": 6, "complexity": 4, "token_count": 57, "parameters": [ "a" ], "start_line": 208, "end_line": 215, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "piecewise", "long_name": "piecewise( x , condlist , funclist , * args , ** kw )", "filename": "function_base.py", "nloc": 21, "complexity": 7, "token_count": 163, "parameters": [ "x", "condlist", "funclist", "args", "kw" ], "start_line": 220, "end_line": 271, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 0 }, { "name": "select", "long_name": "select( condlist , choicelist , default = 0 )", "filename": "function_base.py", "nloc": 18, "complexity": 7, "token_count": 165, "parameters": [ "condlist", "choicelist", "default" ], "start_line": 273, "end_line": 319, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "_asarray1d", "long_name": "_asarray1d( arr , copy = False )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 33, "parameters": [ "arr", "copy" ], "start_line": 321, "end_line": 327, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "copy", "long_name": "copy( a )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "a" ], "start_line": 329, "end_line": 332, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "amax", "long_name": "amax( a , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "a", "axis" ], "start_line": 335, "end_line": 338, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "amin", "long_name": "amin( a , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "a", "axis" ], "start_line": 340, "end_line": 343, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "alen", "long_name": "alen( a )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "a" ], "start_line": 345, "end_line": 348, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "ptp", "long_name": "ptp( a , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "a", "axis" ], "start_line": 350, "end_line": 353, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "prod", "long_name": "prod( a , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "a", "axis" ], "start_line": 355, "end_line": 358, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "cumprod", "long_name": "cumprod( a , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "a", "axis" ], "start_line": 360, "end_line": 363, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "gradient", "long_name": "gradient( f , * varargs )", "filename": "function_base.py", "nloc": 41, "complexity": 7, "token_count": 325, "parameters": [ "f", "varargs" ], "start_line": 365, "end_line": 437, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 73, "top_nesting_level": 0 }, { "name": "diff", "long_name": "diff( a , n = 1 , axis = - 1 )", "filename": "function_base.py", "nloc": 17, "complexity": 4, "token_count": 142, "parameters": [ "a", "n", "axis" ], "start_line": 440, "end_line": 458, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "angle", "long_name": "angle( z , deg = 0 )", "filename": "function_base.py", "nloc": 13, "complexity": 3, "token_count": 72, "parameters": [ "z", "deg" ], "start_line": 460, "end_line": 474, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "unwrap", "long_name": "unwrap( p , discont = pi , axis = - 1 )", "filename": "function_base.py", "nloc": 13, "complexity": 1, "token_count": 150, "parameters": [ "p", "discont", "axis" ], "start_line": 476, "end_line": 491, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "sort_complex", "long_name": "sort_complex( a )", "filename": "function_base.py", "nloc": 11, "complexity": 4, "token_count": 70, "parameters": [ "a" ], "start_line": 493, "end_line": 508, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "trim_zeros", "long_name": "trim_zeros( filt , trim = 'fb' )", "filename": "function_base.py", "nloc": 13, "complexity": 7, "token_count": 86, "parameters": [ "filt", "trim" ], "start_line": 510, "end_line": 530, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "unique", "long_name": "unique( inseq )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 30, "parameters": [ "inseq" ], "start_line": 532, "end_line": 539, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "extract", "long_name": "extract( condition , arr )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 26, "parameters": [ "condition", "arr" ], "start_line": 541, "end_line": 547, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "insert", "long_name": "insert( arr , mask , vals )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "arr", "mask", "vals" ], "start_line": 549, "end_line": 554, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "nansum", "long_name": "nansum( a , axis = - 1 )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 46, "parameters": [ "a", "axis" ], "start_line": 556, "end_line": 562, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "nanmin", "long_name": "nanmin( a , axis = - 1 )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 48, "parameters": [ "a", "axis" ], "start_line": 564, "end_line": 570, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "nanargmin", "long_name": "nanargmin( a , axis = - 1 )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 48, "parameters": [ "a", "axis" ], "start_line": 572, "end_line": 578, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "nanmax", "long_name": "nanmax( a , axis = - 1 )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 49, "parameters": [ "a", "axis" ], "start_line": 580, "end_line": 586, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "nanargmax", "long_name": "nanargmax( a , axis = - 1 )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 49, "parameters": [ "a", "axis" ], "start_line": 588, "end_line": 594, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "disp", "long_name": "disp( mesg , device = None , linefeed = True )", "filename": "function_base.py", "nloc": 10, "complexity": 3, "token_count": 53, "parameters": [ "mesg", "device", "linefeed" ], "start_line": 596, "end_line": 608, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , pyfunc , otypes = '' , doc = None )", "filename": "function_base.py", "nloc": 20, "complexity": 6, "token_count": 114, "parameters": [ "self", "pyfunc", "otypes", "doc" ], "start_line": 641, "end_line": 661, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , * args )", "filename": "function_base.py", "nloc": 25, "complexity": 11, "token_count": 228, "parameters": [ "self", "args" ], "start_line": 663, "end_line": 691, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "round_", "long_name": "round_( a , decimals = 0 )", "filename": "function_base.py", "nloc": 19, "complexity": 6, "token_count": 184, "parameters": [ "a", "decimals" ], "start_line": 694, "end_line": 719, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 } ], "methods_before": [ { "name": "binary_repr", "long_name": "binary_repr( num )", "filename": "function_base.py", "nloc": 9, "complexity": 3, "token_count": 50, "parameters": [ "num" ], "start_line": 33, "end_line": 45, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "base_repr", "long_name": "base_repr( number , base = 2 , padding = 0 )", "filename": "function_base.py", "nloc": 14, "complexity": 3, "token_count": 97, "parameters": [ "number", "base", "padding" ], "start_line": 47, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "logspace", "long_name": "logspace( start , stop , num = 50 , endpoint = 1 )", "filename": "function_base.py", "nloc": 9, "complexity": 3, "token_count": 99, "parameters": [ "start", "stop", "num", "endpoint" ], "start_line": 68, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "linspace", "long_name": "linspace( start , stop , num = 50 , endpoint = 1 , retstep = False )", "filename": "function_base.py", "nloc": 12, "complexity": 4, "token_count": 103, "parameters": [ "start", "stop", "num", "endpoint", "retstep" ], "start_line": 83, "end_line": 99, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "iterable", "long_name": "iterable( y )", "filename": "function_base.py", "nloc": 4, "complexity": 2, "token_count": 17, "parameters": [ "y" ], "start_line": 101, "end_line": 104, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "histogram", "long_name": "histogram( x , bins = 10 , range = None , normed = False )", "filename": "function_base.py", "nloc": 18, "complexity": 6, "token_count": 171, "parameters": [ "x", "bins", "range", "normed" ], "start_line": 106, "end_line": 125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "average", "long_name": "average( a , axis = 0 , weights = None , returned = 0 )", "filename": "function_base.py", "nloc": 44, "complexity": 12, "token_count": 335, "parameters": [ "a", "axis", "weights", "returned" ], "start_line": 127, "end_line": 190, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 64, "top_nesting_level": 0 }, { "name": "isaltered", "long_name": "isaltered( )", "filename": "function_base.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 193, "end_line": 195, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "asarray_chkfinite", "long_name": "asarray_chkfinite( x )", "filename": "function_base.py", "nloc": 6, "complexity": 4, "token_count": 57, "parameters": [ "x" ], "start_line": 198, "end_line": 205, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "piecewise", "long_name": "piecewise( x , condlist , funclist , * args , ** kw )", "filename": "function_base.py", "nloc": 21, "complexity": 7, "token_count": 163, "parameters": [ "x", "condlist", "funclist", "args", "kw" ], "start_line": 210, "end_line": 261, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 0 }, { "name": "select", "long_name": "select( condlist , choicelist , default = 0 )", "filename": "function_base.py", "nloc": 18, "complexity": 7, "token_count": 165, "parameters": [ "condlist", "choicelist", "default" ], "start_line": 263, "end_line": 309, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "_asarray1d", "long_name": "_asarray1d( arr , copy = False )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 33, "parameters": [ "arr", "copy" ], "start_line": 311, "end_line": 317, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "copy", "long_name": "copy( a )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "a" ], "start_line": 319, "end_line": 322, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "amax", "long_name": "amax( m , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "m", "axis" ], "start_line": 325, "end_line": 328, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "amin", "long_name": "amin( m , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "m", "axis" ], "start_line": 330, "end_line": 333, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "alen", "long_name": "alen( m )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "m" ], "start_line": 335, "end_line": 338, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "ptp", "long_name": "ptp( m , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "m", "axis" ], "start_line": 340, "end_line": 343, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "prod", "long_name": "prod( m , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "m", "axis" ], "start_line": 345, "end_line": 348, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "cumprod", "long_name": "cumprod( m , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "m", "axis" ], "start_line": 350, "end_line": 353, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "gradient", "long_name": "gradient( f , * varargs )", "filename": "function_base.py", "nloc": 41, "complexity": 7, "token_count": 325, "parameters": [ "f", "varargs" ], "start_line": 355, "end_line": 427, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 73, "top_nesting_level": 0 }, { "name": "diff", "long_name": "diff( x , n = 1 , axis = - 1 )", "filename": "function_base.py", "nloc": 17, "complexity": 4, "token_count": 142, "parameters": [ "x", "n", "axis" ], "start_line": 430, "end_line": 448, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "angle", "long_name": "angle( z , deg = 0 )", "filename": "function_base.py", "nloc": 13, "complexity": 3, "token_count": 72, "parameters": [ "z", "deg" ], "start_line": 450, "end_line": 463, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "unwrap", "long_name": "unwrap( p , discont = pi , axis = - 1 )", "filename": "function_base.py", "nloc": 13, "complexity": 1, "token_count": 150, "parameters": [ "p", "discont", "axis" ], "start_line": 465, "end_line": 480, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "sort_complex", "long_name": "sort_complex( a )", "filename": "function_base.py", "nloc": 11, "complexity": 4, "token_count": 70, "parameters": [ "a" ], "start_line": 482, "end_line": 497, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "trim_zeros", "long_name": "trim_zeros( filt , trim = 'fb' )", "filename": "function_base.py", "nloc": 13, "complexity": 7, "token_count": 86, "parameters": [ "filt", "trim" ], "start_line": 499, "end_line": 519, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "unique", "long_name": "unique( inseq )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 30, "parameters": [ "inseq" ], "start_line": 521, "end_line": 528, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "extract", "long_name": "extract( condition , arr )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 26, "parameters": [ "condition", "arr" ], "start_line": 530, "end_line": 535, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "insert", "long_name": "insert( arr , mask , vals )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "arr", "mask", "vals" ], "start_line": 537, "end_line": 541, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "nansum", "long_name": "nansum( x , axis = - 1 )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 46, "parameters": [ "x", "axis" ], "start_line": 543, "end_line": 549, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "nanmin", "long_name": "nanmin( x , axis = - 1 )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 48, "parameters": [ "x", "axis" ], "start_line": 551, "end_line": 557, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "nanargmin", "long_name": "nanargmin( x , axis = - 1 )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 48, "parameters": [ "x", "axis" ], "start_line": 559, "end_line": 565, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "nanmax", "long_name": "nanmax( x , axis = - 1 )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 49, "parameters": [ "x", "axis" ], "start_line": 567, "end_line": 573, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "nanargmax", "long_name": "nanargmax( x , axis = - 1 )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 49, "parameters": [ "x", "axis" ], "start_line": 575, "end_line": 581, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "disp", "long_name": "disp( mesg , device = None , linefeed = 1 )", "filename": "function_base.py", "nloc": 10, "complexity": 3, "token_count": 53, "parameters": [ "mesg", "device", "linefeed" ], "start_line": 583, "end_line": 594, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , pyfunc , otypes = '' , doc = None )", "filename": "function_base.py", "nloc": 20, "complexity": 6, "token_count": 114, "parameters": [ "self", "pyfunc", "otypes", "doc" ], "start_line": 627, "end_line": 647, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , * args )", "filename": "function_base.py", "nloc": 25, "complexity": 11, "token_count": 228, "parameters": [ "self", "args" ], "start_line": 649, "end_line": 677, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "round_", "long_name": "round_( x , decimals = 0 )", "filename": "function_base.py", "nloc": 19, "complexity": 6, "token_count": 184, "parameters": [ "x", "decimals" ], "start_line": 680, "end_line": 705, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "copy", "long_name": "copy( a )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "a" ], "start_line": 329, "end_line": 332, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "unique", "long_name": "unique( inseq )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 30, "parameters": [ "inseq" ], "start_line": 532, "end_line": 539, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "histogram", "long_name": "histogram( x , bins = 10 , range = None , normed = False )", "filename": "function_base.py", "nloc": 18, "complexity": 6, "token_count": 171, "parameters": [ "x", "bins", "range", "normed" ], "start_line": 106, "end_line": 125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "nanargmin", "long_name": "nanargmin( a , axis = - 1 )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 48, "parameters": [ "a", "axis" ], "start_line": 572, "end_line": 578, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "nanargmax", "long_name": "nanargmax( a , axis = - 1 )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 49, "parameters": [ "a", "axis" ], "start_line": 588, "end_line": 594, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "alen", "long_name": "alen( a )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "a" ], "start_line": 345, "end_line": 348, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "insert", "long_name": "insert( arr , mask , vals )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "arr", "mask", "vals" ], "start_line": 549, "end_line": 554, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "binary_repr", "long_name": "binary_repr( num )", "filename": "function_base.py", "nloc": 9, "complexity": 3, "token_count": 50, "parameters": [ "num" ], "start_line": 33, "end_line": 46, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "asarray_chkfinite", "long_name": "asarray_chkfinite( a )", "filename": "function_base.py", "nloc": 6, "complexity": 4, "token_count": 57, "parameters": [ "a" ], "start_line": 208, "end_line": 215, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "nansum", "long_name": "nansum( x , axis = - 1 )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 46, "parameters": [ "x", "axis" ], "start_line": 543, "end_line": 549, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "nanmax", "long_name": "nanmax( a , axis = - 1 )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 49, "parameters": [ "a", "axis" ], "start_line": 580, "end_line": 586, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , pyfunc , otypes = '' , doc = None )", "filename": "function_base.py", "nloc": 20, "complexity": 6, "token_count": 114, "parameters": [ "self", "pyfunc", "otypes", "doc" ], "start_line": 641, "end_line": 661, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , * args )", "filename": "function_base.py", "nloc": 25, "complexity": 11, "token_count": 228, "parameters": [ "self", "args" ], "start_line": 663, "end_line": 691, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "prod", "long_name": "prod( m , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "m", "axis" ], "start_line": 345, "end_line": 348, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "amin", "long_name": "amin( m , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "m", "axis" ], "start_line": 330, "end_line": 333, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "cumprod", "long_name": "cumprod( m , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "m", "axis" ], "start_line": 350, "end_line": 353, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "amin", "long_name": "amin( a , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "a", "axis" ], "start_line": 340, "end_line": 343, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "nanargmax", "long_name": "nanargmax( x , axis = - 1 )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 49, "parameters": [ "x", "axis" ], "start_line": 575, "end_line": 581, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "round_", "long_name": "round_( x , decimals = 0 )", "filename": "function_base.py", "nloc": 19, "complexity": 6, "token_count": 184, "parameters": [ "x", "decimals" ], "start_line": 680, "end_line": 705, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "extract", "long_name": "extract( condition , arr )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 26, "parameters": [ "condition", "arr" ], "start_line": 541, "end_line": 547, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "nanmax", "long_name": "nanmax( x , axis = - 1 )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 49, "parameters": [ "x", "axis" ], "start_line": 567, "end_line": 573, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "cumprod", "long_name": "cumprod( a , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "a", "axis" ], "start_line": 360, "end_line": 363, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "logspace", "long_name": "logspace( start , stop , num = 50 , endpoint = True )", "filename": "function_base.py", "nloc": 9, "complexity": 3, "token_count": 99, "parameters": [ "start", "stop", "num", "endpoint" ], "start_line": 69, "end_line": 82, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "diff", "long_name": "diff( a , n = 1 , axis = - 1 )", "filename": "function_base.py", "nloc": 17, "complexity": 4, "token_count": 142, "parameters": [ "a", "n", "axis" ], "start_line": 440, "end_line": 458, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "amax", "long_name": "amax( a , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "a", "axis" ], "start_line": 335, "end_line": 338, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "diff", "long_name": "diff( x , n = 1 , axis = - 1 )", "filename": "function_base.py", "nloc": 17, "complexity": 4, "token_count": 142, "parameters": [ "x", "n", "axis" ], "start_line": 430, "end_line": 448, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "asarray_chkfinite", "long_name": "asarray_chkfinite( x )", "filename": "function_base.py", "nloc": 6, "complexity": 4, "token_count": 57, "parameters": [ "x" ], "start_line": 198, "end_line": 205, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "logspace", "long_name": "logspace( start , stop , num = 50 , endpoint = 1 )", "filename": "function_base.py", "nloc": 9, "complexity": 3, "token_count": 99, "parameters": [ "start", "stop", "num", "endpoint" ], "start_line": 68, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "round_", "long_name": "round_( a , decimals = 0 )", "filename": "function_base.py", "nloc": 19, "complexity": 6, "token_count": 184, "parameters": [ "a", "decimals" ], "start_line": 694, "end_line": 719, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "histogram", "long_name": "histogram( a , bins = 10 , range = None , normed = False )", "filename": "function_base.py", "nloc": 18, "complexity": 6, "token_count": 171, "parameters": [ "a", "bins", "range", "normed" ], "start_line": 106, "end_line": 125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "linspace", "long_name": "linspace( start , stop , num = 50 , endpoint = True , retstep = False )", "filename": "function_base.py", "nloc": 12, "complexity": 4, "token_count": 103, "parameters": [ "start", "stop", "num", "endpoint", "retstep" ], "start_line": 84, "end_line": 99, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "gradient", "long_name": "gradient( f , * varargs )", "filename": "function_base.py", "nloc": 41, "complexity": 7, "token_count": 325, "parameters": [ "f", "varargs" ], "start_line": 365, "end_line": 437, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 73, "top_nesting_level": 0 }, { "name": "select", "long_name": "select( condlist , choicelist , default = 0 )", "filename": "function_base.py", "nloc": 18, "complexity": 7, "token_count": 165, "parameters": [ "condlist", "choicelist", "default" ], "start_line": 273, "end_line": 319, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "average", "long_name": "average( a , axis = 0 , weights = None , returned = 0 )", "filename": "function_base.py", "nloc": 44, "complexity": 12, "token_count": 335, "parameters": [ "a", "axis", "weights", "returned" ], "start_line": 127, "end_line": 190, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 64, "top_nesting_level": 0 }, { "name": "sort_complex", "long_name": "sort_complex( a )", "filename": "function_base.py", "nloc": 11, "complexity": 4, "token_count": 70, "parameters": [ "a" ], "start_line": 493, "end_line": 508, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "disp", "long_name": "disp( mesg , device = None , linefeed = 1 )", "filename": "function_base.py", "nloc": 10, "complexity": 3, "token_count": 53, "parameters": [ "mesg", "device", "linefeed" ], "start_line": 583, "end_line": 594, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "nanmin", "long_name": "nanmin( a , axis = - 1 )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 48, "parameters": [ "a", "axis" ], "start_line": 564, "end_line": 570, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "alen", "long_name": "alen( m )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "m" ], "start_line": 335, "end_line": 338, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "angle", "long_name": "angle( z , deg = 0 )", "filename": "function_base.py", "nloc": 13, "complexity": 3, "token_count": 72, "parameters": [ "z", "deg" ], "start_line": 460, "end_line": 474, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "nansum", "long_name": "nansum( a , axis = - 1 )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 46, "parameters": [ "a", "axis" ], "start_line": 556, "end_line": 562, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "ptp", "long_name": "ptp( m , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "m", "axis" ], "start_line": 340, "end_line": 343, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "nanmin", "long_name": "nanmin( x , axis = - 1 )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 48, "parameters": [ "x", "axis" ], "start_line": 551, "end_line": 557, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "linspace", "long_name": "linspace( start , stop , num = 50 , endpoint = 1 , retstep = False )", "filename": "function_base.py", "nloc": 12, "complexity": 4, "token_count": 103, "parameters": [ "start", "stop", "num", "endpoint", "retstep" ], "start_line": 83, "end_line": 99, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "prod", "long_name": "prod( a , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "a", "axis" ], "start_line": 355, "end_line": 358, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "piecewise", "long_name": "piecewise( x , condlist , funclist , * args , ** kw )", "filename": "function_base.py", "nloc": 21, "complexity": 7, "token_count": 163, "parameters": [ "x", "condlist", "funclist", "args", "kw" ], "start_line": 220, "end_line": 271, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 0 }, { "name": "ptp", "long_name": "ptp( a , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "a", "axis" ], "start_line": 350, "end_line": 353, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "amax", "long_name": "amax( m , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "m", "axis" ], "start_line": 325, "end_line": 328, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "nanargmin", "long_name": "nanargmin( x , axis = - 1 )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 48, "parameters": [ "x", "axis" ], "start_line": 559, "end_line": 565, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "disp", "long_name": "disp( mesg , device = None , linefeed = True )", "filename": "function_base.py", "nloc": 10, "complexity": 3, "token_count": 53, "parameters": [ "mesg", "device", "linefeed" ], "start_line": 596, "end_line": 608, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "average", "long_name": "average( a , axis = 0 , weights = None , returned = False )", "filename": "function_base.py", "nloc": 44, "complexity": 12, "token_count": 335, "parameters": [ "a", "axis", "weights", "returned" ], "start_line": 127, "end_line": 200, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 74, "top_nesting_level": 0 }, { "name": "_asarray1d", "long_name": "_asarray1d( arr , copy = False )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 33, "parameters": [ "arr", "copy" ], "start_line": 321, "end_line": 327, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "trim_zeros", "long_name": "trim_zeros( filt , trim = 'fb' )", "filename": "function_base.py", "nloc": 13, "complexity": 7, "token_count": 86, "parameters": [ "filt", "trim" ], "start_line": 510, "end_line": 530, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "unwrap", "long_name": "unwrap( p , discont = pi , axis = - 1 )", "filename": "function_base.py", "nloc": 13, "complexity": 1, "token_count": 150, "parameters": [ "p", "discont", "axis" ], "start_line": 476, "end_line": 491, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 } ], "nloc": 453, "complexity": 127, "token_count": 3442, "diff_parsed": { "added": [ "__all__ = ['logspace', 'linspace', 'round_',", " 'select', 'piecewise', 'trim_zeros', 'alen', 'amax', 'amin', 'ptp',", " 'copy', 'iterable', 'base_repr', 'binary_repr', 'prod', 'cumprod',", " 'diff', 'gradient', 'angle', 'unwrap', 'sort_complex', 'disp',", " 'unique', 'extract', 'insert', 'nansum', 'nanmax', 'nanargmax',", " 'nanargmin', 'nanmin', 'vectorize', 'asarray_chkfinite', 'average',", " 'histogram', 'bincount', 'digitize']", " This is equivalent to using base_repr with base 2, but about 25x", " faster.", "def logspace(start, stop, num=50, endpoint=True):", " \"\"\" Return evenly spaced samples on a logarithmic scale.", " Return 'num' evenly spaced samples from 10**start to 10**stop.", " If 'endpoint' is True then the last sample is 10**stop.", " y = _nx.arange(0, num) * step + start", " y = _nx.arange(0, num) * step + start", " return _nx.power(10.0, y)", "def linspace(start, stop, num=50, endpoint=True, retstep=False):", " \"\"\" Return 'num' evenly spaced samples from 'start' to 'stop'. If", " 'endpoint' is True, the last sample is 'stop'. If 'retstep' is", " True then return the step value used.", " y = _nx.arange(0, num) * step + start", " y = _nx.arange(0, num) * step + start", "def histogram(a, bins=10, range=None, normed=False):", " a = asarray(a).ravel()", " range = (a.min(), a.max())", " mn, mx = [a+0.0 for a in range]", " n = a.sort().searchsorted(bins)", " n = concatenate([n, [len(a)]])", " return 1.0/(a.size*db) * n, bins", "def average(a, axis=0, weights=None, returned=False):", " \"\"\"average(a, axis=0, weights=None, returned=False)", "", " Compute average over the given axis. If axis is None, average", " over all dimensions of the array. Equivalent to a.mean(axis),", " but with a default axis of 0 instead of None.", " The average of an integer or floating-point array always has type", " Float.", "", " If an integer axis is given, this equals:", " a.sum(axis) * 1.0 / len(a)", "", " If axis is None, this equals:", " a.sum(axis) * 1.0 / product(a.shape)", " If weights are given, result is:", " sum(a * weights) / sum(weights),", " where the weights must have a's shape or be 1D with length the", " size of a in the given axis. Integer weights are converted to", " Float. Not specifying weights is equivalent to specifying", " weights that are all 1.", "", " If 'returned' is True, return a tuple: the result and the sum of", " the weights or count of values. The shape of these two results", " will be the same.", " Raises ZeroDivisionError if appropriate. (The version in MA does", " not -- it returns masked values).", " n = add.reduce(multiply(a, w))", " r[axis] = slice(None, None, 1)", " raise ValueError, 'averaging weights have wrong shape'", " raise ZeroDivisionError, 'zero denominator in average()'", "def asarray_chkfinite(a):", " \"\"\"Like asarray, but check that no NaNs or Infs are present.", " a = asarray(a)", " if (a.dtypechar in _nx.typecodes['AllFloat']) \\", " and (_nx.isnan(a).any() or _nx.isinf(a).any()):", " raise ValueError, \"array must not contain infs or NaNs\"", " return a", " \"\"\"Return a piecewise-defined function.", " for k in range(1, n):", " \"\"\" Return an array composed of different elements of choicelist", " arrays in choicelist. If condlist is [c0, ..., cN-1] then choicelist", " represented as [v0, ..., vN-1]. The default choice if none of the", " Note that one of the condition arrays must be large enough to handle", " choicelist.insert(0, default)", " for k in range(1, n+1):", "def _asarray1d(arr, copy=False):", " \"\"\"Ensure 1D array for one array.", " \"\"\"Return an array copy of the given object.", " return array(a, copy=True)", "def amax(a, axis=-1):", " \"\"\"Return the maximum of 'a' along dimension axis.", " return asarray(a).max(axis)", "def amin(a, axis=-1):", " \"\"\"Return the minimum of a along dimension axis.", " return asarray(a).min(axis)", "def alen(a):", " \"\"\"Return the length of a Python object interpreted as an array", " return len(asarray(a))", "def ptp(a, axis=-1):", " \"\"\"Return maximum - minimum along the the given dimension", " return asarray(a).ptp(axis)", "def prod(a, axis=-1):", " \"\"\"Return the product of the elements along the given axis", " return asarray(a).prod(axis)", "def cumprod(a, axis=-1):", " \"\"\"Return the cumulative product of the elments along the given axis", " return asarray(a).cumprod(axis)", "def gradient(f, *varargs):", " # create slice objects --- initially all are [:, :, ..., :]", " if otype not in ['f', 'd', 'F', 'D']:", " slice1[axis] = slice(1, -1)", " slice2[axis] = slice(2, None)", " slice3[axis] = slice(None, -2)", " # 1D equivalent -- out[1:-1] = (f[2:] - f[:-2])/2.0", " # 1D equivalent -- out[0] = (f[1] - f[0])", " # 1D equivalent -- out[-1] = (f[-1] - f[-2])", "def diff(a, n=1, axis=-1):", " \"\"\"Calculate the nth order discrete difference along given axis.", " return a", " raise ValueError, 'order must be non-negative but got ' + `n`", " a = asarray(a)", " nd = len(a.shape)", " slice1[axis] = slice(1, None)", " slice2[axis] = slice(None, -1)", " return diff(a[slice1]-a[slice2], n-1, axis=axis)", " return a[slice1]-a[slice2]", "def angle(z, deg=0):", " \"\"\"Return the angle of the complex argument z.", " \"\"\"", " return arctan2(zimag, zreal) * fact", "def unwrap(p, discont=pi, axis=-1):", " \"\"\"Unwrap radian phase p by changing absolute jumps greater than", " 'discont' to their 2*pi complement along the given axis.", " dd = diff(p, axis=axis)", " slice1 = [slice(None, None)]*nd # full slices", " slice1[axis] = slice(1, None)", " ddmod = mod(dd+pi, 2*pi)-pi", " _nx.putmask(ddmod, (ddmod==-pi) & (dd > 0), pi)", " _nx.putmask(ph_correct, abs(dd)>> import scipy", " >>> a = array((0, 0, 0, 1, 2, 3, 2, 1, 0))", " >>> scipy.trim_zeros(a)", " array([1, 2, 3, 2, 1])", " \"\"\"Return unique items from a 1-dimensional sequence.", " \"\"\"Return the elements of ravel(arr) where ravel(condition) is True", " (in 1D).", " Equivalent to compress(ravel(condition), ravel(arr)).", " \"\"\"Similar to putmask arr[mask] = vals but the 1D array vals has the", " same number of elements as the non-zero values of mask. Inverse of", " extract.", "def nansum(a, axis=-1):", " \"\"\"Sum the array over the given axis, treating NaNs as 0.", " y = array(a)", " y[isnan(a)] = 0", "def nanmin(a, axis=-1):", " \"\"\"Find the minimium over the given axis, ignoring NaNs.", " y = array(a)", " y[isnan(a)] = _nx.inf", "def nanargmin(a, axis=-1):", " \"\"\"Find the indices of the minimium over the given axis ignoring NaNs.", " y = array(a)", " y[isnan(a)] = _nx.inf", "def nanmax(a, axis=-1):", " \"\"\"Find the maximum over the given axis ignoring NaNs.", " y = array(a)", " y[isnan(a)] = -_nx.inf", "def nanargmax(a, axis=-1):", " \"\"\"Find the maximum over the given axis ignoring NaNs.", " y = array(a)", " y[isnan(a)] = -_nx.inf", "def disp(mesg, device=None, linefeed=True):", " \"\"\"Display a message to the given device (default is sys.stdout)", " with or without a linefeed.", " def myfunc(a, b):", " >>> vfunc([1, 2, 3, 4], 2)", " array([3, 4, 1, 2])", " def __init__(self, pyfunc, otypes='', doc=None):", " if isinstance(otypes, types.StringType):", " def __call__(self, *args):", " return tuple([x.astype(c) for x, c in zip(self.ufunc(*args), self.otypes)])", "def round_(a, decimals=0):", " \"\"\"Round 'a' to the given number of decimal places. Rounding", " behaviour is equivalent to Python.", " Return 'a' if the array is not floating point. Round both the real", " and imaginary parts separately if the array is complex.", " a = asarray(a)", " if not issubclass(a.dtype, _nx.inexact):", " return a", " if issubclass(a.dtype, _nx.complexfloating):", " return round_(a.real, decimals) + 1j*round_(a.imag, decimals)", " s = sign(a)", " a = absolute(multiply(a, 10.**decimals))", " a = absolute(a)", " rem = a-asarray(a).astype(_nx.intp)", " a = _nx.where(_nx.less(rem, 0.5), _nx.floor(a), _nx.ceil(a))", " return multiply(a, s/(10.**decimals))", " return multiply(a, s)" ], "deleted": [ "__all__ = ['logspace','linspace', 'round_',", " 'select','piecewise','trim_zeros','alen','amax', 'amin', 'ptp',", " 'copy', 'iterable', 'base_repr', 'binary_repr',", " 'prod','cumprod', 'diff','gradient','angle','unwrap','sort_complex',", " 'disp','unique','extract','insert','nansum','nanmax','nanargmax',", " 'nanargmin','nanmin', 'vectorize','asarray_chkfinite',", " 'average','histogram','bincount','digitize']", " This is abuut 25x faster than using base_repr with base 2.", "def logspace(start,stop,num=50,endpoint=1):", " \"\"\" Evenly spaced samples on a logarithmic scale.", " Return num evenly spaced samples from 10**start to 10**stop. If", " endpoint=1 then last sample is 10**stop.", " y = _nx.arange(0,num) * step + start", " y = _nx.arange(0,num) * step + start", " return _nx.power(10.0,y)", "def linspace(start,stop,num=50,endpoint=1,retstep=False):", " \"\"\" Evenly spaced samples.", "", " Return num evenly spaced samples from start to stop. If endpoint=1 then", " last sample is stop. If retstep is true then return the step value used.", " y = _nx.arange(0,num) * step + start", " y = _nx.arange(0,num) * step + start", "def histogram(x, bins=10, range=None, normed=False):", " x = asarray(x).ravel()", " range = (x.min(), x.max())", " mn, mx = [x+0.0 for x in range]", " n = x.sort().searchsorted(bins)", " n = concatenate([n, [len(x)]])", " return 1.0/(x.size*db) * n, bins", "def average(a, axis=0, weights=None, returned=0):", " \"\"\"average(a, axis=0, weights=None)", " Computes average along indicated axis.", " If axis is None, average over the entire array.", " Inputs can be integer or floating types; result is type Float.", "", " If weights are given, result is:", " sum(a*weights)/(sum(weights))", " weights must have a's shape or be the 1-d with length the size", " of a in the given axis. Integer weights are converted to Float.", " Not supplying weights is equivalent to supply weights that are", " all 1.", " If returned, return a tuple: the result and the sum of the weights", " or count of values. The shape of these two results will be the same.", " raises ZeroDivisionError if appropriate when result is scalar.", " (The version in MA does not -- it returns masked values).", " n = add.reduce(multiply(a,w))", " r[axis] = slice(None,None,1)", " raise ValueError, 'average: weights wrong shape.'", " raise ZeroDivisionError, 'Numeric.average, zero denominator'", "def asarray_chkfinite(x):", " \"\"\"Like asarray except it checks to be sure no NaNs or Infs are present.", " x = asarray(x)", " if (x.dtypechar in _nx.typecodes['AllFloat']) \\", " and (_nx.isnan(x).any() or _nx.isinf(x).any()):", " raise ValueError, \"array must not contain infs or nans\"", " return x", " \"\"\"Returns a piecewise-defined function.", " for k in range(1,n):", " \"\"\" Returns an array comprised from different elements of choicelist", " arrays in choicelist. If condlist is [c0,...,cN-1] then choicelist", " represented as [v0,...,vN-1]. The default choice if none of the", " Note, that one of the condition arrays must be large enough to handle", " choicelist.insert(0,default)", " for k in range(1,n+1):", "def _asarray1d(arr,copy=False):", " \"\"\"Ensure 1d array for one array.", " \"\"\"Return an array copy of the object.", " return array(a,copy=True)", "def amax(m,axis=-1):", " \"\"\"Returns the maximum of m along dimension axis.", " return asarray(m).max(axis)", "def amin(m,axis=-1):", " \"\"\"Returns the minimum of m along dimension axis.", " return asarray(m).min(axis)", "def alen(m):", " \"\"\"Returns the length of a Python object interpreted as an array", " return len(asarray(m))", "def ptp(m,axis=-1):", " \"\"\"Returns the maximum - minimum along the the given dimension", " return asarray(m).ptp(axis)", "def prod(m,axis=-1):", " \"\"\"Returns the product of the elements along the given axis", " return asarray(m).prod(axis)", "def cumprod(m,axis=-1):", " \"\"\"Returns the cumulative product of the elments along the given axis", " return asarray(m).cumprod(axis)", "def gradient(f,*varargs):", " # create slice objects --- initially all are [:,:,...,:]", " if otype not in ['f','d','F','D']:", " slice1[axis] = slice(1,-1)", " slice2[axis] = slice(2,None)", " slice3[axis] = slice(None,-2)", " # 1d equivalent -- out[1:-1] = (f[2:] - f[:-2])/2.0", " # 1d equivalent -- out[0] = (f[1] - f[0])", " # 1d equivalent -- out[-1] = (f[-1] - f[-2])", "def diff(x, n=1,axis=-1):", " \"\"\"Calculates the nth order, discrete difference along given axis.", " return x", " raise ValueError,'Order must be non-negative but got ' + `n`", " x = asarray(x)", " nd = len(x.shape)", " slice1[axis] = slice(1,None)", " slice2[axis] = slice(None,-1)", " return diff(x[slice1]-x[slice2], n-1, axis=axis)", " return x[slice1]-x[slice2]", "def angle(z,deg=0):", " \"\"\"Return the angle of complex argument z.\"\"\"", " return arctan2(zimag,zreal) * fact", "def unwrap(p,discont=pi,axis=-1):", " \"\"\"unwraps radian phase p by changing absolute jumps greater than", " discont to their 2*pi complement along the given axis.", " dd = diff(p,axis=axis)", " slice1 = [slice(None,None)]*nd # full slices", " slice1[axis] = slice(1,None)", " ddmod = mod(dd+pi,2*pi)-pi", " _nx.putmask(ddmod,(ddmod==-pi) & (dd > 0),pi)", " _nx.putmask(ph_correct,abs(dd)>> import scipy", " >>> a = array((0,0,0,1,2,3,2,1,0))", " >>> scipy.trim_zeros(a)", " array([1, 2, 3, 2, 1])", " \"\"\"Returns unique items in 1-dimensional sequence.", " \"\"\"Elements of ravel(arr) where ravel(condition) is true (1-d)", " Equivalent of compress(ravel(condition), ravel(arr))", " \"\"\"Similar to putmask arr[mask] = vals but 1d array vals has the", " same number of elements as the non-zero values of mask. Inverse of extract.", "def nansum(x,axis=-1):", " \"\"\"Sum the array over the given axis treating nans as 0", " y = array(x)", " y[isnan(x)] = 0", "def nanmin(x,axis=-1):", " \"\"\"Find the minimium over the given axis ignoring nans.", " y = array(x)", " y[isnan(x)] = _nx.inf", "def nanargmin(x,axis=-1):", " \"\"\"Find the indices of the minimium over the given axis ignoring nans.", " y = array(x)", " y[isnan(x)] = _nx.inf", "def nanmax(x,axis=-1):", " \"\"\"Find the maximum over the given axis ignoring nans.", " y = array(x)", " y[isnan(x)] = -_nx.inf", "def nanargmax(x,axis=-1):", " \"\"\"Find the maximum over the given axis ignoring nans.", " y = array(x)", " y[isnan(x)] = -_nx.inf", "def disp(mesg, device=None, linefeed=1):", " \"\"\"Display a message to device (default is sys.stdout) with(out) linefeed.", " def myfunc(a,b):", " >>> vfunc([1,2,3,4],2)", " array([3,4,1,2])", " def __init__(self,pyfunc,otypes='',doc=None):", " if isinstance(otypes,types.StringType):", " def __call__(self,*args):", " return tuple([x.astype(c) for x,c in zip(self.ufunc(*args), self.otypes)])", "def round_(x, decimals=0):", " \"\"\"round_(m, decimals=0) Rounds x to decimals places.", " Returns x if array is not floating point and rounds both the real", " and imaginary parts separately if array is complex. Rounds in the", " same way as standard Python.", " x = asarray(x)", " if not issubclass(x.dtype, _nx.inexact):", " return x", " if issubclass(x.dtype, _nx.complexfloating):", " return round_(x.real, decimals) + 1j*round_(x.imag, decimals)", " s = sign(x)", " x = absolute(multiply(x,10.**decimals))", " x = absolute(x)", " rem = x-asarray(x).astype(_nx.intp)", " x = _nx.where(_nx.less(rem,0.5), _nx.floor(x), _nx.ceil(x))", " return multiply(x,s/(10.**decimals))", " return multiply(x,s)" ] } }, { "old_path": "scipy/base/oldnumeric.py", "new_path": "scipy/base/oldnumeric.py", "filename": "oldnumeric.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -290,8 +290,26 @@ def clip(m, m_min, m_max):\n ## selector = less(m, m_min)+2*greater(m, m_max)\n ## return choose(selector, (m, m_min, m_max))\n \n-def sum (x, axis=0, rtype=None):\n- \"\"\"Sum the array over the given axis.\n+def sum(x, axis=0, rtype=None):\n+ \"\"\"Sum the array over the given axis. The optional rtype 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() rtype\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], rtype=Int32)\n+ 1\n+ >>> sum([[0, 1], [0, 5]])\n+ array([0, 6])\n+ >>> sum([[0, 1], [0, 5]], axis=1)\n+ array([1, 5])\n \"\"\"\n return asarray(x).sum(axis, rtype)\n \n", "added_lines": 20, "deleted_lines": 2, "source_code": "# Compatibility module containing deprecated names\n\nimport multiarray as mu\nimport umath as um\nimport numerictypes as nt\nfrom numeric import asarray, array, correlate, outer, concatenate\nimport sys\n_dt_ = nt.dtype2char\n\n#Use this to add a new axis to an array\n\n#compatibility only\nNewAxis = None\n#deprecated\n\nUFuncType = type(um.sin)\nArrayType = mu.ndarray\narraytype = ArrayType\nUfuncType = UFuncType\n\nLittleEndian = (sys.byteorder == 'little')\n\n\n# backward compatible names from old Precision.py\n\nCharacter = 'S1'\nUnsignedInt8 = _dt_(nt.uint8)\nUnsignedInt16 = _dt_(nt.uint16)\nUnsignedInt32 = _dt_(nt.uint32)\nUnsignedInt = _dt_(nt.uint)\n\ntypecodes = {'Character':'S1', 'Integer':'bhilq', 'UnsignedInteger':'BHILQ',\n 'Float':'fdg', 'Complex':'FDG', 'AllInteger':'bBhHiIlLqQ',\n 'AllFloat':'fdgFDG', 'All':'?bhilqBHILQfdgFDGSUVO'}\n\n\ndef sarray(a, dtype=None, copy=False):\n return array(a, dtype, copy)\n\ntry:\n UnsignedInt64 = _dt_(nt.uint64)\n UnsignedInt128 = _dt_(nt.uint128)\nexcept AttributeError:\n pass\n\nInt8 = _dt_(nt.int8)\nInt16 = _dt_(nt.int16)\nInt32 = _dt_(nt.int32)\n\ntry:\n Int64 = _dt_(nt.int64)\n Int128 = _dt_(nt.int128)\nexcept AttributeError:\n pass\n\nInt0 = _dt_(nt.int)\nInt = _dt_(nt.int)\nFloat0 = _dt_(nt.float)\nFloat = _dt_(nt.float)\nComplex0 = _dt_(nt.complex)\nComplex = _dt_(nt.complex)\nPyObject = _dt_(nt.object)\n\nFloat32 = _dt_(nt.float32)\nFloat64 = _dt_(nt.float64)\n\ntry:\n Float128 = _dt_(nt.float128)\nexcept AttributeError: \n pass\n\nComplex32 = _dt_(nt.complex64)\nComplex64 = _dt_(nt.complex128)\n\ntry:\n Complex128 = _dt_(nt.complex256)\nexcept AttributeError: \n pass\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 a = array(a,copy=False)\n v = array(v,copy=False)\n return a.put(a, ind, v.astype(a.dtype))\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(mask, v)\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=False)\n return a.sort(axis)\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 a = ravel(a)\n Na = len(a)\n if not Na: return zeros(new_shape, a.dtypechar)\n total_size = um.multiply.reduce(new_shape)\n n_copies = int(total_size / Na)\n extra = total_size % Na\n\n if 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\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## a = asarray(a)\n## nd = len(a.shape)\n## new_axes = range(nd)\n## if (axis1 < 0): axis1 += nd\n## if (axis2 < 0): axis2 += nd\n## try: \n## new_axes.remove(axis1) \n## new_axes.remove(axis2) \n## except ValueError: \n## raise ValueError, \"axis1(=%d) and axis2(=%d) must be different and within range.\" % (axis1, axis2) \n## new_axes = new_axes + [axis1, axis2] ### insert at the end, not the beginning\n## a = transpose(a, new_axes)\n## s = a.shape\n## rank = len(s) \n## if rank == 2:\n## n1 = s[0]\n## n2 = s[1]\n## n = n1 * n2\n## s = (n,)\n## a = reshape(a, s)\n## if offset < 0:\n## return take(a, range(- n2 * offset, min(n2, n1+offset) *\n## (n2+1) - n2 * offset, n2+1), axis=0)\n## else:\n## return take(a, range(offset, min(n1, n2-offset) *\n## (n2+1) + offset, n2+1), axis=0)\n## else:\n## my_diagonal = []\n## for i in range(s[0]):\n## my_diagonal.append(diagonal(a[i], offset, rank-3, rank-2)) ###\n## return array(my_diagonal)\n \n\ndef trace(a, offset=0, axis1=0, axis2=1, rtype=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, rtype)\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## return repeat(arange(len(a)), not_equal(a, 0))\n\ndef shape(a):\n \"\"\"shape(a) returns the shape of a (as a function call which\n also works on nested sequences).\n \"\"\"\n return asarray(a).shape\n\ndef compress(condition, m, axis=-1):\n \"\"\"compress(condition, x, axis=-1) = those elements of x corresponding \n to those elements of condition that are \"true\". condition must be the\n same size as the given dimension of x.\"\"\"\n return asarray(m).compress(condition, axis)\n\ndef clip(m, m_min, m_max):\n \"\"\"clip(m, m_min, m_max) = every entry in m that is less than m_min is\n replaced by m_min, and every entry greater than m_max is replaced by\n m_max.\n \"\"\"\n return asarray(m).clip(m_min, m_max)\n## selector = less(m, m_min)+2*greater(m, m_max)\n## return choose(selector, (m, m_min, m_max))\n\ndef sum(x, axis=0, rtype=None):\n \"\"\"Sum the array over the given axis. The optional rtype 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() rtype\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], rtype=Int32)\n 1\n >>> sum([[0, 1], [0, 5]])\n array([0, 6])\n >>> sum([[0, 1], [0, 5]], axis=1)\n array([1, 5])\n \"\"\"\n return asarray(x).sum(axis, rtype)\n\ndef product (x, axis=0, rtype=None):\n \"\"\"Product of the array elements over the given axis.\"\"\"\n return asarray(x).prod(axis, rtype)\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, rtype=None):\n \"\"\"Sum the array over the given axis.\"\"\"\n return asarray(x).cumsum(axis, rtype)\n\ndef cumproduct (x, axis=0, rtype=None):\n \"\"\"Sum the array over the given axis.\"\"\"\n return asarray(x).cumprod(axis, rtype)\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:\n return asarray(a).ndim\n\ndef shape (a):\n \"Get the shape of sequence a\"\n try:\n return a.shape\n except:\n return asarray(a).shape\n\ndef size (a, axis=None):\n \"Get the number of elements in sequence a, or along a certain axis.\"\n a = asarray(a)\n if axis is None:\n return a.size\n else:\n return a.shape[axis]\n\nfrom function_base import round_\naround = round_ \n", "source_code_before": "# Compatibility module containing deprecated names\n\nimport multiarray as mu\nimport umath as um\nimport numerictypes as nt\nfrom numeric import asarray, array, correlate, outer, concatenate\nimport sys\n_dt_ = nt.dtype2char\n\n#Use this to add a new axis to an array\n\n#compatibility only\nNewAxis = None\n#deprecated\n\nUFuncType = type(um.sin)\nArrayType = mu.ndarray\narraytype = ArrayType\nUfuncType = UFuncType\n\nLittleEndian = (sys.byteorder == 'little')\n\n\n# backward compatible names from old Precision.py\n\nCharacter = 'S1'\nUnsignedInt8 = _dt_(nt.uint8)\nUnsignedInt16 = _dt_(nt.uint16)\nUnsignedInt32 = _dt_(nt.uint32)\nUnsignedInt = _dt_(nt.uint)\n\ntypecodes = {'Character':'S1', 'Integer':'bhilq', 'UnsignedInteger':'BHILQ',\n 'Float':'fdg', 'Complex':'FDG', 'AllInteger':'bBhHiIlLqQ',\n 'AllFloat':'fdgFDG', 'All':'?bhilqBHILQfdgFDGSUVO'}\n\n\ndef sarray(a, dtype=None, copy=False):\n return array(a, dtype, copy)\n\ntry:\n UnsignedInt64 = _dt_(nt.uint64)\n UnsignedInt128 = _dt_(nt.uint128)\nexcept AttributeError:\n pass\n\nInt8 = _dt_(nt.int8)\nInt16 = _dt_(nt.int16)\nInt32 = _dt_(nt.int32)\n\ntry:\n Int64 = _dt_(nt.int64)\n Int128 = _dt_(nt.int128)\nexcept AttributeError:\n pass\n\nInt0 = _dt_(nt.int)\nInt = _dt_(nt.int)\nFloat0 = _dt_(nt.float)\nFloat = _dt_(nt.float)\nComplex0 = _dt_(nt.complex)\nComplex = _dt_(nt.complex)\nPyObject = _dt_(nt.object)\n\nFloat32 = _dt_(nt.float32)\nFloat64 = _dt_(nt.float64)\n\ntry:\n Float128 = _dt_(nt.float128)\nexcept AttributeError: \n pass\n\nComplex32 = _dt_(nt.complex64)\nComplex64 = _dt_(nt.complex128)\n\ntry:\n Complex128 = _dt_(nt.complex256)\nexcept AttributeError: \n pass\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 a = array(a,copy=False)\n v = array(v,copy=False)\n return a.put(a, ind, v.astype(a.dtype))\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(mask, v)\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=False)\n return a.sort(axis)\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 a = ravel(a)\n Na = len(a)\n if not Na: return zeros(new_shape, a.dtypechar)\n total_size = um.multiply.reduce(new_shape)\n n_copies = int(total_size / Na)\n extra = total_size % Na\n\n if 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\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## a = asarray(a)\n## nd = len(a.shape)\n## new_axes = range(nd)\n## if (axis1 < 0): axis1 += nd\n## if (axis2 < 0): axis2 += nd\n## try: \n## new_axes.remove(axis1) \n## new_axes.remove(axis2) \n## except ValueError: \n## raise ValueError, \"axis1(=%d) and axis2(=%d) must be different and within range.\" % (axis1, axis2) \n## new_axes = new_axes + [axis1, axis2] ### insert at the end, not the beginning\n## a = transpose(a, new_axes)\n## s = a.shape\n## rank = len(s) \n## if rank == 2:\n## n1 = s[0]\n## n2 = s[1]\n## n = n1 * n2\n## s = (n,)\n## a = reshape(a, s)\n## if offset < 0:\n## return take(a, range(- n2 * offset, min(n2, n1+offset) *\n## (n2+1) - n2 * offset, n2+1), axis=0)\n## else:\n## return take(a, range(offset, min(n1, n2-offset) *\n## (n2+1) + offset, n2+1), axis=0)\n## else:\n## my_diagonal = []\n## for i in range(s[0]):\n## my_diagonal.append(diagonal(a[i], offset, rank-3, rank-2)) ###\n## return array(my_diagonal)\n \n\ndef trace(a, offset=0, axis1=0, axis2=1, rtype=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, rtype)\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## return repeat(arange(len(a)), not_equal(a, 0))\n\ndef shape(a):\n \"\"\"shape(a) returns the shape of a (as a function call which\n also works on nested sequences).\n \"\"\"\n return asarray(a).shape\n\ndef compress(condition, m, axis=-1):\n \"\"\"compress(condition, x, axis=-1) = those elements of x corresponding \n to those elements of condition that are \"true\". condition must be the\n same size as the given dimension of x.\"\"\"\n return asarray(m).compress(condition, axis)\n\ndef clip(m, m_min, m_max):\n \"\"\"clip(m, m_min, m_max) = every entry in m that is less than m_min is\n replaced by m_min, and every entry greater than m_max is replaced by\n m_max.\n \"\"\"\n return asarray(m).clip(m_min, m_max)\n## selector = less(m, m_min)+2*greater(m, m_max)\n## return choose(selector, (m, m_min, m_max))\n\ndef sum (x, axis=0, rtype=None):\n \"\"\"Sum the array over the given axis.\n \"\"\"\n return asarray(x).sum(axis, rtype)\n\ndef product (x, axis=0, rtype=None):\n \"\"\"Product of the array elements over the given axis.\"\"\"\n return asarray(x).prod(axis, rtype)\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, rtype=None):\n \"\"\"Sum the array over the given axis.\"\"\"\n return asarray(x).cumsum(axis, rtype)\n\ndef cumproduct (x, axis=0, rtype=None):\n \"\"\"Sum the array over the given axis.\"\"\"\n return asarray(x).cumprod(axis, rtype)\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:\n return asarray(a).ndim\n\ndef shape (a):\n \"Get the shape of sequence a\"\n try:\n return a.shape\n except:\n return asarray(a).shape\n\ndef size (a, axis=None):\n \"Get the number of elements in sequence a, or along a certain axis.\"\n a = asarray(a)\n if axis is None:\n return a.size\n else:\n return a.shape[axis]\n\nfrom function_base import round_\naround = round_ \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": 37, "end_line": 38, "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": 93, "end_line": 95, "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": 97, "end_line": 100, "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": 102, "end_line": 104, "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": 106, "end_line": 115, "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": 4, "complexity": 1, "token_count": 48, "parameters": [ "a", "ind", "v" ], "start_line": 117, "end_line": 131, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "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": 133, "end_line": 138, "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": 140, "end_line": 145, "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": 147, "end_line": 153, "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": 3, "complexity": 1, "token_count": 28, "parameters": [ "a", "axis" ], "start_line": 155, "end_line": 159, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "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": 161, "end_line": 166, "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": 168, "end_line": 173, "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": 175, "end_line": 180, "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": 182, "end_line": 186, "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": 14, "complexity": 4, "token_count": 102, "parameters": [ "a", "new_shape" ], "start_line": 188, "end_line": 212, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "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": 215, "end_line": 219, "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 , rtype = None )", "filename": "oldnumeric.py", "nloc": 2, "complexity": 1, "token_count": 38, "parameters": [ "a", "offset", "axis1", "axis2", "rtype" ], "start_line": 253, "end_line": 257, "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": 259, "end_line": 263, "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": 265, "end_line": 269, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "shape", "long_name": "shape( a )", "filename": "oldnumeric.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "a" ], "start_line": 272, "end_line": 276, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "compress", "long_name": "compress( condition , m , axis = - 1 )", "filename": "oldnumeric.py", "nloc": 2, "complexity": 1, "token_count": 25, "parameters": [ "condition", "m", "axis" ], "start_line": 278, "end_line": 282, "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": 284, "end_line": 289, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "sum", "long_name": "sum( x , axis = 0 , rtype = None )", "filename": "oldnumeric.py", "nloc": 2, "complexity": 1, "token_count": 26, "parameters": [ "x", "axis", "rtype" ], "start_line": 293, "end_line": 314, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "product", "long_name": "product( x , axis = 0 , rtype = None )", "filename": "oldnumeric.py", "nloc": 2, "complexity": 1, "token_count": 26, "parameters": [ "x", "axis", "rtype" ], "start_line": 316, "end_line": 318, "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": 320, "end_line": 322, "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": 324, "end_line": 326, "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": 328, "end_line": 331, "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": 333, "end_line": 336, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "cumsum", "long_name": "cumsum( x , axis = 0 , rtype = None )", "filename": "oldnumeric.py", "nloc": 2, "complexity": 1, "token_count": 26, "parameters": [ "x", "axis", "rtype" ], "start_line": 338, "end_line": 340, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "cumproduct", "long_name": "cumproduct( x , axis = 0 , rtype = None )", "filename": "oldnumeric.py", "nloc": 2, "complexity": 1, "token_count": 26, "parameters": [ "x", "axis", "rtype" ], "start_line": 342, "end_line": 344, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "ndim", "long_name": "ndim( a )", "filename": "oldnumeric.py", "nloc": 5, "complexity": 2, "token_count": 21, "parameters": [ "a" ], "start_line": 346, "end_line": 350, "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": 21, "parameters": [ "a" ], "start_line": 352, "end_line": 359, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "shape", "long_name": "shape( a )", "filename": "oldnumeric.py", "nloc": 6, "complexity": 2, "token_count": 21, "parameters": [ "a" ], "start_line": 361, "end_line": 366, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "size", "long_name": "size( a , axis = None )", "filename": "oldnumeric.py", "nloc": 7, "complexity": 2, "token_count": 34, "parameters": [ "a", "axis" ], "start_line": 368, "end_line": 374, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "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": 37, "end_line": 38, "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": 93, "end_line": 95, "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": 97, "end_line": 100, "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": 102, "end_line": 104, "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": 106, "end_line": 115, "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": 4, "complexity": 1, "token_count": 48, "parameters": [ "a", "ind", "v" ], "start_line": 117, "end_line": 131, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "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": 133, "end_line": 138, "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": 140, "end_line": 145, "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": 147, "end_line": 153, "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": 3, "complexity": 1, "token_count": 28, "parameters": [ "a", "axis" ], "start_line": 155, "end_line": 159, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "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": 161, "end_line": 166, "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": 168, "end_line": 173, "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": 175, "end_line": 180, "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": 182, "end_line": 186, "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": 14, "complexity": 4, "token_count": 102, "parameters": [ "a", "new_shape" ], "start_line": 188, "end_line": 212, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "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": 215, "end_line": 219, "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 , rtype = None )", "filename": "oldnumeric.py", "nloc": 2, "complexity": 1, "token_count": 38, "parameters": [ "a", "offset", "axis1", "axis2", "rtype" ], "start_line": 253, "end_line": 257, "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": 259, "end_line": 263, "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": 265, "end_line": 269, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "shape", "long_name": "shape( a )", "filename": "oldnumeric.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "a" ], "start_line": 272, "end_line": 276, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "compress", "long_name": "compress( condition , m , axis = - 1 )", "filename": "oldnumeric.py", "nloc": 2, "complexity": 1, "token_count": 25, "parameters": [ "condition", "m", "axis" ], "start_line": 278, "end_line": 282, "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": 284, "end_line": 289, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "sum", "long_name": "sum( x , axis = 0 , rtype = None )", "filename": "oldnumeric.py", "nloc": 2, "complexity": 1, "token_count": 26, "parameters": [ "x", "axis", "rtype" ], "start_line": 293, "end_line": 296, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "product", "long_name": "product( x , axis = 0 , rtype = None )", "filename": "oldnumeric.py", "nloc": 2, "complexity": 1, "token_count": 26, "parameters": [ "x", "axis", "rtype" ], "start_line": 298, "end_line": 300, "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": 302, "end_line": 304, "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": 306, "end_line": 308, "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": 310, "end_line": 313, "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": 315, "end_line": 318, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "cumsum", "long_name": "cumsum( x , axis = 0 , rtype = None )", "filename": "oldnumeric.py", "nloc": 2, "complexity": 1, "token_count": 26, "parameters": [ "x", "axis", "rtype" ], "start_line": 320, "end_line": 322, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "cumproduct", "long_name": "cumproduct( x , axis = 0 , rtype = None )", "filename": "oldnumeric.py", "nloc": 2, "complexity": 1, "token_count": 26, "parameters": [ "x", "axis", "rtype" ], "start_line": 324, "end_line": 326, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "ndim", "long_name": "ndim( a )", "filename": "oldnumeric.py", "nloc": 5, "complexity": 2, "token_count": 21, "parameters": [ "a" ], "start_line": 328, "end_line": 332, "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": 21, "parameters": [ "a" ], "start_line": 334, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "shape", "long_name": "shape( a )", "filename": "oldnumeric.py", "nloc": 6, "complexity": 2, "token_count": 21, "parameters": [ "a" ], "start_line": 343, "end_line": 348, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "size", "long_name": "size( a , axis = None )", "filename": "oldnumeric.py", "nloc": 7, "complexity": 2, "token_count": 34, "parameters": [ "a", "axis" ], "start_line": 350, "end_line": 356, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "sum", "long_name": "sum( x , axis = 0 , rtype = None )", "filename": "oldnumeric.py", "nloc": 2, "complexity": 1, "token_count": 26, "parameters": [ "x", "axis", "rtype" ], "start_line": 293, "end_line": 314, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 } ], "nloc": 167, "complexity": 41, "token_count": 1304, "diff_parsed": { "added": [ "def sum(x, axis=0, rtype=None):", " \"\"\"Sum the array over the given axis. The optional rtype argument", " is the data type for intermediate calculations.", "", " The default is to upcast (promote) smaller integer types to the", " platform-dependent Int. For example, on 32-bit platforms:", "", " x.dtype default sum() rtype", " ---------------------------------------------------", " bool, Int8, Int16, Int32 Int32", "", " Examples:", " >>> sum([0.5, 1.5])", " 2.0", " >>> sum([0.5, 1.5], rtype=Int32)", " 1", " >>> sum([[0, 1], [0, 5]])", " array([0, 6])", " >>> sum([[0, 1], [0, 5]], axis=1)", " array([1, 5])" ], "deleted": [ "def sum (x, axis=0, rtype=None):", " \"\"\"Sum the array over the given axis." ] } }, { "old_path": "scipy/base/src/arraymethods.c", "new_path": "scipy/base/src/arraymethods.c", "filename": "arraymethods.c", "extension": "c", "change_type": "MODIFY", "diff": "@@ -606,12 +606,12 @@ array_repeat(PyArrayObject *self, PyObject *args, PyObject *kwds) {\n \treturn PyArray_Repeat(self, repeats, axis);\n }\n \n-static char doc_choose[] = \"self.choose(b0,b1,...,bn)\\n\"\\\n+static char doc_choose[] = \"a.choose(b0, b1, ..., bn)\\n\"\\\n \t\"\\n\"\\\n-\t\" Self sould be an integer array with entries from 0 to n+1, \\n\"\\\n-\t\" The bi arrays should be of the same shape as self. The result\\n\"\\\n-\t\" will be an array with elements chosen from the bi arrays\\n\"\\\n-\t\" according to the value at each position of self.\";\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 \n static PyObject *\n array_choose(PyArrayObject *self, PyObject *args) \n@@ -752,7 +752,7 @@ _setobject_pkl(PyArrayObject *self, PyObject *list)\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\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@@ -1031,7 +1031,26 @@ array_transpose(PyArrayObject *self, PyObject *args)\n \treturn _ARET(PyArray_Transpose(self, shape));\n }\n \n-static char doc_mean[] = \"a.mean(axis=None, rtype=None)\";\n+static char doc_mean[] = \"a.mean(axis=None, rtype=None)\\n\\n\"\\\n+ \"Average the array over the given axis. If axis is None, average over\\n\"\\\n+ \"all dimensions of the array.\\n\"\\\n+ \"\\n\"\\\n+ \"if 'a' has an integer type, the result has type Float.\\n\"\\\n+ \"\\n\"\\\n+ \"If an integer axis is given, this equals:\\n\"\\\n+ \" a.sum(axis, rtype) * 1.0 / len(a)\\n\"\\\n+ \"\\n\"\\ \n+ \"If axis is None, this equals:\\n\"\\\n+ \" a.sum(axis, rtype) * 1.0 / product(a.shape)\\n\"\\\n+\n+ \"The optional rtype argument is the data type for intermediate\\n\"\\\n+ \"calculations in the sum.\\n\"\\\n+ \"\\n\"\\\n+ \"If an integer axis is given, this equals:\\n\"\\\n+ \" a.sum(axis, rtype) * 1.0 / len(a)\\n\"\\\n+ \"\\n\"\\\n+ \"If axis is None, this equals:\\n\"\\\n+ \" a.sum(axis, rtype) * 1.0 / product(a.shape)\";\n \n static PyObject *\n array_mean(PyArrayObject *self, PyObject *args, PyObject *kwds) \n@@ -1048,7 +1067,27 @@ array_mean(PyArrayObject *self, PyObject *args, PyObject *kwds)\n \treturn _ARET(PyArray_Mean(self, axis, rtype.type_num));\n }\n \n-static char doc_sum[] = \"a.sum(axis=None, rtype=None)\";\n+static char doc_sum[] = \"a.sum(axis=None, rtype=None)\\n\\n\"\\\n+ \"Sum the array over the given axis. The optional rtype argument\\n\"\\\n+ \"is the data type for intermediate calculations.\\n\"\\\n+ \"\\n\"\\\n+ \"The default is to upcast (promote) smaller integer types to the\\n\"\\\n+ \"platform-dependent Int. For example, on 32-bit platforms:\\n\"\\\n+ \"\\n\"\\\n+ \" a.dtype default sum() rtype\\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(rtype=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 \n static PyObject *\n array_sum(PyArrayObject *self, PyObject *args, PyObject *kwds) \n", "added_lines": 47, "deleted_lines": 8, "source_code": "\n#define _ARET(x) PyArray_Return((PyArrayObject *)(x))\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(indices, values) 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[] = {\"indices\", \"values\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &indices, &values))\n\t\treturn NULL;\n\treturn PyArray_Put(self, indices, values);\n}\n\nstatic char doc_putmask[] = \"a.putmask(mask, values) 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[] = {\"mask\", \"values\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &mask, &values))\n\t\treturn NULL;\n\treturn PyArray_PutMask(self, mask, values);\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.\";\n\nstatic PyObject *\narray_view(PyArrayObject *self, PyObject *args)\n{\n PyArray_Typecode type = {PyArray_NOTYPE, 0, 0};\n\tif (!PyArg_ParseTuple(args, \"|O&\",\n PyArray_TypecodeConverter, &type)) \n return NULL;\n\n\treturn _ARET(PyArray_View(self, &type));\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.field(type, 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 items given.\";\n\nstatic PyObject *\nPyArray_GetField(PyArrayObject *self, PyArray_Typecode *type, \n\t\t\t\t int offset)\n{\n\tPyObject *ret=NULL;\n\tret = PyArray_New(self->ob_type, self->nd, self->dimensions,\n\t\t\t type->type_num, self->strides, \n\t\t\t self->data + offset,\n\t\t\t type->itemsize, self->flags, (PyObject *)self);\n\tif (ret == NULL) return NULL;\n\tPy_INCREF(self);\n\t((PyArrayObject *)ret)->base = (PyObject *)self;\n\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\n\treturn ret;\t\n}\n\nstatic PyObject *\narray_getfield(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n\tPyArray_Typecode typecode = {PyArray_NOTYPE, 0, 0};\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_TypecodeConverter, \n\t\t\t\t\t &typecode, &offset)) return NULL;\n\n\t\n\tif (typecode.itemsize > self->itemsize) {\n\t\tPyErr_SetString(PyExc_TypeError, \"field itemsize must be <=\"\\\n\t\t\t\t\"array itemsize\");\n\t\treturn NULL;\n\t}\n\treturn _ARET(PyArray_GetField(self, &typecode, offset));\n}\n\nstatic PyObject *\nPyArray_Byteswap(PyArrayObject *self, Bool inplace)\n{\n PyArrayObject *ret;\n\tintp size;\n\tPyArray_CopySwapNFunc *copyswapn;\n\tPyArrayIterObject *it;\n\n\tif (inplace) {\n\t\tcopyswapn = self->descr->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, self->itemsize);\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\t\n\t\t\twhile (it->index < it->size) {\n\t\t\t\tcopyswapn(it->dataptr, NULL, 1, 1, \n\t\t\t\t\t self->itemsize);\n\t\t\t\tPyArray_ITER_NEXT(it);\n\t\t\t}\n\t\t\tPy_DECREF(it);\n\t\t}\n\n\t\tif (self->flags & NOTSWAPPED) self->flags &= ~NOTSWAPPED;\n\t\telse self->flags |= NOTSWAPPED;\n\t\t\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n\telse {\n\t\tif ((ret = (PyArrayObject *)PyArray_Copy(self)) == NULL) \n\t\t\treturn NULL;\n\t\t\n\t\tsize = PyArray_SIZE(self);\n\t\t\n\t\t/* set the NOTSWAPPED flag to opposite self */\n\t\t/* ret is always notswapped, \n\t\t PyArray_Copy has already swapped if self was swapped */\n\n\t\tif (self->flags & NOTSWAPPED) {\n\t\t\tret->descr->copyswapn(ret->data, NULL, size, 1, ret->itemsize);\n\t\t\tret->flags &= ~NOTSWAPPED;\n\t\t}\n\t\telse { /* self was swapped, so now ret isn't */\n\t\t\tret->flags |= NOTSWAPPED;\n\t\t}\n\t\t\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.toscalar(). 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->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_Typecode typecode = {PyArray_NOTYPE, 0, 0};\n\t\n if (!PyArg_ParseTuple(args, \"O&\", PyArray_TypecodeConverter,\n\t\t\t &typecode)) return NULL;\n\n\tif (typecode.type_num == PyArray_NOTYPE ||\t\\\n\t typecode.type_num == PyArray_TYPE(self)) {\n\t\treturn _ARET(PyArray_Copy(self));\n\t}\n\treturn _ARET(PyArray_CastToType(self, &typecode));\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\tret = PyArray_New(self->ob_type, PyArray_NDIM(arr),\n\t\t\t PyArray_DIMS(arr), PyArray_TYPE(arr),\n\t\t\t PyArray_STRIDES(arr), PyArray_DATA(arr),\n\t\t\t PyArray_ITEMSIZE(arr), \n\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__(|type) just returns either a new reference to self if type is not given or a new array of type if type is different from the current type of the array.\";\n\nstatic PyObject *\narray_getarray(PyArrayObject *self, PyObject *args) \n{\n\tPyArray_Typecode newtype = {PyArray_NOTYPE, 0, 0};\n\tPyArray_Typecode oldtype = {PyArray_TYPE(self),\n\t\t\t\t PyArray_ITEMSIZE(self),\n\t\t\t\t 0};\n\tPyObject *ret;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\", &PyArray_TypecodeConverter,\n\t\t\t &newtype)) return NULL;\n\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\tnew = PyArray_New(subtype, PyArray_NDIM(self),\n\t\t\t\t PyArray_DIMS(self), PyArray_TYPE(self),\n\t\t\t\t PyArray_STRIDES(self), PyArray_DATA(self),\n\t\t\t\t PyArray_ITEMSIZE(self), \n\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.type_num == PyArray_NOTYPE ||\n\t PyArray_EquivalentTypes(&oldtype, &newtype)) {\n\t\treturn (PyObject *)self;\n\t}\n\telse {\n\t\tret = PyArray_CastToType(self, &newtype);\n\t\tPy_DECREF(self);\n\t\treturn ret;\n\t}\n}\n\nstatic char doc_copy[] = \"m.copy(). Return a copy of the array.\";\n\nstatic PyObject *\narray_copy(PyArrayObject *self, PyObject *args) \n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\t\n return _ARET(PyArray_Copy(self));\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\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 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()\";\n\nstatic PyObject *\narray_sort(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_Sort(self, axis));\n}\n\nstatic char doc_argsort[] = \"a.argsort()\\n\"\\\n\t\" Return the indexes into a that would sort it along the\"\\\n\t\" given axis (or if the sorting should be done\"\\\n\t\" in terms of a.flat\";\n\nstatic PyObject *\narray_argsort(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_ArgSort(self, axis));\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;\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 if (deepcopy == NULL) return NULL;\n Py_DECREF(copy);\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->itemsize;\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\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 *Bool, *thestr=NULL;\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(\"scipy.base.multiarray\");\n\tif (mod == NULL) return NULL;\n\tobj = PyObject_GetAttrString(mod, \"empty\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) return NULL;\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tPyTuple_SET_ITEM(ret, 1, \n\t\t\t Py_BuildValue(\"NNN\",\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,\n\t\t\t\t\t\t\t \"dtypechar\"),\n\t\t\t\t PyInt_FromLong((long) 0)));\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 string giving the typestr (> or < indicates byte order\n\t if swap is possibly needed)\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\"));\t\n\tPyTuple_SET_ITEM(state, 1, PyObject_GetAttrString((PyObject *)self, \n\t\t\t\t\t\t\t \"dtypestr\"));\n\tBool = (PyArray_ISFORTRAN(self) ? Py_True : Py_False);\n\tPy_INCREF(Bool);\n\tPyTuple_SET_ITEM(state, 2, Bool);\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 string giving the typestr (> or < indicates byte order\n\t if swap is possibly needed)\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 PyObject *\narray_setstate(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *shape;\n\tPyArray_Typecode typecode;\n\tlong fortran;\n\tPyObject *rawdata;\n\tchar *datastr;\n\tconst char *typestr;\n\tint len, typestrlen;\n\tint swap;\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!z#iO)\", &PyTuple_Type,\n\t\t\t &shape, &typestr, &typestrlen,\n\t\t\t &fortran, &rawdata))\n\t\treturn NULL;\n\n\tif (_array_typecode_fromstr((char *)typestr, &swap, &typecode) < 0)\n\t\treturn NULL;\n\n\tself->descr = PyArray_DescrFromType(typecode.type_num);\n\tself->itemsize = typecode.itemsize;\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->itemsize *\t\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->itemsize, 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\tself->base = rawdata;\n\t\tPy_INCREF(self->base);\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->itemsize);\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\n\tif (swap) self->flags &= ~NOTSWAPPED;\n\t\n\tPy_INCREF(Py_None);\n\treturn Py_None;\t\n}\n\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), \"rb\");\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\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\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\treturn _ARET(PyArray_Transpose(self, shape));\n}\n\nstatic char doc_mean[] = \"a.mean(axis=None, rtype=None)\\n\\n\"\\\n \"Average the array over the given axis. If axis is None, average over\\n\"\\\n \"all dimensions of the array.\\n\"\\\n \"\\n\"\\\n \"if 'a' has an integer type, the result has type Float.\\n\"\\\n \"\\n\"\\\n \"If an integer axis is given, this equals:\\n\"\\\n \" a.sum(axis, rtype) * 1.0 / len(a)\\n\"\\\n \"\\n\"\\ \n \"If axis is None, this equals:\\n\"\\\n \" a.sum(axis, rtype) * 1.0 / product(a.shape)\\n\"\\\n\n \"The optional rtype argument is the data type for intermediate\\n\"\\\n \"calculations in the sum.\\n\"\\\n \"\\n\"\\\n \"If an integer axis is given, this equals:\\n\"\\\n \" a.sum(axis, rtype) * 1.0 / len(a)\\n\"\\\n \"\\n\"\\\n \"If axis is None, this equals:\\n\"\\\n \" a.sum(axis, rtype) * 1.0 / product(a.shape)\";\n\nstatic PyObject *\narray_mean(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\n\treturn _ARET(PyArray_Mean(self, axis, rtype.type_num));\n}\n\nstatic char doc_sum[] = \"a.sum(axis=None, rtype=None)\\n\\n\"\\\n \"Sum the array over the given axis. The optional rtype argument\\n\"\\\n \"is the data type for intermediate calculations.\\n\"\\\n \"\\n\"\\\n \"The default is to upcast (promote) smaller integer types to the\\n\"\\\n \"platform-dependent Int. For example, on 32-bit platforms:\\n\"\\\n \"\\n\"\\\n \" a.dtype default sum() rtype\\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(rtype=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_Typecode rtype = {PyArray_NOTYPE, 0, 0};\t\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_Sum(self, axis, rtype.type_num);\n}\n\n\nstatic char doc_cumsum[] = \"a.cumsum(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_cumsum(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_CumSum(self, axis, rtype.type_num);\n}\n\nstatic char doc_prod[] = \"a.prod(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_prod(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_Prod(self, axis, rtype.type_num);\n}\n\n\nstatic char doc_cumprod[] = \"a.cumprod(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_cumprod(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_CumProd(self, axis, rtype.type_num);\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\n\nstatic char doc_stddev[] = \"a.std(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_stddev(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_Std(self, axis, rtype.type_num);\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, rtype=None)\";\n\nstatic PyObject *\narray_trace(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis1=0, axis2=1, offset=0;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"offset\", \"axis1\", \"axis2\", \"rtype\", 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_TypecodeConverter, &rtype))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Trace(self, offset, axis1, axis2, rtype.type_num));\n}\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\tBool fortran=FALSE;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\",\n\t\t\t PyArray_BoolConverter, &fortran)) \n\t\treturn 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\tBool fortran=FALSE;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_BoolConverter,\n\t\t\t &fortran)) return NULL;\n\n\treturn PyArray_Ravel(self, (int) fortran);\n}\n\n\n\nstatic char doc_setflags[] = \"a.setflags(write=None, swap=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\", \"swap\", \"align\", \"uic\", NULL};\n\tPyObject *write=Py_None;\n\tPyObject *swap=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, \"|OOOO\", kwlist,\n\t\t\t\t\t &write, &swap, &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 if (swap != Py_None) {\n if (PyObject_IsTrue(swap))\n self->flags &= ~NOTSWAPPED;\n else \n self->flags |= NOTSWAPPED;\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic PyMethodDef array_methods[] = {\n {\"tolist\",\t (PyCFunction)array_tolist,\t1, doc_tolist},\n {\"toscalar\", (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 {\"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, doc_sort},\n\t{\"argsort\",\t(PyCFunction)array_argsort, \n\t METH_VARARGS, 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{\"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 {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\n#undef _ARET\n\n\n", "source_code_before": "\n#define _ARET(x) PyArray_Return((PyArrayObject *)(x))\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(indices, values) 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[] = {\"indices\", \"values\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &indices, &values))\n\t\treturn NULL;\n\treturn PyArray_Put(self, indices, values);\n}\n\nstatic char doc_putmask[] = \"a.putmask(mask, values) 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[] = {\"mask\", \"values\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &mask, &values))\n\t\treturn NULL;\n\treturn PyArray_PutMask(self, mask, values);\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.\";\n\nstatic PyObject *\narray_view(PyArrayObject *self, PyObject *args)\n{\n PyArray_Typecode type = {PyArray_NOTYPE, 0, 0};\n\tif (!PyArg_ParseTuple(args, \"|O&\",\n PyArray_TypecodeConverter, &type)) \n return NULL;\n\n\treturn _ARET(PyArray_View(self, &type));\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.field(type, 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 items given.\";\n\nstatic PyObject *\nPyArray_GetField(PyArrayObject *self, PyArray_Typecode *type, \n\t\t\t\t int offset)\n{\n\tPyObject *ret=NULL;\n\tret = PyArray_New(self->ob_type, self->nd, self->dimensions,\n\t\t\t type->type_num, self->strides, \n\t\t\t self->data + offset,\n\t\t\t type->itemsize, self->flags, (PyObject *)self);\n\tif (ret == NULL) return NULL;\n\tPy_INCREF(self);\n\t((PyArrayObject *)ret)->base = (PyObject *)self;\n\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\n\treturn ret;\t\n}\n\nstatic PyObject *\narray_getfield(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n\tPyArray_Typecode typecode = {PyArray_NOTYPE, 0, 0};\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_TypecodeConverter, \n\t\t\t\t\t &typecode, &offset)) return NULL;\n\n\t\n\tif (typecode.itemsize > self->itemsize) {\n\t\tPyErr_SetString(PyExc_TypeError, \"field itemsize must be <=\"\\\n\t\t\t\t\"array itemsize\");\n\t\treturn NULL;\n\t}\n\treturn _ARET(PyArray_GetField(self, &typecode, offset));\n}\n\nstatic PyObject *\nPyArray_Byteswap(PyArrayObject *self, Bool inplace)\n{\n PyArrayObject *ret;\n\tintp size;\n\tPyArray_CopySwapNFunc *copyswapn;\n\tPyArrayIterObject *it;\n\n\tif (inplace) {\n\t\tcopyswapn = self->descr->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, self->itemsize);\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\t\n\t\t\twhile (it->index < it->size) {\n\t\t\t\tcopyswapn(it->dataptr, NULL, 1, 1, \n\t\t\t\t\t self->itemsize);\n\t\t\t\tPyArray_ITER_NEXT(it);\n\t\t\t}\n\t\t\tPy_DECREF(it);\n\t\t}\n\n\t\tif (self->flags & NOTSWAPPED) self->flags &= ~NOTSWAPPED;\n\t\telse self->flags |= NOTSWAPPED;\n\t\t\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n\telse {\n\t\tif ((ret = (PyArrayObject *)PyArray_Copy(self)) == NULL) \n\t\t\treturn NULL;\n\t\t\n\t\tsize = PyArray_SIZE(self);\n\t\t\n\t\t/* set the NOTSWAPPED flag to opposite self */\n\t\t/* ret is always notswapped, \n\t\t PyArray_Copy has already swapped if self was swapped */\n\n\t\tif (self->flags & NOTSWAPPED) {\n\t\t\tret->descr->copyswapn(ret->data, NULL, size, 1, ret->itemsize);\n\t\t\tret->flags &= ~NOTSWAPPED;\n\t\t}\n\t\telse { /* self was swapped, so now ret isn't */\n\t\t\tret->flags |= NOTSWAPPED;\n\t\t}\n\t\t\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.toscalar(). 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->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_Typecode typecode = {PyArray_NOTYPE, 0, 0};\n\t\n if (!PyArg_ParseTuple(args, \"O&\", PyArray_TypecodeConverter,\n\t\t\t &typecode)) return NULL;\n\n\tif (typecode.type_num == PyArray_NOTYPE ||\t\\\n\t typecode.type_num == PyArray_TYPE(self)) {\n\t\treturn _ARET(PyArray_Copy(self));\n\t}\n\treturn _ARET(PyArray_CastToType(self, &typecode));\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\tret = PyArray_New(self->ob_type, PyArray_NDIM(arr),\n\t\t\t PyArray_DIMS(arr), PyArray_TYPE(arr),\n\t\t\t PyArray_STRIDES(arr), PyArray_DATA(arr),\n\t\t\t PyArray_ITEMSIZE(arr), \n\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__(|type) just returns either a new reference to self if type is not given or a new array of type if type is different from the current type of the array.\";\n\nstatic PyObject *\narray_getarray(PyArrayObject *self, PyObject *args) \n{\n\tPyArray_Typecode newtype = {PyArray_NOTYPE, 0, 0};\n\tPyArray_Typecode oldtype = {PyArray_TYPE(self),\n\t\t\t\t PyArray_ITEMSIZE(self),\n\t\t\t\t 0};\n\tPyObject *ret;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\", &PyArray_TypecodeConverter,\n\t\t\t &newtype)) return NULL;\n\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\tnew = PyArray_New(subtype, PyArray_NDIM(self),\n\t\t\t\t PyArray_DIMS(self), PyArray_TYPE(self),\n\t\t\t\t PyArray_STRIDES(self), PyArray_DATA(self),\n\t\t\t\t PyArray_ITEMSIZE(self), \n\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.type_num == PyArray_NOTYPE ||\n\t PyArray_EquivalentTypes(&oldtype, &newtype)) {\n\t\treturn (PyObject *)self;\n\t}\n\telse {\n\t\tret = PyArray_CastToType(self, &newtype);\n\t\tPy_DECREF(self);\n\t\treturn ret;\n\t}\n}\n\nstatic char doc_copy[] = \"m.copy(). Return a copy of the array.\";\n\nstatic PyObject *\narray_copy(PyArrayObject *self, PyObject *args) \n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\t\n return _ARET(PyArray_Copy(self));\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\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 PyArray_Repeat(self, repeats, axis);\n}\n\nstatic char doc_choose[] = \"self.choose(b0,b1,...,bn)\\n\"\\\n\t\"\\n\"\\\n\t\" Self sould be an integer array with entries from 0 to n+1, \\n\"\\\n\t\" The bi arrays should be of the same shape as self. The result\\n\"\\\n\t\" will be an array with elements chosen from the bi arrays\\n\"\\\n\t\" according to the value at each position of self.\";\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()\";\n\nstatic PyObject *\narray_sort(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_Sort(self, axis));\n}\n\nstatic char doc_argsort[] = \"a.argsort()\\n\"\\\n\t\" Return the indexes into a that would sort it along the\"\\\n\t\" given axis (or if the sorting should be done\"\\\n\t\" in terms of a.flat\";\n\nstatic PyObject *\narray_argsort(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_ArgSort(self, axis));\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;\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 if (deepcopy == NULL) return NULL;\n Py_DECREF(copy);\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->itemsize;\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\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 *Bool, *thestr=NULL;\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(\"scipy.base.multiarray\");\n\tif (mod == NULL) return NULL;\n\tobj = PyObject_GetAttrString(mod, \"empty\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) return NULL;\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tPyTuple_SET_ITEM(ret, 1, \n\t\t\t Py_BuildValue(\"NNN\",\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,\n\t\t\t\t\t\t\t \"dtypechar\"),\n\t\t\t\t PyInt_FromLong((long) 0)));\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 string giving the typestr (> or < indicates byte order\n\t if swap is possibly needed)\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\"));\t\n\tPyTuple_SET_ITEM(state, 1, PyObject_GetAttrString((PyObject *)self, \n\t\t\t\t\t\t\t \"dtypestr\"));\n\tBool = (PyArray_ISFORTRAN(self) ? Py_True : Py_False);\n\tPy_INCREF(Bool);\n\tPyTuple_SET_ITEM(state, 2, Bool);\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 string giving the typestr (> or < indicates byte order\n\t if swap is possibly needed)\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 PyObject *\narray_setstate(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *shape;\n\tPyArray_Typecode typecode;\n\tlong fortran;\n\tPyObject *rawdata;\n\tchar *datastr;\n\tconst char *typestr;\n\tint len, typestrlen;\n\tint swap;\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!z#iO)\", &PyTuple_Type,\n\t\t\t &shape, &typestr, &typestrlen,\n\t\t\t &fortran, &rawdata))\n\t\treturn NULL;\n\n\tif (_array_typecode_fromstr((char *)typestr, &swap, &typecode) < 0)\n\t\treturn NULL;\n\n\tself->descr = PyArray_DescrFromType(typecode.type_num);\n\tself->itemsize = typecode.itemsize;\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->itemsize *\t\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->itemsize, 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\tself->base = rawdata;\n\t\tPy_INCREF(self->base);\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->itemsize);\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\n\tif (swap) self->flags &= ~NOTSWAPPED;\n\t\n\tPy_INCREF(Py_None);\n\treturn Py_None;\t\n}\n\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), \"rb\");\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\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\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\treturn _ARET(PyArray_Transpose(self, shape));\n}\n\nstatic char doc_mean[] = \"a.mean(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_mean(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\n\treturn _ARET(PyArray_Mean(self, axis, rtype.type_num));\n}\n\nstatic char doc_sum[] = \"a.sum(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_sum(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\t\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_Sum(self, axis, rtype.type_num);\n}\n\n\nstatic char doc_cumsum[] = \"a.cumsum(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_cumsum(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_CumSum(self, axis, rtype.type_num);\n}\n\nstatic char doc_prod[] = \"a.prod(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_prod(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_Prod(self, axis, rtype.type_num);\n}\n\n\nstatic char doc_cumprod[] = \"a.cumprod(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_cumprod(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_CumProd(self, axis, rtype.type_num);\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\n\nstatic char doc_stddev[] = \"a.std(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_stddev(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_Std(self, axis, rtype.type_num);\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, rtype=None)\";\n\nstatic PyObject *\narray_trace(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis1=0, axis2=1, offset=0;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"offset\", \"axis1\", \"axis2\", \"rtype\", 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_TypecodeConverter, &rtype))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Trace(self, offset, axis1, axis2, rtype.type_num));\n}\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\tBool fortran=FALSE;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\",\n\t\t\t PyArray_BoolConverter, &fortran)) \n\t\treturn 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\tBool fortran=FALSE;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_BoolConverter,\n\t\t\t &fortran)) return NULL;\n\n\treturn PyArray_Ravel(self, (int) fortran);\n}\n\n\n\nstatic char doc_setflags[] = \"a.setflags(write=None, swap=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\", \"swap\", \"align\", \"uic\", NULL};\n\tPyObject *write=Py_None;\n\tPyObject *swap=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, \"|OOOO\", kwlist,\n\t\t\t\t\t &write, &swap, &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 if (swap != Py_None) {\n if (PyObject_IsTrue(swap))\n self->flags &= ~NOTSWAPPED;\n else \n self->flags |= NOTSWAPPED;\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic PyMethodDef array_methods[] = {\n {\"tolist\",\t (PyCFunction)array_tolist,\t1, doc_tolist},\n {\"toscalar\", (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 {\"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, doc_sort},\n\t{\"argsort\",\t(PyCFunction)array_argsort, \n\t METH_VARARGS, 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{\"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 {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": 7, "end_line": 20, "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": 26, "end_line": 34, "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": 41, "end_line": 50, "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": 56, "end_line": 66, "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": 70, "end_line": 84, "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": 47, "complexity": 13, "token_count": 290, "parameters": [ "self", "args" ], "start_line": 92, "end_line": 141, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "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": 146, "end_line": 150, "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": 8, "complexity": 2, "token_count": 53, "parameters": [ "self", "args" ], "start_line": 157, "end_line": 165, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "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": 170, "end_line": 178, "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": 183, "end_line": 191, "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": 196, "end_line": 204, "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": 209, "end_line": 217, "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": 223, "end_line": 231, "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": 237, "end_line": 244, "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_Typecode * type , int offset)", "filename": "arraymethods.c", "nloc": 14, "complexity": 2, "token_count": 110, "parameters": [ "self", "type", "offset" ], "start_line": 252, "end_line": 265, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "array_getfield", "long_name": "array_getfield( PyArrayObject * self , PyObject * args , PyObject * kwds)", "filename": "arraymethods.c", "nloc": 15, "complexity": 3, "token_count": 110, "parameters": [ "self", "args", "kwds" ], "start_line": 268, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "PyArray_Byteswap", "long_name": "PyArray_Byteswap( PyArrayObject * self , Bool inplace)", "filename": "arraymethods.c", "nloc": 41, "complexity": 7, "token_count": 247, "parameters": [ "self", "inplace" ], "start_line": 288, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "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": 348, "end_line": 356, "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": 362, "end_line": 372, "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": 378, "end_line": 382, "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": 206, "parameters": [ "self", "args", "kwds" ], "start_line": 387, "end_line": 421, "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": 69, "parameters": [ "self", "args" ], "start_line": 427, "end_line": 436, "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": 11, "complexity": 4, "token_count": 82, "parameters": [ "self", "args" ], "start_line": 443, "end_line": 455, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "array_wraparray", "long_name": "array_wraparray( PyArrayObject * self , PyObject * args)", "filename": "arraymethods.c", "nloc": 25, "complexity": 4, "token_count": 144, "parameters": [ "self", "args" ], "start_line": 463, "end_line": 489, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "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": 493, "end_line": 497, "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": 242, "parameters": [ "self", "args" ], "start_line": 503, "end_line": 546, "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": 5, "complexity": 2, "token_count": 34, "parameters": [ "self", "args" ], "start_line": 551, "end_line": 556, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "array_resize", "long_name": "array_resize( PyArrayObject * self , PyObject * args)", "filename": "arraymethods.c", "nloc": 25, "complexity": 5, "token_count": 120, "parameters": [ "self", "args" ], "start_line": 564, "end_line": 589, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "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": 75, "parameters": [ "self", "args", "kwds" ], "start_line": 597, "end_line": 607, "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": 617, "end_line": 632, "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)", "filename": "arraymethods.c", "nloc": 7, "complexity": 2, "token_count": 46, "parameters": [ "self", "args" ], "start_line": 637, "end_line": 645, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "array_argsort", "long_name": "array_argsort( PyArrayObject * self , PyObject * args)", "filename": "arraymethods.c", "nloc": 7, "complexity": 2, "token_count": 46, "parameters": [ "self", "args" ], "start_line": 653, "end_line": 661, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "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": 673, "end_line": 680, "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": 685, "end_line": 718, "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": 722, "end_line": 741, "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": 113, "parameters": [ "self", "list" ], "start_line": 744, "end_line": 762, "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": 45, "complexity": 8, "token_count": 301, "parameters": [ "self", "args" ], "start_line": 768, "end_line": 831, "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": 88, "complexity": 17, "token_count": 534, "parameters": [ "self", "args" ], "start_line": 846, "end_line": 951, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 106, "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": 954, "end_line": 975, "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": 978, "end_line": 989, "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": 995, "end_line": 1006, "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": 1011, "end_line": 1016, "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": 9, "complexity": 3, "token_count": 65, "parameters": [ "self", "args" ], "start_line": 1022, "end_line": 1032, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "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": 89, "parameters": [ "self", "args", "kwds" ], "start_line": 1056, "end_line": 1068, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1093, "end_line": 1105, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1111, "end_line": 1123, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1128, "end_line": 1140, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1146, "end_line": 1158, "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": 1164, "end_line": 1172, "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": 1177, "end_line": 1185, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1191, "end_line": 1203, "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": 1208, "end_line": 1219, "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": 1225, "end_line": 1230, "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": 11, "complexity": 2, "token_count": 109, "parameters": [ "self", "args", "kwds" ], "start_line": 1236, "end_line": 1248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 1254, "end_line": 1264, "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": 1271, "end_line": 1277, "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": 1283, "end_line": 1293, "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": 8, "complexity": 2, "token_count": 46, "parameters": [ "self", "args" ], "start_line": 1298, "end_line": 1307, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "array_ravel", "long_name": "array_ravel( PyArrayObject * self , PyObject * args)", "filename": "arraymethods.c", "nloc": 7, "complexity": 2, "token_count": 46, "parameters": [ "self", "args" ], "start_line": 1312, "end_line": 1320, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "array_setflags", "long_name": "array_setflags( PyArrayObject * self , PyObject * args , PyObject * kwds)", "filename": "arraymethods.c", "nloc": 60, "complexity": 12, "token_count": 299, "parameters": [ "self", "args", "kwds" ], "start_line": 1330, "end_line": 1394, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 65, "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": 7, "end_line": 20, "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": 26, "end_line": 34, "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": 41, "end_line": 50, "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": 56, "end_line": 66, "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": 70, "end_line": 84, "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": 47, "complexity": 13, "token_count": 290, "parameters": [ "self", "args" ], "start_line": 92, "end_line": 141, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "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": 146, "end_line": 150, "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": 8, "complexity": 2, "token_count": 53, "parameters": [ "self", "args" ], "start_line": 157, "end_line": 165, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "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": 170, "end_line": 178, "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": 183, "end_line": 191, "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": 196, "end_line": 204, "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": 209, "end_line": 217, "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": 223, "end_line": 231, "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": 237, "end_line": 244, "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_Typecode * type , int offset)", "filename": "arraymethods.c", "nloc": 14, "complexity": 2, "token_count": 110, "parameters": [ "self", "type", "offset" ], "start_line": 252, "end_line": 265, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "array_getfield", "long_name": "array_getfield( PyArrayObject * self , PyObject * args , PyObject * kwds)", "filename": "arraymethods.c", "nloc": 15, "complexity": 3, "token_count": 110, "parameters": [ "self", "args", "kwds" ], "start_line": 268, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "PyArray_Byteswap", "long_name": "PyArray_Byteswap( PyArrayObject * self , Bool inplace)", "filename": "arraymethods.c", "nloc": 41, "complexity": 7, "token_count": 247, "parameters": [ "self", "inplace" ], "start_line": 288, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "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": 348, "end_line": 356, "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": 362, "end_line": 372, "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": 378, "end_line": 382, "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": 206, "parameters": [ "self", "args", "kwds" ], "start_line": 387, "end_line": 421, "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": 69, "parameters": [ "self", "args" ], "start_line": 427, "end_line": 436, "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": 11, "complexity": 4, "token_count": 82, "parameters": [ "self", "args" ], "start_line": 443, "end_line": 455, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "array_wraparray", "long_name": "array_wraparray( PyArrayObject * self , PyObject * args)", "filename": "arraymethods.c", "nloc": 25, "complexity": 4, "token_count": 144, "parameters": [ "self", "args" ], "start_line": 463, "end_line": 489, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "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": 493, "end_line": 497, "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": 242, "parameters": [ "self", "args" ], "start_line": 503, "end_line": 546, "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": 5, "complexity": 2, "token_count": 34, "parameters": [ "self", "args" ], "start_line": 551, "end_line": 556, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "array_resize", "long_name": "array_resize( PyArrayObject * self , PyObject * args)", "filename": "arraymethods.c", "nloc": 25, "complexity": 5, "token_count": 120, "parameters": [ "self", "args" ], "start_line": 564, "end_line": 589, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "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": 75, "parameters": [ "self", "args", "kwds" ], "start_line": 597, "end_line": 607, "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": 617, "end_line": 632, "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)", "filename": "arraymethods.c", "nloc": 7, "complexity": 2, "token_count": 46, "parameters": [ "self", "args" ], "start_line": 637, "end_line": 645, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "array_argsort", "long_name": "array_argsort( PyArrayObject * self , PyObject * args)", "filename": "arraymethods.c", "nloc": 7, "complexity": 2, "token_count": 46, "parameters": [ "self", "args" ], "start_line": 653, "end_line": 661, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "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": 673, "end_line": 680, "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": 685, "end_line": 718, "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": 722, "end_line": 741, "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": 113, "parameters": [ "self", "list" ], "start_line": 744, "end_line": 762, "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": 45, "complexity": 8, "token_count": 301, "parameters": [ "self", "args" ], "start_line": 768, "end_line": 831, "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": 88, "complexity": 17, "token_count": 534, "parameters": [ "self", "args" ], "start_line": 846, "end_line": 951, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 106, "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": 954, "end_line": 975, "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": 978, "end_line": 989, "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": 995, "end_line": 1006, "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": 1011, "end_line": 1016, "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": 9, "complexity": 3, "token_count": 65, "parameters": [ "self", "args" ], "start_line": 1022, "end_line": 1032, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "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": 89, "parameters": [ "self", "args", "kwds" ], "start_line": 1037, "end_line": 1049, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1054, "end_line": 1066, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1072, "end_line": 1084, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1089, "end_line": 1101, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1107, "end_line": 1119, "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": 1125, "end_line": 1133, "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": 1138, "end_line": 1146, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1152, "end_line": 1164, "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": 1169, "end_line": 1180, "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": 1186, "end_line": 1191, "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": 11, "complexity": 2, "token_count": 109, "parameters": [ "self", "args", "kwds" ], "start_line": 1197, "end_line": 1209, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 1215, "end_line": 1225, "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": 1232, "end_line": 1238, "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": 1244, "end_line": 1254, "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": 8, "complexity": 2, "token_count": 46, "parameters": [ "self", "args" ], "start_line": 1259, "end_line": 1268, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "array_ravel", "long_name": "array_ravel( PyArrayObject * self , PyObject * args)", "filename": "arraymethods.c", "nloc": 7, "complexity": 2, "token_count": 46, "parameters": [ "self", "args" ], "start_line": 1273, "end_line": 1281, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "array_setflags", "long_name": "array_setflags( PyArrayObject * self , PyObject * args , PyObject * kwds)", "filename": "arraymethods.c", "nloc": 60, "complexity": 12, "token_count": 299, "parameters": [ "self", "args", "kwds" ], "start_line": 1291, "end_line": 1355, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 65, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "_setobject_pkl", "long_name": "_setobject_pkl( PyArrayObject * self , PyObject * list)", "filename": "arraymethods.c", "nloc": 17, "complexity": 3, "token_count": 113, "parameters": [ "self", "list" ], "start_line": 744, "end_line": 762, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 } ], "nloc": 1195, "complexity": 205, "token_count": 7439, "diff_parsed": { "added": [ "static char doc_choose[] = \"a.choose(b0, b1, ..., bn)\\n\"\\", "\t\"Return an array with elements chosen from 'a' at the positions\\n\"\\", " \"of the given arrays b_i. The array 'a' should be an integer array\\n\"\\", " \"with entries from 0 to n+1, and the b_i arrays should have the same\\n\"\\", " \"shape as 'a'.\";", "\t\ttheobject = PyList_GET_ITEM(list, (int) iter->index);", "static char doc_mean[] = \"a.mean(axis=None, rtype=None)\\n\\n\"\\", " \"Average the array over the given axis. If axis is None, average over\\n\"\\", " \"all dimensions of the array.\\n\"\\", " \"\\n\"\\", " \"if 'a' has an integer type, the result has type Float.\\n\"\\", " \"\\n\"\\", " \"If an integer axis is given, this equals:\\n\"\\", " \" a.sum(axis, rtype) * 1.0 / len(a)\\n\"\\", " \"\\n\"\\", " \"If axis is None, this equals:\\n\"\\", " \" a.sum(axis, rtype) * 1.0 / product(a.shape)\\n\"\\", "", " \"The optional rtype argument is the data type for intermediate\\n\"\\", " \"calculations in the sum.\\n\"\\", " \"\\n\"\\", " \"If an integer axis is given, this equals:\\n\"\\", " \" a.sum(axis, rtype) * 1.0 / len(a)\\n\"\\", " \"\\n\"\\", " \"If axis is None, this equals:\\n\"\\", " \" a.sum(axis, rtype) * 1.0 / product(a.shape)\";", "static char doc_sum[] = \"a.sum(axis=None, rtype=None)\\n\\n\"\\", " \"Sum the array over the given axis. The optional rtype 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\"\\", " \" a.dtype default sum() rtype\\n\"\\", " \" ---------------------------------------------------\\n\"\\", " \" bool, Int8, Int16, Int32 Int32\\n\"\\", " \"\\n\"\\", " \"Examples:\\n\"\\", " \"\\n\"\\", " \">>> array([0.5, 1.5]).sum()\\n\"\\", " \"2.0\\n\"\\", " \">>> array([0.5, 1.5].sum(rtype=Int32)\\n\"\\", " \"1\\n\"\\", " \">>> array([[0, 1], [0, 5]]).sum()\\n\"\\", " \"array([0, 6])\\n\"\\", " \">>> array([[0, 1], [0, 5]]).sum(axis=1)\\n\"\\", " \"array([1, 5])\";" ], "deleted": [ "static char doc_choose[] = \"self.choose(b0,b1,...,bn)\\n\"\\", "\t\" Self sould be an integer array with entries from 0 to n+1, \\n\"\\", "\t\" The bi arrays should be of the same shape as self. The result\\n\"\\", "\t\" will be an array with elements chosen from the bi arrays\\n\"\\", "\t\" according to the value at each position of self.\";", "\t\ttheobject = PyList_GET_ITEM(list,(int) iter->index);", "static char doc_mean[] = \"a.mean(axis=None, rtype=None)\";", "static char doc_sum[] = \"a.sum(axis=None, rtype=None)\";" ] } } ] }, { "hash": "fa94504b1eee72c89ebe4503969781ebf903c3b7", "msg": "Trivial changes to a.mean() docstring", "author": { "name": "edschofield", "email": "edschofield@localhost" }, "committer": { "name": "edschofield", "email": "edschofield@localhost" }, "author_date": "2005-10-27T14:17:47+00:00", "author_timezone": 0, "committer_date": "2005-10-27T14:17:47+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "6d634976e0d55422ab4c2bdd771078050fe5744d" ], "project_name": "repo_copy", "project_path": "/tmp/tmpn4cqam_6/repo_copy", "deletions": 2, "insertions": 2, "lines": 4, "files": 1, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "scipy/base/src/arraymethods.c", "new_path": "scipy/base/src/arraymethods.c", "filename": "arraymethods.c", "extension": "c", "change_type": "MODIFY", "diff": "@@ -1039,10 +1039,10 @@ static char doc_mean[] = \"a.mean(axis=None, rtype=None)\\n\\n\"\\\n \"\\n\"\\\n \"If an integer axis is given, this equals:\\n\"\\\n \" a.sum(axis, rtype) * 1.0 / len(a)\\n\"\\\n- \"\\n\"\\ \n+ \"\\n\"\\\n \"If axis is None, this equals:\\n\"\\\n \" a.sum(axis, rtype) * 1.0 / product(a.shape)\\n\"\\\n-\n+ \"\\n\"\\\n \"The optional rtype argument is the data type for intermediate\\n\"\\\n \"calculations in the sum.\\n\"\\\n \"\\n\"\\\n", "added_lines": 2, "deleted_lines": 2, "source_code": "\n#define _ARET(x) PyArray_Return((PyArrayObject *)(x))\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(indices, values) 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[] = {\"indices\", \"values\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &indices, &values))\n\t\treturn NULL;\n\treturn PyArray_Put(self, indices, values);\n}\n\nstatic char doc_putmask[] = \"a.putmask(mask, values) 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[] = {\"mask\", \"values\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &mask, &values))\n\t\treturn NULL;\n\treturn PyArray_PutMask(self, mask, values);\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.\";\n\nstatic PyObject *\narray_view(PyArrayObject *self, PyObject *args)\n{\n PyArray_Typecode type = {PyArray_NOTYPE, 0, 0};\n\tif (!PyArg_ParseTuple(args, \"|O&\",\n PyArray_TypecodeConverter, &type)) \n return NULL;\n\n\treturn _ARET(PyArray_View(self, &type));\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.field(type, 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 items given.\";\n\nstatic PyObject *\nPyArray_GetField(PyArrayObject *self, PyArray_Typecode *type, \n\t\t\t\t int offset)\n{\n\tPyObject *ret=NULL;\n\tret = PyArray_New(self->ob_type, self->nd, self->dimensions,\n\t\t\t type->type_num, self->strides, \n\t\t\t self->data + offset,\n\t\t\t type->itemsize, self->flags, (PyObject *)self);\n\tif (ret == NULL) return NULL;\n\tPy_INCREF(self);\n\t((PyArrayObject *)ret)->base = (PyObject *)self;\n\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\n\treturn ret;\t\n}\n\nstatic PyObject *\narray_getfield(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n\tPyArray_Typecode typecode = {PyArray_NOTYPE, 0, 0};\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_TypecodeConverter, \n\t\t\t\t\t &typecode, &offset)) return NULL;\n\n\t\n\tif (typecode.itemsize > self->itemsize) {\n\t\tPyErr_SetString(PyExc_TypeError, \"field itemsize must be <=\"\\\n\t\t\t\t\"array itemsize\");\n\t\treturn NULL;\n\t}\n\treturn _ARET(PyArray_GetField(self, &typecode, offset));\n}\n\nstatic PyObject *\nPyArray_Byteswap(PyArrayObject *self, Bool inplace)\n{\n PyArrayObject *ret;\n\tintp size;\n\tPyArray_CopySwapNFunc *copyswapn;\n\tPyArrayIterObject *it;\n\n\tif (inplace) {\n\t\tcopyswapn = self->descr->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, self->itemsize);\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\t\n\t\t\twhile (it->index < it->size) {\n\t\t\t\tcopyswapn(it->dataptr, NULL, 1, 1, \n\t\t\t\t\t self->itemsize);\n\t\t\t\tPyArray_ITER_NEXT(it);\n\t\t\t}\n\t\t\tPy_DECREF(it);\n\t\t}\n\n\t\tif (self->flags & NOTSWAPPED) self->flags &= ~NOTSWAPPED;\n\t\telse self->flags |= NOTSWAPPED;\n\t\t\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n\telse {\n\t\tif ((ret = (PyArrayObject *)PyArray_Copy(self)) == NULL) \n\t\t\treturn NULL;\n\t\t\n\t\tsize = PyArray_SIZE(self);\n\t\t\n\t\t/* set the NOTSWAPPED flag to opposite self */\n\t\t/* ret is always notswapped, \n\t\t PyArray_Copy has already swapped if self was swapped */\n\n\t\tif (self->flags & NOTSWAPPED) {\n\t\t\tret->descr->copyswapn(ret->data, NULL, size, 1, ret->itemsize);\n\t\t\tret->flags &= ~NOTSWAPPED;\n\t\t}\n\t\telse { /* self was swapped, so now ret isn't */\n\t\t\tret->flags |= NOTSWAPPED;\n\t\t}\n\t\t\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.toscalar(). 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->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_Typecode typecode = {PyArray_NOTYPE, 0, 0};\n\t\n if (!PyArg_ParseTuple(args, \"O&\", PyArray_TypecodeConverter,\n\t\t\t &typecode)) return NULL;\n\n\tif (typecode.type_num == PyArray_NOTYPE ||\t\\\n\t typecode.type_num == PyArray_TYPE(self)) {\n\t\treturn _ARET(PyArray_Copy(self));\n\t}\n\treturn _ARET(PyArray_CastToType(self, &typecode));\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\tret = PyArray_New(self->ob_type, PyArray_NDIM(arr),\n\t\t\t PyArray_DIMS(arr), PyArray_TYPE(arr),\n\t\t\t PyArray_STRIDES(arr), PyArray_DATA(arr),\n\t\t\t PyArray_ITEMSIZE(arr), \n\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__(|type) just returns either a new reference to self if type is not given or a new array of type if type is different from the current type of the array.\";\n\nstatic PyObject *\narray_getarray(PyArrayObject *self, PyObject *args) \n{\n\tPyArray_Typecode newtype = {PyArray_NOTYPE, 0, 0};\n\tPyArray_Typecode oldtype = {PyArray_TYPE(self),\n\t\t\t\t PyArray_ITEMSIZE(self),\n\t\t\t\t 0};\n\tPyObject *ret;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\", &PyArray_TypecodeConverter,\n\t\t\t &newtype)) return NULL;\n\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\tnew = PyArray_New(subtype, PyArray_NDIM(self),\n\t\t\t\t PyArray_DIMS(self), PyArray_TYPE(self),\n\t\t\t\t PyArray_STRIDES(self), PyArray_DATA(self),\n\t\t\t\t PyArray_ITEMSIZE(self), \n\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.type_num == PyArray_NOTYPE ||\n\t PyArray_EquivalentTypes(&oldtype, &newtype)) {\n\t\treturn (PyObject *)self;\n\t}\n\telse {\n\t\tret = PyArray_CastToType(self, &newtype);\n\t\tPy_DECREF(self);\n\t\treturn ret;\n\t}\n}\n\nstatic char doc_copy[] = \"m.copy(). Return a copy of the array.\";\n\nstatic PyObject *\narray_copy(PyArrayObject *self, PyObject *args) \n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\t\n return _ARET(PyArray_Copy(self));\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\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 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()\";\n\nstatic PyObject *\narray_sort(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_Sort(self, axis));\n}\n\nstatic char doc_argsort[] = \"a.argsort()\\n\"\\\n\t\" Return the indexes into a that would sort it along the\"\\\n\t\" given axis (or if the sorting should be done\"\\\n\t\" in terms of a.flat\";\n\nstatic PyObject *\narray_argsort(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_ArgSort(self, axis));\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;\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 if (deepcopy == NULL) return NULL;\n Py_DECREF(copy);\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->itemsize;\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\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 *Bool, *thestr=NULL;\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(\"scipy.base.multiarray\");\n\tif (mod == NULL) return NULL;\n\tobj = PyObject_GetAttrString(mod, \"empty\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) return NULL;\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tPyTuple_SET_ITEM(ret, 1, \n\t\t\t Py_BuildValue(\"NNN\",\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,\n\t\t\t\t\t\t\t \"dtypechar\"),\n\t\t\t\t PyInt_FromLong((long) 0)));\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 string giving the typestr (> or < indicates byte order\n\t if swap is possibly needed)\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\"));\t\n\tPyTuple_SET_ITEM(state, 1, PyObject_GetAttrString((PyObject *)self, \n\t\t\t\t\t\t\t \"dtypestr\"));\n\tBool = (PyArray_ISFORTRAN(self) ? Py_True : Py_False);\n\tPy_INCREF(Bool);\n\tPyTuple_SET_ITEM(state, 2, Bool);\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 string giving the typestr (> or < indicates byte order\n\t if swap is possibly needed)\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 PyObject *\narray_setstate(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *shape;\n\tPyArray_Typecode typecode;\n\tlong fortran;\n\tPyObject *rawdata;\n\tchar *datastr;\n\tconst char *typestr;\n\tint len, typestrlen;\n\tint swap;\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!z#iO)\", &PyTuple_Type,\n\t\t\t &shape, &typestr, &typestrlen,\n\t\t\t &fortran, &rawdata))\n\t\treturn NULL;\n\n\tif (_array_typecode_fromstr((char *)typestr, &swap, &typecode) < 0)\n\t\treturn NULL;\n\n\tself->descr = PyArray_DescrFromType(typecode.type_num);\n\tself->itemsize = typecode.itemsize;\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->itemsize *\t\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->itemsize, 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\tself->base = rawdata;\n\t\tPy_INCREF(self->base);\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->itemsize);\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\n\tif (swap) self->flags &= ~NOTSWAPPED;\n\t\n\tPy_INCREF(Py_None);\n\treturn Py_None;\t\n}\n\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), \"rb\");\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\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\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\treturn _ARET(PyArray_Transpose(self, shape));\n}\n\nstatic char doc_mean[] = \"a.mean(axis=None, rtype=None)\\n\\n\"\\\n \"Average the array over the given axis. If axis is None, average over\\n\"\\\n \"all dimensions of the array.\\n\"\\\n \"\\n\"\\\n \"if 'a' has an integer type, the result has type Float.\\n\"\\\n \"\\n\"\\\n \"If an integer axis is given, this equals:\\n\"\\\n \" a.sum(axis, rtype) * 1.0 / len(a)\\n\"\\\n \"\\n\"\\\n \"If axis is None, this equals:\\n\"\\\n \" a.sum(axis, rtype) * 1.0 / product(a.shape)\\n\"\\\n \"\\n\"\\\n \"The optional rtype argument is the data type for intermediate\\n\"\\\n \"calculations in the sum.\\n\"\\\n \"\\n\"\\\n \"If an integer axis is given, this equals:\\n\"\\\n \" a.sum(axis, rtype) * 1.0 / len(a)\\n\"\\\n \"\\n\"\\\n \"If axis is None, this equals:\\n\"\\\n \" a.sum(axis, rtype) * 1.0 / product(a.shape)\";\n\nstatic PyObject *\narray_mean(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\n\treturn _ARET(PyArray_Mean(self, axis, rtype.type_num));\n}\n\nstatic char doc_sum[] = \"a.sum(axis=None, rtype=None)\\n\\n\"\\\n \"Sum the array over the given axis. The optional rtype argument\\n\"\\\n \"is the data type for intermediate calculations.\\n\"\\\n \"\\n\"\\\n \"The default is to upcast (promote) smaller integer types to the\\n\"\\\n \"platform-dependent Int. For example, on 32-bit platforms:\\n\"\\\n \"\\n\"\\\n \" a.dtype default sum() rtype\\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(rtype=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_Typecode rtype = {PyArray_NOTYPE, 0, 0};\t\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_Sum(self, axis, rtype.type_num);\n}\n\n\nstatic char doc_cumsum[] = \"a.cumsum(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_cumsum(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_CumSum(self, axis, rtype.type_num);\n}\n\nstatic char doc_prod[] = \"a.prod(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_prod(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_Prod(self, axis, rtype.type_num);\n}\n\n\nstatic char doc_cumprod[] = \"a.cumprod(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_cumprod(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_CumProd(self, axis, rtype.type_num);\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\n\nstatic char doc_stddev[] = \"a.std(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_stddev(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_Std(self, axis, rtype.type_num);\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, rtype=None)\";\n\nstatic PyObject *\narray_trace(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis1=0, axis2=1, offset=0;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"offset\", \"axis1\", \"axis2\", \"rtype\", 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_TypecodeConverter, &rtype))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Trace(self, offset, axis1, axis2, rtype.type_num));\n}\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\tBool fortran=FALSE;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\",\n\t\t\t PyArray_BoolConverter, &fortran)) \n\t\treturn 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\tBool fortran=FALSE;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_BoolConverter,\n\t\t\t &fortran)) return NULL;\n\n\treturn PyArray_Ravel(self, (int) fortran);\n}\n\n\n\nstatic char doc_setflags[] = \"a.setflags(write=None, swap=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\", \"swap\", \"align\", \"uic\", NULL};\n\tPyObject *write=Py_None;\n\tPyObject *swap=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, \"|OOOO\", kwlist,\n\t\t\t\t\t &write, &swap, &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 if (swap != Py_None) {\n if (PyObject_IsTrue(swap))\n self->flags &= ~NOTSWAPPED;\n else \n self->flags |= NOTSWAPPED;\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic PyMethodDef array_methods[] = {\n {\"tolist\",\t (PyCFunction)array_tolist,\t1, doc_tolist},\n {\"toscalar\", (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 {\"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, doc_sort},\n\t{\"argsort\",\t(PyCFunction)array_argsort, \n\t METH_VARARGS, 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{\"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 {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\n#undef _ARET\n\n\n", "source_code_before": "\n#define _ARET(x) PyArray_Return((PyArrayObject *)(x))\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(indices, values) 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[] = {\"indices\", \"values\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &indices, &values))\n\t\treturn NULL;\n\treturn PyArray_Put(self, indices, values);\n}\n\nstatic char doc_putmask[] = \"a.putmask(mask, values) 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[] = {\"mask\", \"values\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &mask, &values))\n\t\treturn NULL;\n\treturn PyArray_PutMask(self, mask, values);\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.\";\n\nstatic PyObject *\narray_view(PyArrayObject *self, PyObject *args)\n{\n PyArray_Typecode type = {PyArray_NOTYPE, 0, 0};\n\tif (!PyArg_ParseTuple(args, \"|O&\",\n PyArray_TypecodeConverter, &type)) \n return NULL;\n\n\treturn _ARET(PyArray_View(self, &type));\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.field(type, 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 items given.\";\n\nstatic PyObject *\nPyArray_GetField(PyArrayObject *self, PyArray_Typecode *type, \n\t\t\t\t int offset)\n{\n\tPyObject *ret=NULL;\n\tret = PyArray_New(self->ob_type, self->nd, self->dimensions,\n\t\t\t type->type_num, self->strides, \n\t\t\t self->data + offset,\n\t\t\t type->itemsize, self->flags, (PyObject *)self);\n\tif (ret == NULL) return NULL;\n\tPy_INCREF(self);\n\t((PyArrayObject *)ret)->base = (PyObject *)self;\n\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\n\treturn ret;\t\n}\n\nstatic PyObject *\narray_getfield(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n\tPyArray_Typecode typecode = {PyArray_NOTYPE, 0, 0};\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_TypecodeConverter, \n\t\t\t\t\t &typecode, &offset)) return NULL;\n\n\t\n\tif (typecode.itemsize > self->itemsize) {\n\t\tPyErr_SetString(PyExc_TypeError, \"field itemsize must be <=\"\\\n\t\t\t\t\"array itemsize\");\n\t\treturn NULL;\n\t}\n\treturn _ARET(PyArray_GetField(self, &typecode, offset));\n}\n\nstatic PyObject *\nPyArray_Byteswap(PyArrayObject *self, Bool inplace)\n{\n PyArrayObject *ret;\n\tintp size;\n\tPyArray_CopySwapNFunc *copyswapn;\n\tPyArrayIterObject *it;\n\n\tif (inplace) {\n\t\tcopyswapn = self->descr->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, self->itemsize);\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\t\n\t\t\twhile (it->index < it->size) {\n\t\t\t\tcopyswapn(it->dataptr, NULL, 1, 1, \n\t\t\t\t\t self->itemsize);\n\t\t\t\tPyArray_ITER_NEXT(it);\n\t\t\t}\n\t\t\tPy_DECREF(it);\n\t\t}\n\n\t\tif (self->flags & NOTSWAPPED) self->flags &= ~NOTSWAPPED;\n\t\telse self->flags |= NOTSWAPPED;\n\t\t\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n\telse {\n\t\tif ((ret = (PyArrayObject *)PyArray_Copy(self)) == NULL) \n\t\t\treturn NULL;\n\t\t\n\t\tsize = PyArray_SIZE(self);\n\t\t\n\t\t/* set the NOTSWAPPED flag to opposite self */\n\t\t/* ret is always notswapped, \n\t\t PyArray_Copy has already swapped if self was swapped */\n\n\t\tif (self->flags & NOTSWAPPED) {\n\t\t\tret->descr->copyswapn(ret->data, NULL, size, 1, ret->itemsize);\n\t\t\tret->flags &= ~NOTSWAPPED;\n\t\t}\n\t\telse { /* self was swapped, so now ret isn't */\n\t\t\tret->flags |= NOTSWAPPED;\n\t\t}\n\t\t\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.toscalar(). 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->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_Typecode typecode = {PyArray_NOTYPE, 0, 0};\n\t\n if (!PyArg_ParseTuple(args, \"O&\", PyArray_TypecodeConverter,\n\t\t\t &typecode)) return NULL;\n\n\tif (typecode.type_num == PyArray_NOTYPE ||\t\\\n\t typecode.type_num == PyArray_TYPE(self)) {\n\t\treturn _ARET(PyArray_Copy(self));\n\t}\n\treturn _ARET(PyArray_CastToType(self, &typecode));\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\tret = PyArray_New(self->ob_type, PyArray_NDIM(arr),\n\t\t\t PyArray_DIMS(arr), PyArray_TYPE(arr),\n\t\t\t PyArray_STRIDES(arr), PyArray_DATA(arr),\n\t\t\t PyArray_ITEMSIZE(arr), \n\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__(|type) just returns either a new reference to self if type is not given or a new array of type if type is different from the current type of the array.\";\n\nstatic PyObject *\narray_getarray(PyArrayObject *self, PyObject *args) \n{\n\tPyArray_Typecode newtype = {PyArray_NOTYPE, 0, 0};\n\tPyArray_Typecode oldtype = {PyArray_TYPE(self),\n\t\t\t\t PyArray_ITEMSIZE(self),\n\t\t\t\t 0};\n\tPyObject *ret;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\", &PyArray_TypecodeConverter,\n\t\t\t &newtype)) return NULL;\n\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\tnew = PyArray_New(subtype, PyArray_NDIM(self),\n\t\t\t\t PyArray_DIMS(self), PyArray_TYPE(self),\n\t\t\t\t PyArray_STRIDES(self), PyArray_DATA(self),\n\t\t\t\t PyArray_ITEMSIZE(self), \n\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.type_num == PyArray_NOTYPE ||\n\t PyArray_EquivalentTypes(&oldtype, &newtype)) {\n\t\treturn (PyObject *)self;\n\t}\n\telse {\n\t\tret = PyArray_CastToType(self, &newtype);\n\t\tPy_DECREF(self);\n\t\treturn ret;\n\t}\n}\n\nstatic char doc_copy[] = \"m.copy(). Return a copy of the array.\";\n\nstatic PyObject *\narray_copy(PyArrayObject *self, PyObject *args) \n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\t\n return _ARET(PyArray_Copy(self));\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\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 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()\";\n\nstatic PyObject *\narray_sort(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_Sort(self, axis));\n}\n\nstatic char doc_argsort[] = \"a.argsort()\\n\"\\\n\t\" Return the indexes into a that would sort it along the\"\\\n\t\" given axis (or if the sorting should be done\"\\\n\t\" in terms of a.flat\";\n\nstatic PyObject *\narray_argsort(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_ArgSort(self, axis));\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;\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 if (deepcopy == NULL) return NULL;\n Py_DECREF(copy);\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->itemsize;\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\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 *Bool, *thestr=NULL;\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(\"scipy.base.multiarray\");\n\tif (mod == NULL) return NULL;\n\tobj = PyObject_GetAttrString(mod, \"empty\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) return NULL;\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tPyTuple_SET_ITEM(ret, 1, \n\t\t\t Py_BuildValue(\"NNN\",\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,\n\t\t\t\t\t\t\t \"dtypechar\"),\n\t\t\t\t PyInt_FromLong((long) 0)));\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 string giving the typestr (> or < indicates byte order\n\t if swap is possibly needed)\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\"));\t\n\tPyTuple_SET_ITEM(state, 1, PyObject_GetAttrString((PyObject *)self, \n\t\t\t\t\t\t\t \"dtypestr\"));\n\tBool = (PyArray_ISFORTRAN(self) ? Py_True : Py_False);\n\tPy_INCREF(Bool);\n\tPyTuple_SET_ITEM(state, 2, Bool);\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 string giving the typestr (> or < indicates byte order\n\t if swap is possibly needed)\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 PyObject *\narray_setstate(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *shape;\n\tPyArray_Typecode typecode;\n\tlong fortran;\n\tPyObject *rawdata;\n\tchar *datastr;\n\tconst char *typestr;\n\tint len, typestrlen;\n\tint swap;\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!z#iO)\", &PyTuple_Type,\n\t\t\t &shape, &typestr, &typestrlen,\n\t\t\t &fortran, &rawdata))\n\t\treturn NULL;\n\n\tif (_array_typecode_fromstr((char *)typestr, &swap, &typecode) < 0)\n\t\treturn NULL;\n\n\tself->descr = PyArray_DescrFromType(typecode.type_num);\n\tself->itemsize = typecode.itemsize;\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->itemsize *\t\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->itemsize, 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\tself->base = rawdata;\n\t\tPy_INCREF(self->base);\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->itemsize);\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\n\tif (swap) self->flags &= ~NOTSWAPPED;\n\t\n\tPy_INCREF(Py_None);\n\treturn Py_None;\t\n}\n\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), \"rb\");\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\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\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\treturn _ARET(PyArray_Transpose(self, shape));\n}\n\nstatic char doc_mean[] = \"a.mean(axis=None, rtype=None)\\n\\n\"\\\n \"Average the array over the given axis. If axis is None, average over\\n\"\\\n \"all dimensions of the array.\\n\"\\\n \"\\n\"\\\n \"if 'a' has an integer type, the result has type Float.\\n\"\\\n \"\\n\"\\\n \"If an integer axis is given, this equals:\\n\"\\\n \" a.sum(axis, rtype) * 1.0 / len(a)\\n\"\\\n \"\\n\"\\ \n \"If axis is None, this equals:\\n\"\\\n \" a.sum(axis, rtype) * 1.0 / product(a.shape)\\n\"\\\n\n \"The optional rtype argument is the data type for intermediate\\n\"\\\n \"calculations in the sum.\\n\"\\\n \"\\n\"\\\n \"If an integer axis is given, this equals:\\n\"\\\n \" a.sum(axis, rtype) * 1.0 / len(a)\\n\"\\\n \"\\n\"\\\n \"If axis is None, this equals:\\n\"\\\n \" a.sum(axis, rtype) * 1.0 / product(a.shape)\";\n\nstatic PyObject *\narray_mean(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\n\treturn _ARET(PyArray_Mean(self, axis, rtype.type_num));\n}\n\nstatic char doc_sum[] = \"a.sum(axis=None, rtype=None)\\n\\n\"\\\n \"Sum the array over the given axis. The optional rtype argument\\n\"\\\n \"is the data type for intermediate calculations.\\n\"\\\n \"\\n\"\\\n \"The default is to upcast (promote) smaller integer types to the\\n\"\\\n \"platform-dependent Int. For example, on 32-bit platforms:\\n\"\\\n \"\\n\"\\\n \" a.dtype default sum() rtype\\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(rtype=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_Typecode rtype = {PyArray_NOTYPE, 0, 0};\t\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_Sum(self, axis, rtype.type_num);\n}\n\n\nstatic char doc_cumsum[] = \"a.cumsum(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_cumsum(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_CumSum(self, axis, rtype.type_num);\n}\n\nstatic char doc_prod[] = \"a.prod(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_prod(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_Prod(self, axis, rtype.type_num);\n}\n\n\nstatic char doc_cumprod[] = \"a.cumprod(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_cumprod(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_CumProd(self, axis, rtype.type_num);\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\n\nstatic char doc_stddev[] = \"a.std(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_stddev(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_Std(self, axis, rtype.type_num);\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, rtype=None)\";\n\nstatic PyObject *\narray_trace(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis1=0, axis2=1, offset=0;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"offset\", \"axis1\", \"axis2\", \"rtype\", 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_TypecodeConverter, &rtype))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Trace(self, offset, axis1, axis2, rtype.type_num));\n}\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\tBool fortran=FALSE;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\",\n\t\t\t PyArray_BoolConverter, &fortran)) \n\t\treturn 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\tBool fortran=FALSE;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_BoolConverter,\n\t\t\t &fortran)) return NULL;\n\n\treturn PyArray_Ravel(self, (int) fortran);\n}\n\n\n\nstatic char doc_setflags[] = \"a.setflags(write=None, swap=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\", \"swap\", \"align\", \"uic\", NULL};\n\tPyObject *write=Py_None;\n\tPyObject *swap=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, \"|OOOO\", kwlist,\n\t\t\t\t\t &write, &swap, &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 if (swap != Py_None) {\n if (PyObject_IsTrue(swap))\n self->flags &= ~NOTSWAPPED;\n else \n self->flags |= NOTSWAPPED;\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic PyMethodDef array_methods[] = {\n {\"tolist\",\t (PyCFunction)array_tolist,\t1, doc_tolist},\n {\"toscalar\", (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 {\"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, doc_sort},\n\t{\"argsort\",\t(PyCFunction)array_argsort, \n\t METH_VARARGS, 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{\"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 {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": 7, "end_line": 20, "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": 26, "end_line": 34, "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": 41, "end_line": 50, "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": 56, "end_line": 66, "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": 70, "end_line": 84, "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": 47, "complexity": 13, "token_count": 290, "parameters": [ "self", "args" ], "start_line": 92, "end_line": 141, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "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": 146, "end_line": 150, "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": 8, "complexity": 2, "token_count": 53, "parameters": [ "self", "args" ], "start_line": 157, "end_line": 165, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "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": 170, "end_line": 178, "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": 183, "end_line": 191, "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": 196, "end_line": 204, "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": 209, "end_line": 217, "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": 223, "end_line": 231, "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": 237, "end_line": 244, "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_Typecode * type , int offset)", "filename": "arraymethods.c", "nloc": 14, "complexity": 2, "token_count": 110, "parameters": [ "self", "type", "offset" ], "start_line": 252, "end_line": 265, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "array_getfield", "long_name": "array_getfield( PyArrayObject * self , PyObject * args , PyObject * kwds)", "filename": "arraymethods.c", "nloc": 15, "complexity": 3, "token_count": 110, "parameters": [ "self", "args", "kwds" ], "start_line": 268, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "PyArray_Byteswap", "long_name": "PyArray_Byteswap( PyArrayObject * self , Bool inplace)", "filename": "arraymethods.c", "nloc": 41, "complexity": 7, "token_count": 247, "parameters": [ "self", "inplace" ], "start_line": 288, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "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": 348, "end_line": 356, "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": 362, "end_line": 372, "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": 378, "end_line": 382, "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": 206, "parameters": [ "self", "args", "kwds" ], "start_line": 387, "end_line": 421, "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": 69, "parameters": [ "self", "args" ], "start_line": 427, "end_line": 436, "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": 11, "complexity": 4, "token_count": 82, "parameters": [ "self", "args" ], "start_line": 443, "end_line": 455, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "array_wraparray", "long_name": "array_wraparray( PyArrayObject * self , PyObject * args)", "filename": "arraymethods.c", "nloc": 25, "complexity": 4, "token_count": 144, "parameters": [ "self", "args" ], "start_line": 463, "end_line": 489, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "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": 493, "end_line": 497, "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": 242, "parameters": [ "self", "args" ], "start_line": 503, "end_line": 546, "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": 5, "complexity": 2, "token_count": 34, "parameters": [ "self", "args" ], "start_line": 551, "end_line": 556, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "array_resize", "long_name": "array_resize( PyArrayObject * self , PyObject * args)", "filename": "arraymethods.c", "nloc": 25, "complexity": 5, "token_count": 120, "parameters": [ "self", "args" ], "start_line": 564, "end_line": 589, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "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": 75, "parameters": [ "self", "args", "kwds" ], "start_line": 597, "end_line": 607, "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": 617, "end_line": 632, "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)", "filename": "arraymethods.c", "nloc": 7, "complexity": 2, "token_count": 46, "parameters": [ "self", "args" ], "start_line": 637, "end_line": 645, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "array_argsort", "long_name": "array_argsort( PyArrayObject * self , PyObject * args)", "filename": "arraymethods.c", "nloc": 7, "complexity": 2, "token_count": 46, "parameters": [ "self", "args" ], "start_line": 653, "end_line": 661, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "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": 673, "end_line": 680, "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": 685, "end_line": 718, "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": 722, "end_line": 741, "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": 113, "parameters": [ "self", "list" ], "start_line": 744, "end_line": 762, "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": 45, "complexity": 8, "token_count": 301, "parameters": [ "self", "args" ], "start_line": 768, "end_line": 831, "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": 88, "complexity": 17, "token_count": 534, "parameters": [ "self", "args" ], "start_line": 846, "end_line": 951, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 106, "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": 954, "end_line": 975, "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": 978, "end_line": 989, "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": 995, "end_line": 1006, "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": 1011, "end_line": 1016, "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": 9, "complexity": 3, "token_count": 65, "parameters": [ "self", "args" ], "start_line": 1022, "end_line": 1032, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "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": 89, "parameters": [ "self", "args", "kwds" ], "start_line": 1056, "end_line": 1068, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1093, "end_line": 1105, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1111, "end_line": 1123, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1128, "end_line": 1140, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1146, "end_line": 1158, "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": 1164, "end_line": 1172, "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": 1177, "end_line": 1185, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1191, "end_line": 1203, "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": 1208, "end_line": 1219, "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": 1225, "end_line": 1230, "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": 11, "complexity": 2, "token_count": 109, "parameters": [ "self", "args", "kwds" ], "start_line": 1236, "end_line": 1248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 1254, "end_line": 1264, "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": 1271, "end_line": 1277, "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": 1283, "end_line": 1293, "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": 8, "complexity": 2, "token_count": 46, "parameters": [ "self", "args" ], "start_line": 1298, "end_line": 1307, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "array_ravel", "long_name": "array_ravel( PyArrayObject * self , PyObject * args)", "filename": "arraymethods.c", "nloc": 7, "complexity": 2, "token_count": 46, "parameters": [ "self", "args" ], "start_line": 1312, "end_line": 1320, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "array_setflags", "long_name": "array_setflags( PyArrayObject * self , PyObject * args , PyObject * kwds)", "filename": "arraymethods.c", "nloc": 60, "complexity": 12, "token_count": 299, "parameters": [ "self", "args", "kwds" ], "start_line": 1330, "end_line": 1394, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 65, "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": 7, "end_line": 20, "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": 26, "end_line": 34, "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": 41, "end_line": 50, "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": 56, "end_line": 66, "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": 70, "end_line": 84, "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": 47, "complexity": 13, "token_count": 290, "parameters": [ "self", "args" ], "start_line": 92, "end_line": 141, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "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": 146, "end_line": 150, "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": 8, "complexity": 2, "token_count": 53, "parameters": [ "self", "args" ], "start_line": 157, "end_line": 165, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "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": 170, "end_line": 178, "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": 183, "end_line": 191, "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": 196, "end_line": 204, "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": 209, "end_line": 217, "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": 223, "end_line": 231, "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": 237, "end_line": 244, "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_Typecode * type , int offset)", "filename": "arraymethods.c", "nloc": 14, "complexity": 2, "token_count": 110, "parameters": [ "self", "type", "offset" ], "start_line": 252, "end_line": 265, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "array_getfield", "long_name": "array_getfield( PyArrayObject * self , PyObject * args , PyObject * kwds)", "filename": "arraymethods.c", "nloc": 15, "complexity": 3, "token_count": 110, "parameters": [ "self", "args", "kwds" ], "start_line": 268, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "PyArray_Byteswap", "long_name": "PyArray_Byteswap( PyArrayObject * self , Bool inplace)", "filename": "arraymethods.c", "nloc": 41, "complexity": 7, "token_count": 247, "parameters": [ "self", "inplace" ], "start_line": 288, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "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": 348, "end_line": 356, "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": 362, "end_line": 372, "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": 378, "end_line": 382, "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": 206, "parameters": [ "self", "args", "kwds" ], "start_line": 387, "end_line": 421, "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": 69, "parameters": [ "self", "args" ], "start_line": 427, "end_line": 436, "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": 11, "complexity": 4, "token_count": 82, "parameters": [ "self", "args" ], "start_line": 443, "end_line": 455, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "array_wraparray", "long_name": "array_wraparray( PyArrayObject * self , PyObject * args)", "filename": "arraymethods.c", "nloc": 25, "complexity": 4, "token_count": 144, "parameters": [ "self", "args" ], "start_line": 463, "end_line": 489, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "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": 493, "end_line": 497, "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": 242, "parameters": [ "self", "args" ], "start_line": 503, "end_line": 546, "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": 5, "complexity": 2, "token_count": 34, "parameters": [ "self", "args" ], "start_line": 551, "end_line": 556, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "array_resize", "long_name": "array_resize( PyArrayObject * self , PyObject * args)", "filename": "arraymethods.c", "nloc": 25, "complexity": 5, "token_count": 120, "parameters": [ "self", "args" ], "start_line": 564, "end_line": 589, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "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": 75, "parameters": [ "self", "args", "kwds" ], "start_line": 597, "end_line": 607, "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": 617, "end_line": 632, "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)", "filename": "arraymethods.c", "nloc": 7, "complexity": 2, "token_count": 46, "parameters": [ "self", "args" ], "start_line": 637, "end_line": 645, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "array_argsort", "long_name": "array_argsort( PyArrayObject * self , PyObject * args)", "filename": "arraymethods.c", "nloc": 7, "complexity": 2, "token_count": 46, "parameters": [ "self", "args" ], "start_line": 653, "end_line": 661, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "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": 673, "end_line": 680, "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": 685, "end_line": 718, "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": 722, "end_line": 741, "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": 113, "parameters": [ "self", "list" ], "start_line": 744, "end_line": 762, "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": 45, "complexity": 8, "token_count": 301, "parameters": [ "self", "args" ], "start_line": 768, "end_line": 831, "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": 88, "complexity": 17, "token_count": 534, "parameters": [ "self", "args" ], "start_line": 846, "end_line": 951, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 106, "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": 954, "end_line": 975, "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": 978, "end_line": 989, "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": 995, "end_line": 1006, "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": 1011, "end_line": 1016, "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": 9, "complexity": 3, "token_count": 65, "parameters": [ "self", "args" ], "start_line": 1022, "end_line": 1032, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "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": 89, "parameters": [ "self", "args", "kwds" ], "start_line": 1056, "end_line": 1068, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1093, "end_line": 1105, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1111, "end_line": 1123, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1128, "end_line": 1140, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1146, "end_line": 1158, "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": 1164, "end_line": 1172, "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": 1177, "end_line": 1185, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1191, "end_line": 1203, "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": 1208, "end_line": 1219, "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": 1225, "end_line": 1230, "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": 11, "complexity": 2, "token_count": 109, "parameters": [ "self", "args", "kwds" ], "start_line": 1236, "end_line": 1248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 1254, "end_line": 1264, "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": 1271, "end_line": 1277, "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": 1283, "end_line": 1293, "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": 8, "complexity": 2, "token_count": 46, "parameters": [ "self", "args" ], "start_line": 1298, "end_line": 1307, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "array_ravel", "long_name": "array_ravel( PyArrayObject * self , PyObject * args)", "filename": "arraymethods.c", "nloc": 7, "complexity": 2, "token_count": 46, "parameters": [ "self", "args" ], "start_line": 1312, "end_line": 1320, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "array_setflags", "long_name": "array_setflags( PyArrayObject * self , PyObject * args , PyObject * kwds)", "filename": "arraymethods.c", "nloc": 60, "complexity": 12, "token_count": 299, "parameters": [ "self", "args", "kwds" ], "start_line": 1330, "end_line": 1394, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 65, "top_nesting_level": 0 } ], "changed_methods": [], "nloc": 1195, "complexity": 205, "token_count": 7441, "diff_parsed": { "added": [ " \"\\n\"\\", " \"\\n\"\\" ], "deleted": [ " \"\\n\"\\", "" ] } } ] }, { "hash": "4e736713fb9865aae3e889c48420ddaf1fe4fa69", "msg": "More docstring fixes for mean() and sum().", "author": { "name": "edschofield", "email": "edschofield@localhost" }, "committer": { "name": "edschofield", "email": "edschofield@localhost" }, "author_date": "2005-10-27T15:08:34+00:00", "author_timezone": 0, "committer_date": "2005-10-27T15:08:34+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "fa94504b1eee72c89ebe4503969781ebf903c3b7" ], "project_name": "repo_copy", "project_path": "/tmp/tmpn4cqam_6/repo_copy", "deletions": 43, "insertions": 35, "lines": 78, "files": 2, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "scipy/base/function_base.py", "new_path": "scipy/base/function_base.py", "filename": "function_base.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -127,32 +127,29 @@ def histogram(a, bins=10, range=None, normed=False):\n def average(a, axis=0, weights=None, returned=False):\n \"\"\"average(a, axis=0, weights=None, returned=False)\n \n- Compute average over the given axis. If axis is None, average \n- over all dimensions of the array. Equivalent to a.mean(axis), \n- but with a default axis of 0 instead of None.\n-\n- The average of an integer or floating-point array always has type\n- Float. \n- \n- If an integer axis is given, this equals:\n- a.sum(axis) * 1.0 / len(a)\n- \n- If axis is None, this equals:\n- a.sum(axis) * 1.0 / product(a.shape)\n-\n- If weights are given, result is:\n- sum(a * weights) / sum(weights),\n- where the weights must have a's shape or be 1D with length the \n- size of a in the given axis. Integer weights are converted to \n- Float. Not specifying weights is equivalent to specifying \n- weights that are all 1.\n-\n- If 'returned' is True, return a tuple: the result and the sum of\n- the weights or count of values. The shape of these two results\n- will be the same.\n-\n- Raises ZeroDivisionError if appropriate. (The version in MA does\n- not -- it returns masked values).\n+ Average the array over the given axis. If the axis is None, average\n+ over all dimensions of the array. Equivalent to a.mean(axis), but\n+ with a default axis of 0 instead of None.\n+\n+ If an integer axis is given, this equals:\n+ a.sum(axis) * 1.0 / len(a)\n+ \n+ If axis is None, this equals:\n+ a.sum(axis) * 1.0 / product(a.shape)\n+\n+ If weights are given, result is:\n+ sum(a * weights) / sum(weights),\n+ where the weights must have a's shape or be 1D with length the \n+ size of a in the given axis. Integer weights are converted to \n+ Float. Not specifying weights is equivalent to specifying \n+ weights that are all 1.\n+\n+ If 'returned' is True, return a tuple: the result and the sum of\n+ the weights or count of values. The shape of these two results\n+ will be the same.\n+\n+ Raises ZeroDivisionError if appropriate. (The version in MA does\n+ not -- it returns masked values).\n \"\"\"\n if axis is None:\n a = array(a).ravel()\n", "added_lines": 23, "deleted_lines": 26, "source_code": "import types\nimport math, operator\nimport numeric as _nx\nfrom numeric import ones, zeros, arange, concatenate, array, asarray, empty\nfrom numeric import ScalarType\nfrom umath import pi, multiply, add, arctan2, maximum, minimum, frompyfunc, \\\n isnan, absolute\nfrom oldnumeric import ravel, nonzero, choose, \\\n sometrue, alltrue, reshape, any, all, typecodes, ArrayType\nfrom type_check import ScalarType, isscalar\nfrom shape_base import squeeze, atleast_1d\nfrom _compiled_base import digitize, bincount, _insert\nfrom ufunclike import sign\n\n__all__ = ['logspace', 'linspace', 'round_',\n 'select', 'piecewise', 'trim_zeros', 'alen', 'amax', 'amin', 'ptp',\n 'copy', 'iterable', 'base_repr', 'binary_repr', 'prod', 'cumprod',\n 'diff', 'gradient', 'angle', 'unwrap', 'sort_complex', 'disp',\n 'unique', 'extract', 'insert', 'nansum', 'nanmax', 'nanargmax',\n 'nanargmin', 'nanmin', 'vectorize', 'asarray_chkfinite', 'average',\n 'histogram', 'bincount', 'digitize']\n\n_lkup = {'0':'000',\n '1':'001',\n '2':'010',\n '3':'011',\n '4':'100',\n '5':'101',\n '6':'110',\n '7':'111',\n 'L':''}\n\ndef binary_repr(num):\n \"\"\"Return the binary representation of the input number as a string.\n\n This is equivalent to using base_repr with base 2, but about 25x\n faster.\n \"\"\"\n ostr = oct(num)\n bin = ''\n for ch in ostr[1:]:\n bin += _lkup[ch]\n ind = 0\n while bin[ind] == '0':\n ind += 1\n return bin[ind:]\n\ndef base_repr (number, base=2, padding=0):\n \"\"\"Return the representation of a number in any given base.\n \"\"\"\n chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'\n\n lnb = math.log(base)\n res = padding*chars[0]\n if number == 0:\n return res + chars[0]\n exponent = int (math.log (number)/lnb)\n while(exponent >= 0):\n term = long(base)**exponent\n lead_digit = int(number / term)\n res += chars[lead_digit]\n number -= term*lead_digit\n exponent -= 1\n return res\n#end Fernando's utilities\n\n\n\ndef logspace(start, stop, num=50, endpoint=True):\n \"\"\" Return evenly spaced samples on a logarithmic scale.\n\n Return 'num' evenly spaced samples from 10**start to 10**stop.\n If 'endpoint' is True then the last sample is 10**stop.\n \"\"\"\n if num <= 0: return array([])\n if endpoint:\n step = (stop-start)/float((num-1))\n y = _nx.arange(0, num) * step + start\n else:\n step = (stop-start)/float(num)\n y = _nx.arange(0, num) * step + start\n return _nx.power(10.0, y)\n\ndef linspace(start, stop, num=50, endpoint=True, retstep=False):\n \"\"\" Return 'num' evenly spaced samples from 'start' to 'stop'. If\n 'endpoint' is True, the last sample is 'stop'. If 'retstep' is\n True then return the step value used.\n \"\"\"\n if num <= 0: return array([])\n if endpoint:\n step = (stop-start)/float((num-1))\n y = _nx.arange(0, num) * step + start \n else:\n step = (stop-start)/float(num)\n y = _nx.arange(0, num) * step + start\n if retstep:\n return y, step\n else:\n return y\n\ndef iterable(y):\n try: iter(y)\n except: return 0\n return 1\n\ndef histogram(a, bins=10, range=None, normed=False):\n a = asarray(a).ravel()\n if not iterable(bins):\n if range is None:\n range = (a.min(), a.max())\n mn, mx = [a+0.0 for a in range]\n if mn == mx:\n mn -= 0.5\n mx += 0.5\n bins = linspace(mn, mx, bins)\n\n n = a.sort().searchsorted(bins)\n n = concatenate([n, [len(a)]])\n n = n[1:]-n[:-1]\n\n if normed:\n db = bins[1] - bins[0]\n return 1.0/(a.size*db) * n, bins\n else:\n return n, bins\n\ndef average(a, axis=0, weights=None, returned=False):\n \"\"\"average(a, axis=0, weights=None, returned=False)\n\n Average the array over the given axis. If the axis is None, average\n over all dimensions of the array. Equivalent to a.mean(axis), but\n with a default axis of 0 instead of None.\n\n If an integer axis is given, this equals:\n a.sum(axis) * 1.0 / len(a)\n \n If axis is None, this equals:\n a.sum(axis) * 1.0 / product(a.shape)\n\n If weights are given, result is:\n sum(a * weights) / sum(weights),\n where the weights must have a's shape or be 1D with length the \n size of a in the given axis. Integer weights are converted to \n Float. Not specifying weights is equivalent to specifying \n weights that are all 1.\n\n If 'returned' is True, return a tuple: the result and the sum of\n the weights or count of values. The shape of these two results\n will be the same.\n\n Raises ZeroDivisionError if appropriate. (The version in MA does\n not -- it returns masked values).\n \"\"\"\n if axis is None:\n a = array(a).ravel()\n if weights is None:\n n = add.reduce(a)\n d = len(a) * 1.0\n else:\n w = array(weights).ravel() * 1.0\n n = add.reduce(multiply(a, w))\n d = add.reduce(w) \n else:\n a = array(a)\n ash = a.shape\n if ash == ():\n a.shape = (1,)\n if weights is None:\n n = add.reduce(a, axis) \n d = ash[axis] * 1.0\n if returned:\n d = ones(shape(n)) * d\n else:\n w = array(weights, copy=False) * 1.0\n wsh = w.shape\n if wsh == ():\n wsh = (1,)\n if wsh == ash:\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis) \n elif wsh == (ash[axis],):\n ni = ash[axis]\n r = [newaxis]*ni\n r[axis] = slice(None, None, 1)\n w1 = eval(\"w[\"+repr(tuple(r))+\"]*ones(ash, Float)\")\n n = add.reduce(a*w1, axis)\n d = add.reduce(w1, axis)\n else:\n raise ValueError, 'averaging weights have wrong shape'\n \n if not isinstance(d, ArrayType):\n if d == 0.0: \n raise ZeroDivisionError, 'zero denominator in average()'\n if returned:\n return n/d, d\n else:\n return n/d\n\n\ndef isaltered():\n val = str(type(_nx.array([1])))\n return 'scipy' in val\n\n\ndef asarray_chkfinite(a):\n \"\"\"Like asarray, but check that no NaNs or Infs are present.\n \"\"\"\n a = asarray(a)\n if (a.dtypechar in _nx.typecodes['AllFloat']) \\\n and (_nx.isnan(a).any() or _nx.isinf(a).any()):\n raise ValueError, \"array must not contain infs or NaNs\"\n return a \n\n\n\n\ndef piecewise(x, condlist, funclist, *args, **kw):\n \"\"\"Return a piecewise-defined function.\n\n x is the domain\n\n condlist is a list of boolean arrays or a single boolean array\n The length of the condition list must be n2 or n2-1 where n2\n is the length of the function list. If len(condlist)==n2-1, then\n an 'otherwise' condition is formed by |'ing all the conditions\n and inverting. \n\n funclist is a list of functions to call of length (n2).\n Each function should return an array output for an array input\n Each function can take (the same set) of extra arguments and\n keyword arguments which are passed in after the function list.\n\n The output is the same shape and type as x and is found by\n calling the functions on the appropriate portions of x.\n\n Note: This is similar to choose or select, except\n the the functions are only evaluated on elements of x\n that satisfy the corresponding condition.\n\n The result is\n |--\n | f1(x) for condition1\n y = --| f2(x) for condition2\n | ...\n | fn(x) for conditionn\n |--\n \n \"\"\"\n n2 = len(funclist)\n if not isinstance(condlist, type([])):\n condlist = [condlist]\n n = len(condlist)\n if n == n2-1: # compute the \"otherwise\" condition.\n totlist = condlist[0]\n for k in range(1, n):\n totlist |= condlist\n condlist.append(~totlist)\n n += 1\n if (n != n2):\n raise ValueError, \"function list and condition list must be the same\"\n y = empty(x.shape, x.dtype)\n for k in range(n):\n item = funclist[k]\n if not callable(item):\n y[condlist[k]] = item\n else:\n y[condlist[k]] = item(x[condlist[k]], *args, **kw)\n return y\n\ndef select(condlist, choicelist, default=0):\n \"\"\" Return an array composed of different elements of choicelist\n depending on the list of conditions.\n\n condlist is a list of condition arrays containing ones or zeros\n \n choicelist is a list of choice arrays (of the \"same\" size as the\n arrays in condlist). The result array has the \"same\" size as the\n arrays in choicelist. If condlist is [c0, ..., cN-1] then choicelist\n must be of length N. The elements of the choicelist can then be\n represented as [v0, ..., vN-1]. The default choice if none of the\n conditions are met is given as the default argument. \n \n The conditions are tested in order and the first one statisfied is\n used to select the choice. In other words, the elements of the\n output array are found from the following tree (notice the order of\n the conditions matters):\n \n if c0: v0\n elif c1: v1\n elif c2: v2\n ...\n elif cN-1: vN-1\n else: default\n \n Note that one of the condition arrays must be large enough to handle\n the largest array in the choice list.\n \"\"\"\n n = len(condlist)\n n2 = len(choicelist)\n if n2 != n:\n raise ValueError, \"list of cases must be same length as list of conditions\"\n choicelist.insert(0, default) \n S = 0\n pfac = 1\n for k in range(1, n+1):\n S += k * pfac * asarray(condlist[k-1])\n if k < n:\n pfac *= (1-asarray(condlist[k-1]))\n # handle special case of a 1-element condition but\n # a multi-element choice\n if type(S) in ScalarType or max(asarray(S).shape)==1:\n pfac = asarray(1)\n for k in range(n2+1):\n pfac = pfac + asarray(choicelist[k]) \n S = S*ones(asarray(pfac).shape)\n return choose(S, tuple(choicelist))\n\ndef _asarray1d(arr, copy=False):\n \"\"\"Ensure 1D array for one array.\n \"\"\"\n if copy:\n return asarray(arr).flatten()\n else:\n return asarray(arr).ravel()\n\ndef copy(a):\n \"\"\"Return an array copy of the given object.\n \"\"\"\n return array(a, copy=True)\n \n# Basic operations\ndef amax(a, axis=-1): \n \"\"\"Return the maximum of 'a' along dimension axis. \n \"\"\"\n return asarray(a).max(axis)\n\ndef amin(a, axis=-1):\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 ptp(a, axis=-1):\n \"\"\"Return maximum - minimum along the the given dimension\n \"\"\"\n return asarray(a).ptp(axis)\n\ndef prod(a, axis=-1):\n \"\"\"Return the product of the elements along the given axis\n \"\"\"\n return asarray(a).prod(axis)\n\ndef cumprod(a, axis=-1):\n \"\"\"Return the cumulative product of the elments along the given axis\n \"\"\"\n return asarray(a).cumprod(axis)\n\ndef gradient(f, *varargs):\n \"\"\"Calculate the gradient of an N-dimensional scalar function.\n\n Uses central differences on the interior and first differences on boundaries\n to give the same shape.\n\n Inputs:\n\n f -- An N-dimensional array giving samples of a scalar function\n\n varargs -- 0, 1, or N scalars giving the sample distances in each direction\n\n Outputs:\n\n N arrays of the same shape as f giving the derivative of f with respect\n to each dimension.\n \"\"\"\n N = len(f.shape) # number of dimensions\n n = len(varargs)\n if n==0:\n dx = [1.0]*N\n elif n==1:\n dx = [varargs[0]]*N\n elif n==N:\n dx = list(varargs)\n else:\n raise SyntaxError, \"invalid number of arguments\"\n\n # use central differences on interior and first differences on endpoints\n\n print dx\n outvals = []\n\n # create slice objects --- initially all are [:, :, ..., :]\n slice1 = [slice(None)]*N\n slice2 = [slice(None)]*N\n slice3 = [slice(None)]*N\n\n otype = f.dtypechar\n if otype not in ['f', 'd', 'F', 'D']:\n otype = 'd'\n\n for axis in range(N):\n # select out appropriate parts for this dimension\n out = zeros(f.shape, f.dtypechar)\n slice1[axis] = slice(1, -1)\n slice2[axis] = slice(2, None)\n slice3[axis] = slice(None, -2)\n # 1D equivalent -- out[1:-1] = (f[2:] - f[:-2])/2.0\n out[slice1] = (f[slice2] - f[slice3])/2.0 \n slice1[axis] = 0\n slice2[axis] = 1\n slice3[axis] = 0\n # 1D equivalent -- out[0] = (f[1] - f[0])\n out[slice1] = (f[slice2] - f[slice3])\n slice1[axis] = -1\n slice2[axis] = -1\n slice3[axis] = -2\n # 1D equivalent -- out[-1] = (f[-1] - f[-2])\n out[slice1] = (f[slice2] - f[slice3])\n \n # divide by step size\n outvals.append(out / dx[axis])\n \n # reset the slice object in this dimension to \":\"\n slice1[axis] = slice(None)\n slice2[axis] = slice(None)\n slice3[axis] = slice(None)\n\n if N == 1:\n return outvals[0]\n else:\n return outvals\n \n\ndef diff(a, n=1, axis=-1):\n \"\"\"Calculate the nth order discrete difference along given axis.\n \"\"\"\n if n==0:\n return a\n if n<0:\n raise ValueError, 'order must be non-negative but got ' + `n`\n a = asarray(a)\n nd = len(a.shape)\n slice1 = [slice(None)]*nd\n slice2 = [slice(None)]*nd\n slice1[axis] = slice(1, None)\n slice2[axis] = slice(None, -1)\n slice1 = tuple(slice1)\n slice2 = tuple(slice2)\n if n > 1:\n return diff(a[slice1]-a[slice2], n-1, axis=axis)\n else:\n return a[slice1]-a[slice2]\n \ndef angle(z, deg=0):\n \"\"\"Return the angle of the complex argument z.\n \"\"\"\n if deg:\n fact = 180/pi\n else:\n fact = 1.0\n z = asarray(z)\n if (issubclass(z.dtype, _nx.complexfloating)):\n zimag = z.imag\n zreal = z.real\n else:\n zimag = 0\n zreal = z\n return arctan2(zimag, zreal) * fact\n\ndef unwrap(p, discont=pi, axis=-1):\n \"\"\"Unwrap radian phase p by changing absolute jumps greater than\n 'discont' to their 2*pi complement along the given axis.\n \"\"\"\n p = asarray(p)\n nd = len(p.shape)\n dd = diff(p, axis=axis)\n slice1 = [slice(None, None)]*nd # full slices\n slice1[axis] = slice(1, None)\n ddmod = mod(dd+pi, 2*pi)-pi\n _nx.putmask(ddmod, (ddmod==-pi) & (dd > 0), pi)\n ph_correct = ddmod - dd;\n _nx.putmask(ph_correct, abs(dd)>> import scipy\n >>> a = array((0, 0, 0, 1, 2, 3, 2, 1, 0))\n >>> scipy.trim_zeros(a)\n array([1, 2, 3, 2, 1])\n \"\"\"\n first = 0\n trim = trim.upper()\n if 'F' in trim:\n for i in filt:\n if i != 0.: break\n else: first = first + 1\n last = len(filt)\n if 'B' in trim:\n for i in filt[::-1]:\n if i != 0.: break\n else: last = last - 1\n return filt[first:last]\n\ndef unique(inseq):\n \"\"\"Return unique items from a 1-dimensional sequence.\n \"\"\"\n # Dictionary setting is quite fast.\n set = {}\n for item in inseq:\n set[item] = None\n return asarray(set.keys())\n \ndef extract(condition, arr):\n \"\"\"Return the elements of ravel(arr) where ravel(condition) is True\n (in 1D).\n\n Equivalent to compress(ravel(condition), ravel(arr)).\n \"\"\"\n return _nx.take(ravel(arr), nonzero(ravel(condition)))\n\ndef insert(arr, mask, vals):\n \"\"\"Similar to putmask arr[mask] = vals but the 1D array vals has the\n same number of elements as the non-zero values of mask. Inverse of\n extract.\n \"\"\"\n return _nx._insert(arr, mask, vals)\n\ndef nansum(a, axis=-1):\n \"\"\"Sum the array over the given axis, treating NaNs as 0.\n \"\"\"\n y = array(a)\n if not issubclass(y.dtype, _nx.integer):\n y[isnan(a)] = 0\n return y.sum(axis)\n\ndef nanmin(a, axis=-1):\n \"\"\"Find the minimium over the given axis, ignoring NaNs.\n \"\"\"\n y = array(a)\n if not issubclass(y.dtype, _nx.integer):\n y[isnan(a)] = _nx.inf\n return y.min(axis)\n\ndef nanargmin(a, axis=-1):\n \"\"\"Find the indices of the minimium over the given axis ignoring NaNs.\n \"\"\"\n y = array(a)\n if not issubclass(y.dtype, _nx.integer):\n y[isnan(a)] = _nx.inf \n return y.argmin(axis) \n\ndef nanmax(a, axis=-1):\n \"\"\"Find the maximum over the given axis ignoring NaNs.\n \"\"\"\n y = array(a)\n if not issubclass(y.dtype, _nx.integer):\n y[isnan(a)] = -_nx.inf \n return y.max(axis) \n\ndef nanargmax(a, axis=-1):\n \"\"\"Find the maximum over the given axis ignoring NaNs.\n \"\"\"\n y = array(a)\n if not issubclass(y.dtype, _nx.integer):\n y[isnan(a)] = -_nx.inf \n return y.argmax(axis) \n\ndef disp(mesg, device=None, linefeed=True):\n \"\"\"Display a message to the given device (default is sys.stdout)\n with or without a linefeed.\n \"\"\"\n if device is None:\n import sys\n device = sys.stdout\n if linefeed:\n device.write('%s\\n' % mesg)\n else:\n device.write('%s' % mesg)\n device.flush()\n return\n\nclass vectorize:\n \"\"\"\n vectorize(somefunction, otypes=None, doc=None)\n Generalized Function class.\n\n Description:\n \n Define a vectorized function which takes nested sequence\n objects or scipy arrays as inputs and returns a\n scipy array as output, evaluating the function over successive\n tuples of the input arrays like the python map function except it uses\n the broadcasting rules of scipy. \n\n Input:\n\n somefunction -- a Python function or method\n\n Example:\n\n def myfunc(a, b):\n if a > b:\n return a-b\n else\n return a+b\n\n vfunc = vectorize(myfunc)\n\n >>> vfunc([1, 2, 3, 4], 2)\n array([3, 4, 1, 2])\n\n \"\"\"\n def __init__(self, pyfunc, otypes='', doc=None):\n try:\n fcode = pyfunc.func_code\n except AttributeError:\n raise TypeError, \"object is not a callable Python object\"\n\n self.thefunc = pyfunc\n self.ufunc = None\n self.nin = len(fcode.co_varnames)\n self.nout = None\n if doc is None:\n self.__doc__ = pyfunc.__doc__\n else:\n self.__doc__ = doc\n if isinstance(otypes, types.StringType):\n self.otypes=otypes\n else:\n raise ValueError, \"output types must be a string\"\n for char in self.otypes:\n if char not in typecodes['All']:\n raise ValueError, \"invalid typecode specified\"\n\n def __call__(self, *args):\n # get number of outputs and output types by calling\n # the function on the first entries of args\n if len(args) != self.nin:\n raise ValueError, \"mismatch between python function inputs\"\\\n \" and received arguments\"\n if self.nout is None or self.otypes == '':\n newargs = []\n for arg in args:\n newargs.append(asarray(arg).flat[0])\n theout = self.thefunc(*newargs)\n if isinstance(theout, types.TupleType):\n self.nout = len(theout)\n else:\n self.nout = 1\n theout = (theout,)\n if self.otypes == '':\n otypes = []\n for k in range(self.nout):\n otypes.append(asarray(theout[k]).dtypechar)\n self.otypes = ''.join(otypes)\n\n if self.ufunc is None:\n self.ufunc = frompyfunc(self.thefunc, self.nin, self.nout)\n\n if self.nout == 1:\n return self.ufunc(*args).astype(self.otypes[0])\n else:\n return tuple([x.astype(c) for x, c in zip(self.ufunc(*args), self.otypes)])\n\n\ndef round_(a, decimals=0):\n \"\"\"Round 'a' to the given number of decimal places. Rounding\n behaviour is equivalent to Python.\n\n Return 'a' if the array is not floating point. Round both the real\n and imaginary parts separately if the array is complex.\n \"\"\"\n a = asarray(a)\n if not issubclass(a.dtype, _nx.inexact):\n return a\n if issubclass(a.dtype, _nx.complexfloating):\n return round_(a.real, decimals) + 1j*round_(a.imag, decimals)\n if decimals is not 0:\n decimals = asarray(decimals)\n s = sign(a)\n if decimals is not 0:\n a = absolute(multiply(a, 10.**decimals))\n else:\n a = absolute(a)\n rem = a-asarray(a).astype(_nx.intp)\n a = _nx.where(_nx.less(rem, 0.5), _nx.floor(a), _nx.ceil(a))\n # convert back\n if decimals is not 0:\n return multiply(a, s/(10.**decimals))\n else:\n return multiply(a, s)\n\n", "source_code_before": "import types\nimport math, operator\nimport numeric as _nx\nfrom numeric import ones, zeros, arange, concatenate, array, asarray, empty\nfrom numeric import ScalarType\nfrom umath import pi, multiply, add, arctan2, maximum, minimum, frompyfunc, \\\n isnan, absolute\nfrom oldnumeric import ravel, nonzero, choose, \\\n sometrue, alltrue, reshape, any, all, typecodes, ArrayType\nfrom type_check import ScalarType, isscalar\nfrom shape_base import squeeze, atleast_1d\nfrom _compiled_base import digitize, bincount, _insert\nfrom ufunclike import sign\n\n__all__ = ['logspace', 'linspace', 'round_',\n 'select', 'piecewise', 'trim_zeros', 'alen', 'amax', 'amin', 'ptp',\n 'copy', 'iterable', 'base_repr', 'binary_repr', 'prod', 'cumprod',\n 'diff', 'gradient', 'angle', 'unwrap', 'sort_complex', 'disp',\n 'unique', 'extract', 'insert', 'nansum', 'nanmax', 'nanargmax',\n 'nanargmin', 'nanmin', 'vectorize', 'asarray_chkfinite', 'average',\n 'histogram', 'bincount', 'digitize']\n\n_lkup = {'0':'000',\n '1':'001',\n '2':'010',\n '3':'011',\n '4':'100',\n '5':'101',\n '6':'110',\n '7':'111',\n 'L':''}\n\ndef binary_repr(num):\n \"\"\"Return the binary representation of the input number as a string.\n\n This is equivalent to using base_repr with base 2, but about 25x\n faster.\n \"\"\"\n ostr = oct(num)\n bin = ''\n for ch in ostr[1:]:\n bin += _lkup[ch]\n ind = 0\n while bin[ind] == '0':\n ind += 1\n return bin[ind:]\n\ndef base_repr (number, base=2, padding=0):\n \"\"\"Return the representation of a number in any given base.\n \"\"\"\n chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'\n\n lnb = math.log(base)\n res = padding*chars[0]\n if number == 0:\n return res + chars[0]\n exponent = int (math.log (number)/lnb)\n while(exponent >= 0):\n term = long(base)**exponent\n lead_digit = int(number / term)\n res += chars[lead_digit]\n number -= term*lead_digit\n exponent -= 1\n return res\n#end Fernando's utilities\n\n\n\ndef logspace(start, stop, num=50, endpoint=True):\n \"\"\" Return evenly spaced samples on a logarithmic scale.\n\n Return 'num' evenly spaced samples from 10**start to 10**stop.\n If 'endpoint' is True then the last sample is 10**stop.\n \"\"\"\n if num <= 0: return array([])\n if endpoint:\n step = (stop-start)/float((num-1))\n y = _nx.arange(0, num) * step + start\n else:\n step = (stop-start)/float(num)\n y = _nx.arange(0, num) * step + start\n return _nx.power(10.0, y)\n\ndef linspace(start, stop, num=50, endpoint=True, retstep=False):\n \"\"\" Return 'num' evenly spaced samples from 'start' to 'stop'. If\n 'endpoint' is True, the last sample is 'stop'. If 'retstep' is\n True then return the step value used.\n \"\"\"\n if num <= 0: return array([])\n if endpoint:\n step = (stop-start)/float((num-1))\n y = _nx.arange(0, num) * step + start \n else:\n step = (stop-start)/float(num)\n y = _nx.arange(0, num) * step + start\n if retstep:\n return y, step\n else:\n return y\n\ndef iterable(y):\n try: iter(y)\n except: return 0\n return 1\n\ndef histogram(a, bins=10, range=None, normed=False):\n a = asarray(a).ravel()\n if not iterable(bins):\n if range is None:\n range = (a.min(), a.max())\n mn, mx = [a+0.0 for a in range]\n if mn == mx:\n mn -= 0.5\n mx += 0.5\n bins = linspace(mn, mx, bins)\n\n n = a.sort().searchsorted(bins)\n n = concatenate([n, [len(a)]])\n n = n[1:]-n[:-1]\n\n if normed:\n db = bins[1] - bins[0]\n return 1.0/(a.size*db) * n, bins\n else:\n return n, bins\n\ndef average(a, axis=0, weights=None, returned=False):\n \"\"\"average(a, axis=0, weights=None, returned=False)\n\n Compute average over the given axis. If axis is None, average \n over all dimensions of the array. Equivalent to a.mean(axis), \n but with a default axis of 0 instead of None.\n\n The average of an integer or floating-point array always has type\n Float. \n \n If an integer axis is given, this equals:\n a.sum(axis) * 1.0 / len(a)\n \n If axis is None, this equals:\n a.sum(axis) * 1.0 / product(a.shape)\n\n If weights are given, result is:\n sum(a * weights) / sum(weights),\n where the weights must have a's shape or be 1D with length the \n size of a in the given axis. Integer weights are converted to \n Float. Not specifying weights is equivalent to specifying \n weights that are all 1.\n\n If 'returned' is True, return a tuple: the result and the sum of\n the weights or count of values. The shape of these two results\n will be the same.\n\n Raises ZeroDivisionError if appropriate. (The version in MA does\n not -- it returns masked values).\n \"\"\"\n if axis is None:\n a = array(a).ravel()\n if weights is None:\n n = add.reduce(a)\n d = len(a) * 1.0\n else:\n w = array(weights).ravel() * 1.0\n n = add.reduce(multiply(a, w))\n d = add.reduce(w) \n else:\n a = array(a)\n ash = a.shape\n if ash == ():\n a.shape = (1,)\n if weights is None:\n n = add.reduce(a, axis) \n d = ash[axis] * 1.0\n if returned:\n d = ones(shape(n)) * d\n else:\n w = array(weights, copy=False) * 1.0\n wsh = w.shape\n if wsh == ():\n wsh = (1,)\n if wsh == ash:\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis) \n elif wsh == (ash[axis],):\n ni = ash[axis]\n r = [newaxis]*ni\n r[axis] = slice(None, None, 1)\n w1 = eval(\"w[\"+repr(tuple(r))+\"]*ones(ash, Float)\")\n n = add.reduce(a*w1, axis)\n d = add.reduce(w1, axis)\n else:\n raise ValueError, 'averaging weights have wrong shape'\n \n if not isinstance(d, ArrayType):\n if d == 0.0: \n raise ZeroDivisionError, 'zero denominator in average()'\n if returned:\n return n/d, d\n else:\n return n/d\n\n\ndef isaltered():\n val = str(type(_nx.array([1])))\n return 'scipy' in val\n\n\ndef asarray_chkfinite(a):\n \"\"\"Like asarray, but check that no NaNs or Infs are present.\n \"\"\"\n a = asarray(a)\n if (a.dtypechar in _nx.typecodes['AllFloat']) \\\n and (_nx.isnan(a).any() or _nx.isinf(a).any()):\n raise ValueError, \"array must not contain infs or NaNs\"\n return a \n\n\n\n\ndef piecewise(x, condlist, funclist, *args, **kw):\n \"\"\"Return a piecewise-defined function.\n\n x is the domain\n\n condlist is a list of boolean arrays or a single boolean array\n The length of the condition list must be n2 or n2-1 where n2\n is the length of the function list. If len(condlist)==n2-1, then\n an 'otherwise' condition is formed by |'ing all the conditions\n and inverting. \n\n funclist is a list of functions to call of length (n2).\n Each function should return an array output for an array input\n Each function can take (the same set) of extra arguments and\n keyword arguments which are passed in after the function list.\n\n The output is the same shape and type as x and is found by\n calling the functions on the appropriate portions of x.\n\n Note: This is similar to choose or select, except\n the the functions are only evaluated on elements of x\n that satisfy the corresponding condition.\n\n The result is\n |--\n | f1(x) for condition1\n y = --| f2(x) for condition2\n | ...\n | fn(x) for conditionn\n |--\n \n \"\"\"\n n2 = len(funclist)\n if not isinstance(condlist, type([])):\n condlist = [condlist]\n n = len(condlist)\n if n == n2-1: # compute the \"otherwise\" condition.\n totlist = condlist[0]\n for k in range(1, n):\n totlist |= condlist\n condlist.append(~totlist)\n n += 1\n if (n != n2):\n raise ValueError, \"function list and condition list must be the same\"\n y = empty(x.shape, x.dtype)\n for k in range(n):\n item = funclist[k]\n if not callable(item):\n y[condlist[k]] = item\n else:\n y[condlist[k]] = item(x[condlist[k]], *args, **kw)\n return y\n\ndef select(condlist, choicelist, default=0):\n \"\"\" Return an array composed of different elements of choicelist\n depending on the list of conditions.\n\n condlist is a list of condition arrays containing ones or zeros\n \n choicelist is a list of choice arrays (of the \"same\" size as the\n arrays in condlist). The result array has the \"same\" size as the\n arrays in choicelist. If condlist is [c0, ..., cN-1] then choicelist\n must be of length N. The elements of the choicelist can then be\n represented as [v0, ..., vN-1]. The default choice if none of the\n conditions are met is given as the default argument. \n \n The conditions are tested in order and the first one statisfied is\n used to select the choice. In other words, the elements of the\n output array are found from the following tree (notice the order of\n the conditions matters):\n \n if c0: v0\n elif c1: v1\n elif c2: v2\n ...\n elif cN-1: vN-1\n else: default\n \n Note that one of the condition arrays must be large enough to handle\n the largest array in the choice list.\n \"\"\"\n n = len(condlist)\n n2 = len(choicelist)\n if n2 != n:\n raise ValueError, \"list of cases must be same length as list of conditions\"\n choicelist.insert(0, default) \n S = 0\n pfac = 1\n for k in range(1, n+1):\n S += k * pfac * asarray(condlist[k-1])\n if k < n:\n pfac *= (1-asarray(condlist[k-1]))\n # handle special case of a 1-element condition but\n # a multi-element choice\n if type(S) in ScalarType or max(asarray(S).shape)==1:\n pfac = asarray(1)\n for k in range(n2+1):\n pfac = pfac + asarray(choicelist[k]) \n S = S*ones(asarray(pfac).shape)\n return choose(S, tuple(choicelist))\n\ndef _asarray1d(arr, copy=False):\n \"\"\"Ensure 1D array for one array.\n \"\"\"\n if copy:\n return asarray(arr).flatten()\n else:\n return asarray(arr).ravel()\n\ndef copy(a):\n \"\"\"Return an array copy of the given object.\n \"\"\"\n return array(a, copy=True)\n \n# Basic operations\ndef amax(a, axis=-1): \n \"\"\"Return the maximum of 'a' along dimension axis. \n \"\"\"\n return asarray(a).max(axis)\n\ndef amin(a, axis=-1):\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 ptp(a, axis=-1):\n \"\"\"Return maximum - minimum along the the given dimension\n \"\"\"\n return asarray(a).ptp(axis)\n\ndef prod(a, axis=-1):\n \"\"\"Return the product of the elements along the given axis\n \"\"\"\n return asarray(a).prod(axis)\n\ndef cumprod(a, axis=-1):\n \"\"\"Return the cumulative product of the elments along the given axis\n \"\"\"\n return asarray(a).cumprod(axis)\n\ndef gradient(f, *varargs):\n \"\"\"Calculate the gradient of an N-dimensional scalar function.\n\n Uses central differences on the interior and first differences on boundaries\n to give the same shape.\n\n Inputs:\n\n f -- An N-dimensional array giving samples of a scalar function\n\n varargs -- 0, 1, or N scalars giving the sample distances in each direction\n\n Outputs:\n\n N arrays of the same shape as f giving the derivative of f with respect\n to each dimension.\n \"\"\"\n N = len(f.shape) # number of dimensions\n n = len(varargs)\n if n==0:\n dx = [1.0]*N\n elif n==1:\n dx = [varargs[0]]*N\n elif n==N:\n dx = list(varargs)\n else:\n raise SyntaxError, \"invalid number of arguments\"\n\n # use central differences on interior and first differences on endpoints\n\n print dx\n outvals = []\n\n # create slice objects --- initially all are [:, :, ..., :]\n slice1 = [slice(None)]*N\n slice2 = [slice(None)]*N\n slice3 = [slice(None)]*N\n\n otype = f.dtypechar\n if otype not in ['f', 'd', 'F', 'D']:\n otype = 'd'\n\n for axis in range(N):\n # select out appropriate parts for this dimension\n out = zeros(f.shape, f.dtypechar)\n slice1[axis] = slice(1, -1)\n slice2[axis] = slice(2, None)\n slice3[axis] = slice(None, -2)\n # 1D equivalent -- out[1:-1] = (f[2:] - f[:-2])/2.0\n out[slice1] = (f[slice2] - f[slice3])/2.0 \n slice1[axis] = 0\n slice2[axis] = 1\n slice3[axis] = 0\n # 1D equivalent -- out[0] = (f[1] - f[0])\n out[slice1] = (f[slice2] - f[slice3])\n slice1[axis] = -1\n slice2[axis] = -1\n slice3[axis] = -2\n # 1D equivalent -- out[-1] = (f[-1] - f[-2])\n out[slice1] = (f[slice2] - f[slice3])\n \n # divide by step size\n outvals.append(out / dx[axis])\n \n # reset the slice object in this dimension to \":\"\n slice1[axis] = slice(None)\n slice2[axis] = slice(None)\n slice3[axis] = slice(None)\n\n if N == 1:\n return outvals[0]\n else:\n return outvals\n \n\ndef diff(a, n=1, axis=-1):\n \"\"\"Calculate the nth order discrete difference along given axis.\n \"\"\"\n if n==0:\n return a\n if n<0:\n raise ValueError, 'order must be non-negative but got ' + `n`\n a = asarray(a)\n nd = len(a.shape)\n slice1 = [slice(None)]*nd\n slice2 = [slice(None)]*nd\n slice1[axis] = slice(1, None)\n slice2[axis] = slice(None, -1)\n slice1 = tuple(slice1)\n slice2 = tuple(slice2)\n if n > 1:\n return diff(a[slice1]-a[slice2], n-1, axis=axis)\n else:\n return a[slice1]-a[slice2]\n \ndef angle(z, deg=0):\n \"\"\"Return the angle of the complex argument z.\n \"\"\"\n if deg:\n fact = 180/pi\n else:\n fact = 1.0\n z = asarray(z)\n if (issubclass(z.dtype, _nx.complexfloating)):\n zimag = z.imag\n zreal = z.real\n else:\n zimag = 0\n zreal = z\n return arctan2(zimag, zreal) * fact\n\ndef unwrap(p, discont=pi, axis=-1):\n \"\"\"Unwrap radian phase p by changing absolute jumps greater than\n 'discont' to their 2*pi complement along the given axis.\n \"\"\"\n p = asarray(p)\n nd = len(p.shape)\n dd = diff(p, axis=axis)\n slice1 = [slice(None, None)]*nd # full slices\n slice1[axis] = slice(1, None)\n ddmod = mod(dd+pi, 2*pi)-pi\n _nx.putmask(ddmod, (ddmod==-pi) & (dd > 0), pi)\n ph_correct = ddmod - dd;\n _nx.putmask(ph_correct, abs(dd)>> import scipy\n >>> a = array((0, 0, 0, 1, 2, 3, 2, 1, 0))\n >>> scipy.trim_zeros(a)\n array([1, 2, 3, 2, 1])\n \"\"\"\n first = 0\n trim = trim.upper()\n if 'F' in trim:\n for i in filt:\n if i != 0.: break\n else: first = first + 1\n last = len(filt)\n if 'B' in trim:\n for i in filt[::-1]:\n if i != 0.: break\n else: last = last - 1\n return filt[first:last]\n\ndef unique(inseq):\n \"\"\"Return unique items from a 1-dimensional sequence.\n \"\"\"\n # Dictionary setting is quite fast.\n set = {}\n for item in inseq:\n set[item] = None\n return asarray(set.keys())\n \ndef extract(condition, arr):\n \"\"\"Return the elements of ravel(arr) where ravel(condition) is True\n (in 1D).\n\n Equivalent to compress(ravel(condition), ravel(arr)).\n \"\"\"\n return _nx.take(ravel(arr), nonzero(ravel(condition)))\n\ndef insert(arr, mask, vals):\n \"\"\"Similar to putmask arr[mask] = vals but the 1D array vals has the\n same number of elements as the non-zero values of mask. Inverse of\n extract.\n \"\"\"\n return _nx._insert(arr, mask, vals)\n\ndef nansum(a, axis=-1):\n \"\"\"Sum the array over the given axis, treating NaNs as 0.\n \"\"\"\n y = array(a)\n if not issubclass(y.dtype, _nx.integer):\n y[isnan(a)] = 0\n return y.sum(axis)\n\ndef nanmin(a, axis=-1):\n \"\"\"Find the minimium over the given axis, ignoring NaNs.\n \"\"\"\n y = array(a)\n if not issubclass(y.dtype, _nx.integer):\n y[isnan(a)] = _nx.inf\n return y.min(axis)\n\ndef nanargmin(a, axis=-1):\n \"\"\"Find the indices of the minimium over the given axis ignoring NaNs.\n \"\"\"\n y = array(a)\n if not issubclass(y.dtype, _nx.integer):\n y[isnan(a)] = _nx.inf \n return y.argmin(axis) \n\ndef nanmax(a, axis=-1):\n \"\"\"Find the maximum over the given axis ignoring NaNs.\n \"\"\"\n y = array(a)\n if not issubclass(y.dtype, _nx.integer):\n y[isnan(a)] = -_nx.inf \n return y.max(axis) \n\ndef nanargmax(a, axis=-1):\n \"\"\"Find the maximum over the given axis ignoring NaNs.\n \"\"\"\n y = array(a)\n if not issubclass(y.dtype, _nx.integer):\n y[isnan(a)] = -_nx.inf \n return y.argmax(axis) \n\ndef disp(mesg, device=None, linefeed=True):\n \"\"\"Display a message to the given device (default is sys.stdout)\n with or without a linefeed.\n \"\"\"\n if device is None:\n import sys\n device = sys.stdout\n if linefeed:\n device.write('%s\\n' % mesg)\n else:\n device.write('%s' % mesg)\n device.flush()\n return\n\nclass vectorize:\n \"\"\"\n vectorize(somefunction, otypes=None, doc=None)\n Generalized Function class.\n\n Description:\n \n Define a vectorized function which takes nested sequence\n objects or scipy arrays as inputs and returns a\n scipy array as output, evaluating the function over successive\n tuples of the input arrays like the python map function except it uses\n the broadcasting rules of scipy. \n\n Input:\n\n somefunction -- a Python function or method\n\n Example:\n\n def myfunc(a, b):\n if a > b:\n return a-b\n else\n return a+b\n\n vfunc = vectorize(myfunc)\n\n >>> vfunc([1, 2, 3, 4], 2)\n array([3, 4, 1, 2])\n\n \"\"\"\n def __init__(self, pyfunc, otypes='', doc=None):\n try:\n fcode = pyfunc.func_code\n except AttributeError:\n raise TypeError, \"object is not a callable Python object\"\n\n self.thefunc = pyfunc\n self.ufunc = None\n self.nin = len(fcode.co_varnames)\n self.nout = None\n if doc is None:\n self.__doc__ = pyfunc.__doc__\n else:\n self.__doc__ = doc\n if isinstance(otypes, types.StringType):\n self.otypes=otypes\n else:\n raise ValueError, \"output types must be a string\"\n for char in self.otypes:\n if char not in typecodes['All']:\n raise ValueError, \"invalid typecode specified\"\n\n def __call__(self, *args):\n # get number of outputs and output types by calling\n # the function on the first entries of args\n if len(args) != self.nin:\n raise ValueError, \"mismatch between python function inputs\"\\\n \" and received arguments\"\n if self.nout is None or self.otypes == '':\n newargs = []\n for arg in args:\n newargs.append(asarray(arg).flat[0])\n theout = self.thefunc(*newargs)\n if isinstance(theout, types.TupleType):\n self.nout = len(theout)\n else:\n self.nout = 1\n theout = (theout,)\n if self.otypes == '':\n otypes = []\n for k in range(self.nout):\n otypes.append(asarray(theout[k]).dtypechar)\n self.otypes = ''.join(otypes)\n\n if self.ufunc is None:\n self.ufunc = frompyfunc(self.thefunc, self.nin, self.nout)\n\n if self.nout == 1:\n return self.ufunc(*args).astype(self.otypes[0])\n else:\n return tuple([x.astype(c) for x, c in zip(self.ufunc(*args), self.otypes)])\n\n\ndef round_(a, decimals=0):\n \"\"\"Round 'a' to the given number of decimal places. Rounding\n behaviour is equivalent to Python.\n\n Return 'a' if the array is not floating point. Round both the real\n and imaginary parts separately if the array is complex.\n \"\"\"\n a = asarray(a)\n if not issubclass(a.dtype, _nx.inexact):\n return a\n if issubclass(a.dtype, _nx.complexfloating):\n return round_(a.real, decimals) + 1j*round_(a.imag, decimals)\n if decimals is not 0:\n decimals = asarray(decimals)\n s = sign(a)\n if decimals is not 0:\n a = absolute(multiply(a, 10.**decimals))\n else:\n a = absolute(a)\n rem = a-asarray(a).astype(_nx.intp)\n a = _nx.where(_nx.less(rem, 0.5), _nx.floor(a), _nx.ceil(a))\n # convert back\n if decimals is not 0:\n return multiply(a, s/(10.**decimals))\n else:\n return multiply(a, s)\n\n", "methods": [ { "name": "binary_repr", "long_name": "binary_repr( num )", "filename": "function_base.py", "nloc": 9, "complexity": 3, "token_count": 50, "parameters": [ "num" ], "start_line": 33, "end_line": 46, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "base_repr", "long_name": "base_repr( number , base = 2 , padding = 0 )", "filename": "function_base.py", "nloc": 14, "complexity": 3, "token_count": 97, "parameters": [ "number", "base", "padding" ], "start_line": 48, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "logspace", "long_name": "logspace( start , stop , num = 50 , endpoint = True )", "filename": "function_base.py", "nloc": 9, "complexity": 3, "token_count": 99, "parameters": [ "start", "stop", "num", "endpoint" ], "start_line": 69, "end_line": 82, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "linspace", "long_name": "linspace( start , stop , num = 50 , endpoint = True , retstep = False )", "filename": "function_base.py", "nloc": 12, "complexity": 4, "token_count": 103, "parameters": [ "start", "stop", "num", "endpoint", "retstep" ], "start_line": 84, "end_line": 99, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "iterable", "long_name": "iterable( y )", "filename": "function_base.py", "nloc": 4, "complexity": 2, "token_count": 17, "parameters": [ "y" ], "start_line": 101, "end_line": 104, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "histogram", "long_name": "histogram( a , bins = 10 , range = None , normed = False )", "filename": "function_base.py", "nloc": 18, "complexity": 6, "token_count": 171, "parameters": [ "a", "bins", "range", "normed" ], "start_line": 106, "end_line": 125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "average", "long_name": "average( a , axis = 0 , weights = None , returned = False )", "filename": "function_base.py", "nloc": 44, "complexity": 12, "token_count": 335, "parameters": [ "a", "axis", "weights", "returned" ], "start_line": 127, "end_line": 197, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 71, "top_nesting_level": 0 }, { "name": "isaltered", "long_name": "isaltered( )", "filename": "function_base.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 200, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "asarray_chkfinite", "long_name": "asarray_chkfinite( a )", "filename": "function_base.py", "nloc": 6, "complexity": 4, "token_count": 57, "parameters": [ "a" ], "start_line": 205, "end_line": 212, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "piecewise", "long_name": "piecewise( x , condlist , funclist , * args , ** kw )", "filename": "function_base.py", "nloc": 21, "complexity": 7, "token_count": 163, "parameters": [ "x", "condlist", "funclist", "args", "kw" ], "start_line": 217, "end_line": 268, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 0 }, { "name": "select", "long_name": "select( condlist , choicelist , default = 0 )", "filename": "function_base.py", "nloc": 18, "complexity": 7, "token_count": 165, "parameters": [ "condlist", "choicelist", "default" ], "start_line": 270, "end_line": 316, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "_asarray1d", "long_name": "_asarray1d( arr , copy = False )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 33, "parameters": [ "arr", "copy" ], "start_line": 318, "end_line": 324, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "copy", "long_name": "copy( a )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "a" ], "start_line": 326, "end_line": 329, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "amax", "long_name": "amax( a , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "a", "axis" ], "start_line": 332, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "amin", "long_name": "amin( a , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "a", "axis" ], "start_line": 337, "end_line": 340, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "alen", "long_name": "alen( a )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "a" ], "start_line": 342, "end_line": 345, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "ptp", "long_name": "ptp( a , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "a", "axis" ], "start_line": 347, "end_line": 350, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "prod", "long_name": "prod( a , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "a", "axis" ], "start_line": 352, "end_line": 355, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "cumprod", "long_name": "cumprod( a , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "a", "axis" ], "start_line": 357, "end_line": 360, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "gradient", "long_name": "gradient( f , * varargs )", "filename": "function_base.py", "nloc": 41, "complexity": 7, "token_count": 325, "parameters": [ "f", "varargs" ], "start_line": 362, "end_line": 434, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 73, "top_nesting_level": 0 }, { "name": "diff", "long_name": "diff( a , n = 1 , axis = - 1 )", "filename": "function_base.py", "nloc": 17, "complexity": 4, "token_count": 142, "parameters": [ "a", "n", "axis" ], "start_line": 437, "end_line": 455, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "angle", "long_name": "angle( z , deg = 0 )", "filename": "function_base.py", "nloc": 13, "complexity": 3, "token_count": 72, "parameters": [ "z", "deg" ], "start_line": 457, "end_line": 471, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "unwrap", "long_name": "unwrap( p , discont = pi , axis = - 1 )", "filename": "function_base.py", "nloc": 13, "complexity": 1, "token_count": 150, "parameters": [ "p", "discont", "axis" ], "start_line": 473, "end_line": 488, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "sort_complex", "long_name": "sort_complex( a )", "filename": "function_base.py", "nloc": 11, "complexity": 4, "token_count": 70, "parameters": [ "a" ], "start_line": 490, "end_line": 505, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "trim_zeros", "long_name": "trim_zeros( filt , trim = 'fb' )", "filename": "function_base.py", "nloc": 13, "complexity": 7, "token_count": 86, "parameters": [ "filt", "trim" ], "start_line": 507, "end_line": 527, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "unique", "long_name": "unique( inseq )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 30, "parameters": [ "inseq" ], "start_line": 529, "end_line": 536, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "extract", "long_name": "extract( condition , arr )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 26, "parameters": [ "condition", "arr" ], "start_line": 538, "end_line": 544, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "insert", "long_name": "insert( arr , mask , vals )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "arr", "mask", "vals" ], "start_line": 546, "end_line": 551, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "nansum", "long_name": "nansum( a , axis = - 1 )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 46, "parameters": [ "a", "axis" ], "start_line": 553, "end_line": 559, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "nanmin", "long_name": "nanmin( a , axis = - 1 )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 48, "parameters": [ "a", "axis" ], "start_line": 561, "end_line": 567, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "nanargmin", "long_name": "nanargmin( a , axis = - 1 )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 48, "parameters": [ "a", "axis" ], "start_line": 569, "end_line": 575, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "nanmax", "long_name": "nanmax( a , axis = - 1 )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 49, "parameters": [ "a", "axis" ], "start_line": 577, "end_line": 583, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "nanargmax", "long_name": "nanargmax( a , axis = - 1 )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 49, "parameters": [ "a", "axis" ], "start_line": 585, "end_line": 591, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "disp", "long_name": "disp( mesg , device = None , linefeed = True )", "filename": "function_base.py", "nloc": 10, "complexity": 3, "token_count": 53, "parameters": [ "mesg", "device", "linefeed" ], "start_line": 593, "end_line": 605, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , pyfunc , otypes = '' , doc = None )", "filename": "function_base.py", "nloc": 20, "complexity": 6, "token_count": 114, "parameters": [ "self", "pyfunc", "otypes", "doc" ], "start_line": 638, "end_line": 658, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , * args )", "filename": "function_base.py", "nloc": 25, "complexity": 11, "token_count": 228, "parameters": [ "self", "args" ], "start_line": 660, "end_line": 688, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "round_", "long_name": "round_( a , decimals = 0 )", "filename": "function_base.py", "nloc": 19, "complexity": 6, "token_count": 184, "parameters": [ "a", "decimals" ], "start_line": 691, "end_line": 716, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 } ], "methods_before": [ { "name": "binary_repr", "long_name": "binary_repr( num )", "filename": "function_base.py", "nloc": 9, "complexity": 3, "token_count": 50, "parameters": [ "num" ], "start_line": 33, "end_line": 46, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "base_repr", "long_name": "base_repr( number , base = 2 , padding = 0 )", "filename": "function_base.py", "nloc": 14, "complexity": 3, "token_count": 97, "parameters": [ "number", "base", "padding" ], "start_line": 48, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "logspace", "long_name": "logspace( start , stop , num = 50 , endpoint = True )", "filename": "function_base.py", "nloc": 9, "complexity": 3, "token_count": 99, "parameters": [ "start", "stop", "num", "endpoint" ], "start_line": 69, "end_line": 82, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "linspace", "long_name": "linspace( start , stop , num = 50 , endpoint = True , retstep = False )", "filename": "function_base.py", "nloc": 12, "complexity": 4, "token_count": 103, "parameters": [ "start", "stop", "num", "endpoint", "retstep" ], "start_line": 84, "end_line": 99, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "iterable", "long_name": "iterable( y )", "filename": "function_base.py", "nloc": 4, "complexity": 2, "token_count": 17, "parameters": [ "y" ], "start_line": 101, "end_line": 104, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "histogram", "long_name": "histogram( a , bins = 10 , range = None , normed = False )", "filename": "function_base.py", "nloc": 18, "complexity": 6, "token_count": 171, "parameters": [ "a", "bins", "range", "normed" ], "start_line": 106, "end_line": 125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "average", "long_name": "average( a , axis = 0 , weights = None , returned = False )", "filename": "function_base.py", "nloc": 44, "complexity": 12, "token_count": 335, "parameters": [ "a", "axis", "weights", "returned" ], "start_line": 127, "end_line": 200, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 74, "top_nesting_level": 0 }, { "name": "isaltered", "long_name": "isaltered( )", "filename": "function_base.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 203, "end_line": 205, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "asarray_chkfinite", "long_name": "asarray_chkfinite( a )", "filename": "function_base.py", "nloc": 6, "complexity": 4, "token_count": 57, "parameters": [ "a" ], "start_line": 208, "end_line": 215, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "piecewise", "long_name": "piecewise( x , condlist , funclist , * args , ** kw )", "filename": "function_base.py", "nloc": 21, "complexity": 7, "token_count": 163, "parameters": [ "x", "condlist", "funclist", "args", "kw" ], "start_line": 220, "end_line": 271, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 0 }, { "name": "select", "long_name": "select( condlist , choicelist , default = 0 )", "filename": "function_base.py", "nloc": 18, "complexity": 7, "token_count": 165, "parameters": [ "condlist", "choicelist", "default" ], "start_line": 273, "end_line": 319, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "_asarray1d", "long_name": "_asarray1d( arr , copy = False )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 33, "parameters": [ "arr", "copy" ], "start_line": 321, "end_line": 327, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "copy", "long_name": "copy( a )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "a" ], "start_line": 329, "end_line": 332, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "amax", "long_name": "amax( a , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "a", "axis" ], "start_line": 335, "end_line": 338, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "amin", "long_name": "amin( a , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "a", "axis" ], "start_line": 340, "end_line": 343, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "alen", "long_name": "alen( a )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "a" ], "start_line": 345, "end_line": 348, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "ptp", "long_name": "ptp( a , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "a", "axis" ], "start_line": 350, "end_line": 353, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "prod", "long_name": "prod( a , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "a", "axis" ], "start_line": 355, "end_line": 358, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "cumprod", "long_name": "cumprod( a , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "a", "axis" ], "start_line": 360, "end_line": 363, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "gradient", "long_name": "gradient( f , * varargs )", "filename": "function_base.py", "nloc": 41, "complexity": 7, "token_count": 325, "parameters": [ "f", "varargs" ], "start_line": 365, "end_line": 437, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 73, "top_nesting_level": 0 }, { "name": "diff", "long_name": "diff( a , n = 1 , axis = - 1 )", "filename": "function_base.py", "nloc": 17, "complexity": 4, "token_count": 142, "parameters": [ "a", "n", "axis" ], "start_line": 440, "end_line": 458, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "angle", "long_name": "angle( z , deg = 0 )", "filename": "function_base.py", "nloc": 13, "complexity": 3, "token_count": 72, "parameters": [ "z", "deg" ], "start_line": 460, "end_line": 474, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "unwrap", "long_name": "unwrap( p , discont = pi , axis = - 1 )", "filename": "function_base.py", "nloc": 13, "complexity": 1, "token_count": 150, "parameters": [ "p", "discont", "axis" ], "start_line": 476, "end_line": 491, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "sort_complex", "long_name": "sort_complex( a )", "filename": "function_base.py", "nloc": 11, "complexity": 4, "token_count": 70, "parameters": [ "a" ], "start_line": 493, "end_line": 508, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "trim_zeros", "long_name": "trim_zeros( filt , trim = 'fb' )", "filename": "function_base.py", "nloc": 13, "complexity": 7, "token_count": 86, "parameters": [ "filt", "trim" ], "start_line": 510, "end_line": 530, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "unique", "long_name": "unique( inseq )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 30, "parameters": [ "inseq" ], "start_line": 532, "end_line": 539, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "extract", "long_name": "extract( condition , arr )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 26, "parameters": [ "condition", "arr" ], "start_line": 541, "end_line": 547, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "insert", "long_name": "insert( arr , mask , vals )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "arr", "mask", "vals" ], "start_line": 549, "end_line": 554, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "nansum", "long_name": "nansum( a , axis = - 1 )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 46, "parameters": [ "a", "axis" ], "start_line": 556, "end_line": 562, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "nanmin", "long_name": "nanmin( a , axis = - 1 )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 48, "parameters": [ "a", "axis" ], "start_line": 564, "end_line": 570, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "nanargmin", "long_name": "nanargmin( a , axis = - 1 )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 48, "parameters": [ "a", "axis" ], "start_line": 572, "end_line": 578, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "nanmax", "long_name": "nanmax( a , axis = - 1 )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 49, "parameters": [ "a", "axis" ], "start_line": 580, "end_line": 586, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "nanargmax", "long_name": "nanargmax( a , axis = - 1 )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 49, "parameters": [ "a", "axis" ], "start_line": 588, "end_line": 594, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "disp", "long_name": "disp( mesg , device = None , linefeed = True )", "filename": "function_base.py", "nloc": 10, "complexity": 3, "token_count": 53, "parameters": [ "mesg", "device", "linefeed" ], "start_line": 596, "end_line": 608, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , pyfunc , otypes = '' , doc = None )", "filename": "function_base.py", "nloc": 20, "complexity": 6, "token_count": 114, "parameters": [ "self", "pyfunc", "otypes", "doc" ], "start_line": 641, "end_line": 661, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , * args )", "filename": "function_base.py", "nloc": 25, "complexity": 11, "token_count": 228, "parameters": [ "self", "args" ], "start_line": 663, "end_line": 691, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "round_", "long_name": "round_( a , decimals = 0 )", "filename": "function_base.py", "nloc": 19, "complexity": 6, "token_count": 184, "parameters": [ "a", "decimals" ], "start_line": 694, "end_line": 719, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "average", "long_name": "average( a , axis = 0 , weights = None , returned = False )", "filename": "function_base.py", "nloc": 44, "complexity": 12, "token_count": 335, "parameters": [ "a", "axis", "weights", "returned" ], "start_line": 127, "end_line": 197, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 71, "top_nesting_level": 0 } ], "nloc": 453, "complexity": 127, "token_count": 3442, "diff_parsed": { "added": [ " Average the array over the given axis. If the axis is None, average", " over all dimensions of the array. Equivalent to a.mean(axis), but", " with a default axis of 0 instead of None.", "", " If an integer axis is given, this equals:", " a.sum(axis) * 1.0 / len(a)", "", " If axis is None, this equals:", " a.sum(axis) * 1.0 / product(a.shape)", "", " If weights are given, result is:", " sum(a * weights) / sum(weights),", " where the weights must have a's shape or be 1D with length the", " size of a in the given axis. Integer weights are converted to", " Float. Not specifying weights is equivalent to specifying", " weights that are all 1.", "", " If 'returned' is True, return a tuple: the result and the sum of", " the weights or count of values. The shape of these two results", " will be the same.", "", " Raises ZeroDivisionError if appropriate. (The version in MA does", " not -- it returns masked values)." ], "deleted": [ " Compute average over the given axis. If axis is None, average", " over all dimensions of the array. Equivalent to a.mean(axis),", " but with a default axis of 0 instead of None.", "", " The average of an integer or floating-point array always has type", " Float.", "", " If an integer axis is given, this equals:", " a.sum(axis) * 1.0 / len(a)", "", " If axis is None, this equals:", " a.sum(axis) * 1.0 / product(a.shape)", "", " If weights are given, result is:", " sum(a * weights) / sum(weights),", " where the weights must have a's shape or be 1D with length the", " size of a in the given axis. Integer weights are converted to", " Float. Not specifying weights is equivalent to specifying", " weights that are all 1.", "", " If 'returned' is True, return a tuple: the result and the sum of", " the weights or count of values. The shape of these two results", " will be the same.", "", " Raises ZeroDivisionError if appropriate. (The version in MA does", " not -- it returns masked values)." ] } }, { "old_path": "scipy/base/src/arraymethods.c", "new_path": "scipy/base/src/arraymethods.c", "filename": "arraymethods.c", "extension": "c", "change_type": "MODIFY", "diff": "@@ -1032,10 +1032,8 @@ array_transpose(PyArrayObject *self, PyObject *args)\n }\n \n static char doc_mean[] = \"a.mean(axis=None, rtype=None)\\n\\n\"\\\n- \"Average the array over the given axis. If axis is None, average over\\n\"\\\n- \"all dimensions of the array.\\n\"\\\n- \"\\n\"\\\n- \"if 'a' has an integer type, the result has type Float.\\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, rtype) * 1.0 / len(a)\\n\"\\\n@@ -1044,13 +1042,8 @@ static char doc_mean[] = \"a.mean(axis=None, rtype=None)\\n\\n\"\\\n \" a.sum(axis, rtype) * 1.0 / product(a.shape)\\n\"\\\n \"\\n\"\\\n \"The optional rtype argument is the data type for intermediate\\n\"\\\n- \"calculations in the sum.\\n\"\\\n- \"\\n\"\\\n- \"If an integer axis is given, this equals:\\n\"\\\n- \" a.sum(axis, rtype) * 1.0 / len(a)\\n\"\\\n- \"\\n\"\\\n- \"If axis is None, this equals:\\n\"\\\n- \" a.sum(axis, rtype) * 1.0 / product(a.shape)\";\n+ \"calculations in the sum.\";\n+\n \n static PyObject *\n array_mean(PyArrayObject *self, PyObject *args, PyObject *kwds) \n@@ -1068,21 +1061,23 @@ array_mean(PyArrayObject *self, PyObject *args, PyObject *kwds)\n }\n \n static char doc_sum[] = \"a.sum(axis=None, rtype=None)\\n\\n\"\\\n- \"Sum the array over the given axis. The optional rtype argument\\n\"\\\n- \"is the data type for intermediate calculations.\\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 default is to upcast (promote) smaller integer types to the\\n\"\\\n- \"platform-dependent Int. For example, on 32-bit platforms:\\n\"\\\n+ \"The optional rtype 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() rtype\\n\"\\\n \" ---------------------------------------------------\\n\"\\\n- \" bool, Int8, Int16, Int32 Int32\\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(rtype=Int32)\\n\"\\\n+ \">>> array([0.5, 1.5]).sum(rtype=int32)\\n\"\\\n \"1\\n\"\\\n \">>> array([[0, 1], [0, 5]]).sum()\\n\"\\\n \"array([0, 6])\\n\"\\\n", "added_lines": 12, "deleted_lines": 17, "source_code": "\n#define _ARET(x) PyArray_Return((PyArrayObject *)(x))\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(indices, values) 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[] = {\"indices\", \"values\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &indices, &values))\n\t\treturn NULL;\n\treturn PyArray_Put(self, indices, values);\n}\n\nstatic char doc_putmask[] = \"a.putmask(mask, values) 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[] = {\"mask\", \"values\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &mask, &values))\n\t\treturn NULL;\n\treturn PyArray_PutMask(self, mask, values);\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.\";\n\nstatic PyObject *\narray_view(PyArrayObject *self, PyObject *args)\n{\n PyArray_Typecode type = {PyArray_NOTYPE, 0, 0};\n\tif (!PyArg_ParseTuple(args, \"|O&\",\n PyArray_TypecodeConverter, &type)) \n return NULL;\n\n\treturn _ARET(PyArray_View(self, &type));\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.field(type, 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 items given.\";\n\nstatic PyObject *\nPyArray_GetField(PyArrayObject *self, PyArray_Typecode *type, \n\t\t\t\t int offset)\n{\n\tPyObject *ret=NULL;\n\tret = PyArray_New(self->ob_type, self->nd, self->dimensions,\n\t\t\t type->type_num, self->strides, \n\t\t\t self->data + offset,\n\t\t\t type->itemsize, self->flags, (PyObject *)self);\n\tif (ret == NULL) return NULL;\n\tPy_INCREF(self);\n\t((PyArrayObject *)ret)->base = (PyObject *)self;\n\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\n\treturn ret;\t\n}\n\nstatic PyObject *\narray_getfield(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n\tPyArray_Typecode typecode = {PyArray_NOTYPE, 0, 0};\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_TypecodeConverter, \n\t\t\t\t\t &typecode, &offset)) return NULL;\n\n\t\n\tif (typecode.itemsize > self->itemsize) {\n\t\tPyErr_SetString(PyExc_TypeError, \"field itemsize must be <=\"\\\n\t\t\t\t\"array itemsize\");\n\t\treturn NULL;\n\t}\n\treturn _ARET(PyArray_GetField(self, &typecode, offset));\n}\n\nstatic PyObject *\nPyArray_Byteswap(PyArrayObject *self, Bool inplace)\n{\n PyArrayObject *ret;\n\tintp size;\n\tPyArray_CopySwapNFunc *copyswapn;\n\tPyArrayIterObject *it;\n\n\tif (inplace) {\n\t\tcopyswapn = self->descr->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, self->itemsize);\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\t\n\t\t\twhile (it->index < it->size) {\n\t\t\t\tcopyswapn(it->dataptr, NULL, 1, 1, \n\t\t\t\t\t self->itemsize);\n\t\t\t\tPyArray_ITER_NEXT(it);\n\t\t\t}\n\t\t\tPy_DECREF(it);\n\t\t}\n\n\t\tif (self->flags & NOTSWAPPED) self->flags &= ~NOTSWAPPED;\n\t\telse self->flags |= NOTSWAPPED;\n\t\t\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n\telse {\n\t\tif ((ret = (PyArrayObject *)PyArray_Copy(self)) == NULL) \n\t\t\treturn NULL;\n\t\t\n\t\tsize = PyArray_SIZE(self);\n\t\t\n\t\t/* set the NOTSWAPPED flag to opposite self */\n\t\t/* ret is always notswapped, \n\t\t PyArray_Copy has already swapped if self was swapped */\n\n\t\tif (self->flags & NOTSWAPPED) {\n\t\t\tret->descr->copyswapn(ret->data, NULL, size, 1, ret->itemsize);\n\t\t\tret->flags &= ~NOTSWAPPED;\n\t\t}\n\t\telse { /* self was swapped, so now ret isn't */\n\t\t\tret->flags |= NOTSWAPPED;\n\t\t}\n\t\t\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.toscalar(). 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->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_Typecode typecode = {PyArray_NOTYPE, 0, 0};\n\t\n if (!PyArg_ParseTuple(args, \"O&\", PyArray_TypecodeConverter,\n\t\t\t &typecode)) return NULL;\n\n\tif (typecode.type_num == PyArray_NOTYPE ||\t\\\n\t typecode.type_num == PyArray_TYPE(self)) {\n\t\treturn _ARET(PyArray_Copy(self));\n\t}\n\treturn _ARET(PyArray_CastToType(self, &typecode));\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\tret = PyArray_New(self->ob_type, PyArray_NDIM(arr),\n\t\t\t PyArray_DIMS(arr), PyArray_TYPE(arr),\n\t\t\t PyArray_STRIDES(arr), PyArray_DATA(arr),\n\t\t\t PyArray_ITEMSIZE(arr), \n\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__(|type) just returns either a new reference to self if type is not given or a new array of type if type is different from the current type of the array.\";\n\nstatic PyObject *\narray_getarray(PyArrayObject *self, PyObject *args) \n{\n\tPyArray_Typecode newtype = {PyArray_NOTYPE, 0, 0};\n\tPyArray_Typecode oldtype = {PyArray_TYPE(self),\n\t\t\t\t PyArray_ITEMSIZE(self),\n\t\t\t\t 0};\n\tPyObject *ret;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\", &PyArray_TypecodeConverter,\n\t\t\t &newtype)) return NULL;\n\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\tnew = PyArray_New(subtype, PyArray_NDIM(self),\n\t\t\t\t PyArray_DIMS(self), PyArray_TYPE(self),\n\t\t\t\t PyArray_STRIDES(self), PyArray_DATA(self),\n\t\t\t\t PyArray_ITEMSIZE(self), \n\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.type_num == PyArray_NOTYPE ||\n\t PyArray_EquivalentTypes(&oldtype, &newtype)) {\n\t\treturn (PyObject *)self;\n\t}\n\telse {\n\t\tret = PyArray_CastToType(self, &newtype);\n\t\tPy_DECREF(self);\n\t\treturn ret;\n\t}\n}\n\nstatic char doc_copy[] = \"m.copy(). Return a copy of the array.\";\n\nstatic PyObject *\narray_copy(PyArrayObject *self, PyObject *args) \n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\t\n return _ARET(PyArray_Copy(self));\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\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 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()\";\n\nstatic PyObject *\narray_sort(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_Sort(self, axis));\n}\n\nstatic char doc_argsort[] = \"a.argsort()\\n\"\\\n\t\" Return the indexes into a that would sort it along the\"\\\n\t\" given axis (or if the sorting should be done\"\\\n\t\" in terms of a.flat\";\n\nstatic PyObject *\narray_argsort(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_ArgSort(self, axis));\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;\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 if (deepcopy == NULL) return NULL;\n Py_DECREF(copy);\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->itemsize;\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\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 *Bool, *thestr=NULL;\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(\"scipy.base.multiarray\");\n\tif (mod == NULL) return NULL;\n\tobj = PyObject_GetAttrString(mod, \"empty\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) return NULL;\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tPyTuple_SET_ITEM(ret, 1, \n\t\t\t Py_BuildValue(\"NNN\",\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,\n\t\t\t\t\t\t\t \"dtypechar\"),\n\t\t\t\t PyInt_FromLong((long) 0)));\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 string giving the typestr (> or < indicates byte order\n\t if swap is possibly needed)\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\"));\t\n\tPyTuple_SET_ITEM(state, 1, PyObject_GetAttrString((PyObject *)self, \n\t\t\t\t\t\t\t \"dtypestr\"));\n\tBool = (PyArray_ISFORTRAN(self) ? Py_True : Py_False);\n\tPy_INCREF(Bool);\n\tPyTuple_SET_ITEM(state, 2, Bool);\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 string giving the typestr (> or < indicates byte order\n\t if swap is possibly needed)\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 PyObject *\narray_setstate(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *shape;\n\tPyArray_Typecode typecode;\n\tlong fortran;\n\tPyObject *rawdata;\n\tchar *datastr;\n\tconst char *typestr;\n\tint len, typestrlen;\n\tint swap;\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!z#iO)\", &PyTuple_Type,\n\t\t\t &shape, &typestr, &typestrlen,\n\t\t\t &fortran, &rawdata))\n\t\treturn NULL;\n\n\tif (_array_typecode_fromstr((char *)typestr, &swap, &typecode) < 0)\n\t\treturn NULL;\n\n\tself->descr = PyArray_DescrFromType(typecode.type_num);\n\tself->itemsize = typecode.itemsize;\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->itemsize *\t\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->itemsize, 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\tself->base = rawdata;\n\t\tPy_INCREF(self->base);\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->itemsize);\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\n\tif (swap) self->flags &= ~NOTSWAPPED;\n\t\n\tPy_INCREF(Py_None);\n\treturn Py_None;\t\n}\n\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), \"rb\");\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\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\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\treturn _ARET(PyArray_Transpose(self, shape));\n}\n\nstatic char doc_mean[] = \"a.mean(axis=None, rtype=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, rtype) * 1.0 / len(a)\\n\"\\\n \"\\n\"\\\n \"If axis is None, this equals:\\n\"\\\n \" a.sum(axis, rtype) * 1.0 / product(a.shape)\\n\"\\\n \"\\n\"\\\n \"The optional rtype argument is the data type for intermediate\\n\"\\\n \"calculations in the sum.\";\n\n\nstatic PyObject *\narray_mean(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\n\treturn _ARET(PyArray_Mean(self, axis, rtype.type_num));\n}\n\nstatic char doc_sum[] = \"a.sum(axis=None, rtype=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 rtype 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() rtype\\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(rtype=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_Typecode rtype = {PyArray_NOTYPE, 0, 0};\t\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_Sum(self, axis, rtype.type_num);\n}\n\n\nstatic char doc_cumsum[] = \"a.cumsum(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_cumsum(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_CumSum(self, axis, rtype.type_num);\n}\n\nstatic char doc_prod[] = \"a.prod(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_prod(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_Prod(self, axis, rtype.type_num);\n}\n\n\nstatic char doc_cumprod[] = \"a.cumprod(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_cumprod(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_CumProd(self, axis, rtype.type_num);\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\n\nstatic char doc_stddev[] = \"a.std(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_stddev(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_Std(self, axis, rtype.type_num);\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, rtype=None)\";\n\nstatic PyObject *\narray_trace(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis1=0, axis2=1, offset=0;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"offset\", \"axis1\", \"axis2\", \"rtype\", 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_TypecodeConverter, &rtype))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Trace(self, offset, axis1, axis2, rtype.type_num));\n}\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\tBool fortran=FALSE;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\",\n\t\t\t PyArray_BoolConverter, &fortran)) \n\t\treturn 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\tBool fortran=FALSE;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_BoolConverter,\n\t\t\t &fortran)) return NULL;\n\n\treturn PyArray_Ravel(self, (int) fortran);\n}\n\n\n\nstatic char doc_setflags[] = \"a.setflags(write=None, swap=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\", \"swap\", \"align\", \"uic\", NULL};\n\tPyObject *write=Py_None;\n\tPyObject *swap=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, \"|OOOO\", kwlist,\n\t\t\t\t\t &write, &swap, &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 if (swap != Py_None) {\n if (PyObject_IsTrue(swap))\n self->flags &= ~NOTSWAPPED;\n else \n self->flags |= NOTSWAPPED;\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic PyMethodDef array_methods[] = {\n {\"tolist\",\t (PyCFunction)array_tolist,\t1, doc_tolist},\n {\"toscalar\", (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 {\"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, doc_sort},\n\t{\"argsort\",\t(PyCFunction)array_argsort, \n\t METH_VARARGS, 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{\"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 {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\n#undef _ARET\n\n\n", "source_code_before": "\n#define _ARET(x) PyArray_Return((PyArrayObject *)(x))\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(indices, values) 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[] = {\"indices\", \"values\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &indices, &values))\n\t\treturn NULL;\n\treturn PyArray_Put(self, indices, values);\n}\n\nstatic char doc_putmask[] = \"a.putmask(mask, values) 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[] = {\"mask\", \"values\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &mask, &values))\n\t\treturn NULL;\n\treturn PyArray_PutMask(self, mask, values);\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.\";\n\nstatic PyObject *\narray_view(PyArrayObject *self, PyObject *args)\n{\n PyArray_Typecode type = {PyArray_NOTYPE, 0, 0};\n\tif (!PyArg_ParseTuple(args, \"|O&\",\n PyArray_TypecodeConverter, &type)) \n return NULL;\n\n\treturn _ARET(PyArray_View(self, &type));\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.field(type, 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 items given.\";\n\nstatic PyObject *\nPyArray_GetField(PyArrayObject *self, PyArray_Typecode *type, \n\t\t\t\t int offset)\n{\n\tPyObject *ret=NULL;\n\tret = PyArray_New(self->ob_type, self->nd, self->dimensions,\n\t\t\t type->type_num, self->strides, \n\t\t\t self->data + offset,\n\t\t\t type->itemsize, self->flags, (PyObject *)self);\n\tif (ret == NULL) return NULL;\n\tPy_INCREF(self);\n\t((PyArrayObject *)ret)->base = (PyObject *)self;\n\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\n\treturn ret;\t\n}\n\nstatic PyObject *\narray_getfield(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n\tPyArray_Typecode typecode = {PyArray_NOTYPE, 0, 0};\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_TypecodeConverter, \n\t\t\t\t\t &typecode, &offset)) return NULL;\n\n\t\n\tif (typecode.itemsize > self->itemsize) {\n\t\tPyErr_SetString(PyExc_TypeError, \"field itemsize must be <=\"\\\n\t\t\t\t\"array itemsize\");\n\t\treturn NULL;\n\t}\n\treturn _ARET(PyArray_GetField(self, &typecode, offset));\n}\n\nstatic PyObject *\nPyArray_Byteswap(PyArrayObject *self, Bool inplace)\n{\n PyArrayObject *ret;\n\tintp size;\n\tPyArray_CopySwapNFunc *copyswapn;\n\tPyArrayIterObject *it;\n\n\tif (inplace) {\n\t\tcopyswapn = self->descr->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, self->itemsize);\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\t\n\t\t\twhile (it->index < it->size) {\n\t\t\t\tcopyswapn(it->dataptr, NULL, 1, 1, \n\t\t\t\t\t self->itemsize);\n\t\t\t\tPyArray_ITER_NEXT(it);\n\t\t\t}\n\t\t\tPy_DECREF(it);\n\t\t}\n\n\t\tif (self->flags & NOTSWAPPED) self->flags &= ~NOTSWAPPED;\n\t\telse self->flags |= NOTSWAPPED;\n\t\t\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n\telse {\n\t\tif ((ret = (PyArrayObject *)PyArray_Copy(self)) == NULL) \n\t\t\treturn NULL;\n\t\t\n\t\tsize = PyArray_SIZE(self);\n\t\t\n\t\t/* set the NOTSWAPPED flag to opposite self */\n\t\t/* ret is always notswapped, \n\t\t PyArray_Copy has already swapped if self was swapped */\n\n\t\tif (self->flags & NOTSWAPPED) {\n\t\t\tret->descr->copyswapn(ret->data, NULL, size, 1, ret->itemsize);\n\t\t\tret->flags &= ~NOTSWAPPED;\n\t\t}\n\t\telse { /* self was swapped, so now ret isn't */\n\t\t\tret->flags |= NOTSWAPPED;\n\t\t}\n\t\t\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.toscalar(). 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->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_Typecode typecode = {PyArray_NOTYPE, 0, 0};\n\t\n if (!PyArg_ParseTuple(args, \"O&\", PyArray_TypecodeConverter,\n\t\t\t &typecode)) return NULL;\n\n\tif (typecode.type_num == PyArray_NOTYPE ||\t\\\n\t typecode.type_num == PyArray_TYPE(self)) {\n\t\treturn _ARET(PyArray_Copy(self));\n\t}\n\treturn _ARET(PyArray_CastToType(self, &typecode));\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\tret = PyArray_New(self->ob_type, PyArray_NDIM(arr),\n\t\t\t PyArray_DIMS(arr), PyArray_TYPE(arr),\n\t\t\t PyArray_STRIDES(arr), PyArray_DATA(arr),\n\t\t\t PyArray_ITEMSIZE(arr), \n\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__(|type) just returns either a new reference to self if type is not given or a new array of type if type is different from the current type of the array.\";\n\nstatic PyObject *\narray_getarray(PyArrayObject *self, PyObject *args) \n{\n\tPyArray_Typecode newtype = {PyArray_NOTYPE, 0, 0};\n\tPyArray_Typecode oldtype = {PyArray_TYPE(self),\n\t\t\t\t PyArray_ITEMSIZE(self),\n\t\t\t\t 0};\n\tPyObject *ret;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\", &PyArray_TypecodeConverter,\n\t\t\t &newtype)) return NULL;\n\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\tnew = PyArray_New(subtype, PyArray_NDIM(self),\n\t\t\t\t PyArray_DIMS(self), PyArray_TYPE(self),\n\t\t\t\t PyArray_STRIDES(self), PyArray_DATA(self),\n\t\t\t\t PyArray_ITEMSIZE(self), \n\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.type_num == PyArray_NOTYPE ||\n\t PyArray_EquivalentTypes(&oldtype, &newtype)) {\n\t\treturn (PyObject *)self;\n\t}\n\telse {\n\t\tret = PyArray_CastToType(self, &newtype);\n\t\tPy_DECREF(self);\n\t\treturn ret;\n\t}\n}\n\nstatic char doc_copy[] = \"m.copy(). Return a copy of the array.\";\n\nstatic PyObject *\narray_copy(PyArrayObject *self, PyObject *args) \n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\t\n return _ARET(PyArray_Copy(self));\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\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 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()\";\n\nstatic PyObject *\narray_sort(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_Sort(self, axis));\n}\n\nstatic char doc_argsort[] = \"a.argsort()\\n\"\\\n\t\" Return the indexes into a that would sort it along the\"\\\n\t\" given axis (or if the sorting should be done\"\\\n\t\" in terms of a.flat\";\n\nstatic PyObject *\narray_argsort(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_ArgSort(self, axis));\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;\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 if (deepcopy == NULL) return NULL;\n Py_DECREF(copy);\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->itemsize;\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\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 *Bool, *thestr=NULL;\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(\"scipy.base.multiarray\");\n\tif (mod == NULL) return NULL;\n\tobj = PyObject_GetAttrString(mod, \"empty\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) return NULL;\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tPyTuple_SET_ITEM(ret, 1, \n\t\t\t Py_BuildValue(\"NNN\",\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,\n\t\t\t\t\t\t\t \"dtypechar\"),\n\t\t\t\t PyInt_FromLong((long) 0)));\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 string giving the typestr (> or < indicates byte order\n\t if swap is possibly needed)\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\"));\t\n\tPyTuple_SET_ITEM(state, 1, PyObject_GetAttrString((PyObject *)self, \n\t\t\t\t\t\t\t \"dtypestr\"));\n\tBool = (PyArray_ISFORTRAN(self) ? Py_True : Py_False);\n\tPy_INCREF(Bool);\n\tPyTuple_SET_ITEM(state, 2, Bool);\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 string giving the typestr (> or < indicates byte order\n\t if swap is possibly needed)\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 PyObject *\narray_setstate(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *shape;\n\tPyArray_Typecode typecode;\n\tlong fortran;\n\tPyObject *rawdata;\n\tchar *datastr;\n\tconst char *typestr;\n\tint len, typestrlen;\n\tint swap;\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!z#iO)\", &PyTuple_Type,\n\t\t\t &shape, &typestr, &typestrlen,\n\t\t\t &fortran, &rawdata))\n\t\treturn NULL;\n\n\tif (_array_typecode_fromstr((char *)typestr, &swap, &typecode) < 0)\n\t\treturn NULL;\n\n\tself->descr = PyArray_DescrFromType(typecode.type_num);\n\tself->itemsize = typecode.itemsize;\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->itemsize *\t\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->itemsize, 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\tself->base = rawdata;\n\t\tPy_INCREF(self->base);\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->itemsize);\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\n\tif (swap) self->flags &= ~NOTSWAPPED;\n\t\n\tPy_INCREF(Py_None);\n\treturn Py_None;\t\n}\n\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), \"rb\");\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\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\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\treturn _ARET(PyArray_Transpose(self, shape));\n}\n\nstatic char doc_mean[] = \"a.mean(axis=None, rtype=None)\\n\\n\"\\\n \"Average the array over the given axis. If axis is None, average over\\n\"\\\n \"all dimensions of the array.\\n\"\\\n \"\\n\"\\\n \"if 'a' has an integer type, the result has type Float.\\n\"\\\n \"\\n\"\\\n \"If an integer axis is given, this equals:\\n\"\\\n \" a.sum(axis, rtype) * 1.0 / len(a)\\n\"\\\n \"\\n\"\\\n \"If axis is None, this equals:\\n\"\\\n \" a.sum(axis, rtype) * 1.0 / product(a.shape)\\n\"\\\n \"\\n\"\\\n \"The optional rtype argument is the data type for intermediate\\n\"\\\n \"calculations in the sum.\\n\"\\\n \"\\n\"\\\n \"If an integer axis is given, this equals:\\n\"\\\n \" a.sum(axis, rtype) * 1.0 / len(a)\\n\"\\\n \"\\n\"\\\n \"If axis is None, this equals:\\n\"\\\n \" a.sum(axis, rtype) * 1.0 / product(a.shape)\";\n\nstatic PyObject *\narray_mean(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\n\treturn _ARET(PyArray_Mean(self, axis, rtype.type_num));\n}\n\nstatic char doc_sum[] = \"a.sum(axis=None, rtype=None)\\n\\n\"\\\n \"Sum the array over the given axis. The optional rtype argument\\n\"\\\n \"is the data type for intermediate calculations.\\n\"\\\n \"\\n\"\\\n \"The default is to upcast (promote) smaller integer types to the\\n\"\\\n \"platform-dependent Int. For example, on 32-bit platforms:\\n\"\\\n \"\\n\"\\\n \" a.dtype default sum() rtype\\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(rtype=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_Typecode rtype = {PyArray_NOTYPE, 0, 0};\t\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_Sum(self, axis, rtype.type_num);\n}\n\n\nstatic char doc_cumsum[] = \"a.cumsum(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_cumsum(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_CumSum(self, axis, rtype.type_num);\n}\n\nstatic char doc_prod[] = \"a.prod(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_prod(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_Prod(self, axis, rtype.type_num);\n}\n\n\nstatic char doc_cumprod[] = \"a.cumprod(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_cumprod(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_CumProd(self, axis, rtype.type_num);\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\n\nstatic char doc_stddev[] = \"a.std(axis=None, rtype=None)\";\n\nstatic PyObject *\narray_stddev(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"axis\", \"rtype\", 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_TypecodeConverter,\n\t\t\t\t\t &rtype)) return NULL;\n\t\n\treturn PyArray_Std(self, axis, rtype.type_num);\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, rtype=None)\";\n\nstatic PyObject *\narray_trace(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis1=0, axis2=1, offset=0;\n\tPyArray_Typecode rtype = {PyArray_NOTYPE, 0, 0};\n\tstatic char *kwlist[] = {\"offset\", \"axis1\", \"axis2\", \"rtype\", 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_TypecodeConverter, &rtype))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Trace(self, offset, axis1, axis2, rtype.type_num));\n}\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\tBool fortran=FALSE;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\",\n\t\t\t PyArray_BoolConverter, &fortran)) \n\t\treturn 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\tBool fortran=FALSE;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_BoolConverter,\n\t\t\t &fortran)) return NULL;\n\n\treturn PyArray_Ravel(self, (int) fortran);\n}\n\n\n\nstatic char doc_setflags[] = \"a.setflags(write=None, swap=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\", \"swap\", \"align\", \"uic\", NULL};\n\tPyObject *write=Py_None;\n\tPyObject *swap=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, \"|OOOO\", kwlist,\n\t\t\t\t\t &write, &swap, &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 if (swap != Py_None) {\n if (PyObject_IsTrue(swap))\n self->flags &= ~NOTSWAPPED;\n else \n self->flags |= NOTSWAPPED;\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic PyMethodDef array_methods[] = {\n {\"tolist\",\t (PyCFunction)array_tolist,\t1, doc_tolist},\n {\"toscalar\", (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 {\"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, doc_sort},\n\t{\"argsort\",\t(PyCFunction)array_argsort, \n\t METH_VARARGS, 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{\"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 {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": 7, "end_line": 20, "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": 26, "end_line": 34, "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": 41, "end_line": 50, "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": 56, "end_line": 66, "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": 70, "end_line": 84, "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": 47, "complexity": 13, "token_count": 290, "parameters": [ "self", "args" ], "start_line": 92, "end_line": 141, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "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": 146, "end_line": 150, "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": 8, "complexity": 2, "token_count": 53, "parameters": [ "self", "args" ], "start_line": 157, "end_line": 165, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "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": 170, "end_line": 178, "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": 183, "end_line": 191, "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": 196, "end_line": 204, "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": 209, "end_line": 217, "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": 223, "end_line": 231, "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": 237, "end_line": 244, "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_Typecode * type , int offset)", "filename": "arraymethods.c", "nloc": 14, "complexity": 2, "token_count": 110, "parameters": [ "self", "type", "offset" ], "start_line": 252, "end_line": 265, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "array_getfield", "long_name": "array_getfield( PyArrayObject * self , PyObject * args , PyObject * kwds)", "filename": "arraymethods.c", "nloc": 15, "complexity": 3, "token_count": 110, "parameters": [ "self", "args", "kwds" ], "start_line": 268, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "PyArray_Byteswap", "long_name": "PyArray_Byteswap( PyArrayObject * self , Bool inplace)", "filename": "arraymethods.c", "nloc": 41, "complexity": 7, "token_count": 247, "parameters": [ "self", "inplace" ], "start_line": 288, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "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": 348, "end_line": 356, "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": 362, "end_line": 372, "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": 378, "end_line": 382, "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": 206, "parameters": [ "self", "args", "kwds" ], "start_line": 387, "end_line": 421, "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": 69, "parameters": [ "self", "args" ], "start_line": 427, "end_line": 436, "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": 11, "complexity": 4, "token_count": 82, "parameters": [ "self", "args" ], "start_line": 443, "end_line": 455, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "array_wraparray", "long_name": "array_wraparray( PyArrayObject * self , PyObject * args)", "filename": "arraymethods.c", "nloc": 25, "complexity": 4, "token_count": 144, "parameters": [ "self", "args" ], "start_line": 463, "end_line": 489, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "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": 493, "end_line": 497, "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": 242, "parameters": [ "self", "args" ], "start_line": 503, "end_line": 546, "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": 5, "complexity": 2, "token_count": 34, "parameters": [ "self", "args" ], "start_line": 551, "end_line": 556, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "array_resize", "long_name": "array_resize( PyArrayObject * self , PyObject * args)", "filename": "arraymethods.c", "nloc": 25, "complexity": 5, "token_count": 120, "parameters": [ "self", "args" ], "start_line": 564, "end_line": 589, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "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": 75, "parameters": [ "self", "args", "kwds" ], "start_line": 597, "end_line": 607, "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": 617, "end_line": 632, "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)", "filename": "arraymethods.c", "nloc": 7, "complexity": 2, "token_count": 46, "parameters": [ "self", "args" ], "start_line": 637, "end_line": 645, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "array_argsort", "long_name": "array_argsort( PyArrayObject * self , PyObject * args)", "filename": "arraymethods.c", "nloc": 7, "complexity": 2, "token_count": 46, "parameters": [ "self", "args" ], "start_line": 653, "end_line": 661, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "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": 673, "end_line": 680, "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": 685, "end_line": 718, "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": 722, "end_line": 741, "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": 113, "parameters": [ "self", "list" ], "start_line": 744, "end_line": 762, "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": 45, "complexity": 8, "token_count": 301, "parameters": [ "self", "args" ], "start_line": 768, "end_line": 831, "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": 88, "complexity": 17, "token_count": 534, "parameters": [ "self", "args" ], "start_line": 846, "end_line": 951, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 106, "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": 954, "end_line": 975, "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": 978, "end_line": 989, "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": 995, "end_line": 1006, "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": 1011, "end_line": 1016, "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": 9, "complexity": 3, "token_count": 65, "parameters": [ "self", "args" ], "start_line": 1022, "end_line": 1032, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "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": 89, "parameters": [ "self", "args", "kwds" ], "start_line": 1049, "end_line": 1061, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1088, "end_line": 1100, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1106, "end_line": 1118, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1123, "end_line": 1135, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1141, "end_line": 1153, "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": 1159, "end_line": 1167, "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": 1172, "end_line": 1180, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1186, "end_line": 1198, "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": 1203, "end_line": 1214, "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": 1220, "end_line": 1225, "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": 11, "complexity": 2, "token_count": 109, "parameters": [ "self", "args", "kwds" ], "start_line": 1231, "end_line": 1243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 1249, "end_line": 1259, "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": 1266, "end_line": 1272, "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": 1278, "end_line": 1288, "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": 8, "complexity": 2, "token_count": 46, "parameters": [ "self", "args" ], "start_line": 1293, "end_line": 1302, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "array_ravel", "long_name": "array_ravel( PyArrayObject * self , PyObject * args)", "filename": "arraymethods.c", "nloc": 7, "complexity": 2, "token_count": 46, "parameters": [ "self", "args" ], "start_line": 1307, "end_line": 1315, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "array_setflags", "long_name": "array_setflags( PyArrayObject * self , PyObject * args , PyObject * kwds)", "filename": "arraymethods.c", "nloc": 60, "complexity": 12, "token_count": 299, "parameters": [ "self", "args", "kwds" ], "start_line": 1325, "end_line": 1389, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 65, "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": 7, "end_line": 20, "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": 26, "end_line": 34, "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": 41, "end_line": 50, "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": 56, "end_line": 66, "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": 70, "end_line": 84, "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": 47, "complexity": 13, "token_count": 290, "parameters": [ "self", "args" ], "start_line": 92, "end_line": 141, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "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": 146, "end_line": 150, "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": 8, "complexity": 2, "token_count": 53, "parameters": [ "self", "args" ], "start_line": 157, "end_line": 165, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "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": 170, "end_line": 178, "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": 183, "end_line": 191, "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": 196, "end_line": 204, "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": 209, "end_line": 217, "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": 223, "end_line": 231, "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": 237, "end_line": 244, "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_Typecode * type , int offset)", "filename": "arraymethods.c", "nloc": 14, "complexity": 2, "token_count": 110, "parameters": [ "self", "type", "offset" ], "start_line": 252, "end_line": 265, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "array_getfield", "long_name": "array_getfield( PyArrayObject * self , PyObject * args , PyObject * kwds)", "filename": "arraymethods.c", "nloc": 15, "complexity": 3, "token_count": 110, "parameters": [ "self", "args", "kwds" ], "start_line": 268, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "PyArray_Byteswap", "long_name": "PyArray_Byteswap( PyArrayObject * self , Bool inplace)", "filename": "arraymethods.c", "nloc": 41, "complexity": 7, "token_count": 247, "parameters": [ "self", "inplace" ], "start_line": 288, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "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": 348, "end_line": 356, "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": 362, "end_line": 372, "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": 378, "end_line": 382, "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": 206, "parameters": [ "self", "args", "kwds" ], "start_line": 387, "end_line": 421, "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": 69, "parameters": [ "self", "args" ], "start_line": 427, "end_line": 436, "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": 11, "complexity": 4, "token_count": 82, "parameters": [ "self", "args" ], "start_line": 443, "end_line": 455, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "array_wraparray", "long_name": "array_wraparray( PyArrayObject * self , PyObject * args)", "filename": "arraymethods.c", "nloc": 25, "complexity": 4, "token_count": 144, "parameters": [ "self", "args" ], "start_line": 463, "end_line": 489, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "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": 493, "end_line": 497, "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": 242, "parameters": [ "self", "args" ], "start_line": 503, "end_line": 546, "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": 5, "complexity": 2, "token_count": 34, "parameters": [ "self", "args" ], "start_line": 551, "end_line": 556, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "array_resize", "long_name": "array_resize( PyArrayObject * self , PyObject * args)", "filename": "arraymethods.c", "nloc": 25, "complexity": 5, "token_count": 120, "parameters": [ "self", "args" ], "start_line": 564, "end_line": 589, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "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": 75, "parameters": [ "self", "args", "kwds" ], "start_line": 597, "end_line": 607, "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": 617, "end_line": 632, "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)", "filename": "arraymethods.c", "nloc": 7, "complexity": 2, "token_count": 46, "parameters": [ "self", "args" ], "start_line": 637, "end_line": 645, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "array_argsort", "long_name": "array_argsort( PyArrayObject * self , PyObject * args)", "filename": "arraymethods.c", "nloc": 7, "complexity": 2, "token_count": 46, "parameters": [ "self", "args" ], "start_line": 653, "end_line": 661, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "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": 673, "end_line": 680, "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": 685, "end_line": 718, "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": 722, "end_line": 741, "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": 113, "parameters": [ "self", "list" ], "start_line": 744, "end_line": 762, "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": 45, "complexity": 8, "token_count": 301, "parameters": [ "self", "args" ], "start_line": 768, "end_line": 831, "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": 88, "complexity": 17, "token_count": 534, "parameters": [ "self", "args" ], "start_line": 846, "end_line": 951, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 106, "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": 954, "end_line": 975, "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": 978, "end_line": 989, "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": 995, "end_line": 1006, "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": 1011, "end_line": 1016, "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": 9, "complexity": 3, "token_count": 65, "parameters": [ "self", "args" ], "start_line": 1022, "end_line": 1032, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "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": 89, "parameters": [ "self", "args", "kwds" ], "start_line": 1056, "end_line": 1068, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1093, "end_line": 1105, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1111, "end_line": 1123, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1128, "end_line": 1140, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1146, "end_line": 1158, "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": 1164, "end_line": 1172, "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": 1177, "end_line": 1185, "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": 86, "parameters": [ "self", "args", "kwds" ], "start_line": 1191, "end_line": 1203, "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": 1208, "end_line": 1219, "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": 1225, "end_line": 1230, "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": 11, "complexity": 2, "token_count": 109, "parameters": [ "self", "args", "kwds" ], "start_line": 1236, "end_line": 1248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 1254, "end_line": 1264, "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": 1271, "end_line": 1277, "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": 1283, "end_line": 1293, "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": 8, "complexity": 2, "token_count": 46, "parameters": [ "self", "args" ], "start_line": 1298, "end_line": 1307, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "array_ravel", "long_name": "array_ravel( PyArrayObject * self , PyObject * args)", "filename": "arraymethods.c", "nloc": 7, "complexity": 2, "token_count": 46, "parameters": [ "self", "args" ], "start_line": 1312, "end_line": 1320, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "array_setflags", "long_name": "array_setflags( PyArrayObject * self , PyObject * args , PyObject * kwds)", "filename": "arraymethods.c", "nloc": 60, "complexity": 12, "token_count": 299, "parameters": [ "self", "args", "kwds" ], "start_line": 1330, "end_line": 1394, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 65, "top_nesting_level": 0 } ], "changed_methods": [], "nloc": 1189, "complexity": 205, "token_count": 7429, "diff_parsed": { "added": [ " \"Average the array over the given axis. If the axis is None, average\\n\"\\", " \"over all dimensions of the array.\\n\"\\", " \"calculations in the sum.\";", "", " \"Sum the array over the given axis. If the axis is None, sum over all\\n\"\\", " \"dimensions of the array.\\n\"\\", " \"The optional rtype argument is the data type for the returned value\\n\"\\", " \"and intermediate calculations. The default is to upcast (promote)\\n\"\\", " \"smaller integer types to the platform-dependent int. For example, on\\n\"\\", " \"32-bit platforms:\\n\"\\", " \" bool, int8, int16, int32 int32\\n\"\\", " \">>> array([0.5, 1.5]).sum(rtype=int32)\\n\"\\" ], "deleted": [ " \"Average the array over the given axis. If axis is None, average over\\n\"\\", " \"all dimensions of the array.\\n\"\\", " \"\\n\"\\", " \"if 'a' has an integer type, the result has type Float.\\n\"\\", " \"calculations in the sum.\\n\"\\", " \"\\n\"\\", " \"If an integer axis is given, this equals:\\n\"\\", " \" a.sum(axis, rtype) * 1.0 / len(a)\\n\"\\", " \"\\n\"\\", " \"If axis is None, this equals:\\n\"\\", " \" a.sum(axis, rtype) * 1.0 / product(a.shape)\";", " \"Sum the array over the given axis. The optional rtype argument\\n\"\\", " \"is the data type for intermediate calculations.\\n\"\\", " \"The default is to upcast (promote) smaller integer types to the\\n\"\\", " \"platform-dependent Int. For example, on 32-bit platforms:\\n\"\\", " \" bool, Int8, Int16, Int32 Int32\\n\"\\", " \">>> array([0.5, 1.5].sum(rtype=Int32)\\n\"\\" ] } } ] }, { "hash": "8fcb1062d57eebd4aa12bd00a323209fe5acd563", "msg": "Fix for rank-0 arrays. Now a[0] = 1 throws an IndexError, just like\nreading from a[0] does.\n\n** Note: assigning a[-1] = 0 still segfaults! **", "author": { "name": "edschofield", "email": "edschofield@localhost" }, "committer": { "name": "edschofield", "email": "edschofield@localhost" }, "author_date": "2005-10-27T16:50:32+00:00", "author_timezone": 0, "committer_date": "2005-10-27T16:50:32+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "4e736713fb9865aae3e889c48420ddaf1fe4fa69" ], "project_name": "repo_copy", "project_path": "/tmp/tmpn4cqam_6/repo_copy", "deletions": 1, "insertions": 6, "lines": 7, "files": 1, "dmm_unit_size": 1.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy/base/src/arrayobject.c", "new_path": "scipy/base/src/arrayobject.c", "filename": "arrayobject.c", "extension": "c", "change_type": "MODIFY", "diff": "@@ -569,7 +569,12 @@ copy_and_swap(void *dst, void *src, int itemsize, intp numitems,\n static char *\n index2ptr(PyArrayObject *mp, intp i) \n {\n-\tif (i==0 && (mp->nd == 0 || mp->dimensions[0] > 0)) \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", "added_lines": 6, "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\n/* $Id: arrayobject.c,v 1.59 2005/09/14 00:14:00 teoliphant Exp $ */\n\n/*\n#include \"Python.h\"\n#include \"structmember.h\"\n\n#define _MULTIARRAYMODULE\n#include \"Numeric3/arrayobject.h\"\n*/\n\n/* Helper functions */\n\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\n\nstatic intp\nPyArray_PyIntAsIntp(PyObject *o)\n{\n\tlonglong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr=NULL;\n\tPyArray_Typecode typecode = {PyArray_INTP, 0, 0};\n\tintp ret;\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\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\tarr = PyArray_CastToType((PyArrayObject *)o, &typecode);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tarr = PyArray_FromScalar(o, &typecode);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((intp *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\t\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONGLONG != SIZEOF_PY_INTPTR_T)\n\tif ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C intp\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (intp) long_value;\n}\n\n\nstatic PyObject *array_int(PyArrayObject *v);\n\nstatic int\nPyArray_PyIntAsInt(PyObject *o)\n{\n\tlong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr=NULL;\n\tPyArray_Typecode typecode = {PyArray_INT, 0, 0};\n\tint ret;\n\t\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\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\tarr = PyArray_CastToType((PyArrayObject *)o, &typecode);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tarr = PyArray_FromScalar(o, &typecode);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((int *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONG != SIZEOF_INT)\n\tif ((long_value < INT_MIN) || (long_value > INT_MAX)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C int\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (int) long_value;\n}\n\n\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\nstatic char *\nPyArray_Zero(PyArrayObject *arr)\n{\n char *zeroval;\n char *buf;\n int buf_len;\n PyObject *obj, *ret;\n\n zeroval = PyDataMem_NEW(arr->itemsize);\n if (zeroval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n if (PyArray_ISOBJECT(arr)) {\n obj=PyInt_FromLong((long) 0);\n memcpy(zeroval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return zeroval;\n }\n ret = PyObject_GetAttrString((PyObject *)arr, \"_zero\");\n if (ret != NULL) {\n if (PyObject_AsReadBuffer(ret, (const void **)&buf, \n &buf_len) < 0) {\n PyErr_SetString(PyExc_ValueError, \n \"_zero not returning \" \\\n \"writeable buffer\");\n Py_DECREF(ret);\n return NULL;\n }\n memcpy(zeroval, buf, buf_len);\n Py_DECREF(ret);\n }\n if (PyErr_Occurred()) PyErr_Clear();\n memset(zeroval, 0, arr->itemsize);\n return zeroval;\n}\n\nstatic char *\nPyArray_One(PyArrayObject *arr)\n{\n char *oneval;\n char *buf;\n int buf_len, ret2;\n PyObject *obj, *ret;\n\n oneval = PyDataMem_NEW(arr->itemsize);\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 ret = PyObject_GetAttrString((PyObject *)arr, \"_one\");\n if (ret != NULL) {\n if (PyObject_AsReadBuffer(ret, (const void **)&buf, \n &buf_len) < 0) {\n PyErr_SetString(PyExc_ValueError, \n \"_one not returning \" \\\n \"writeable buffer\");\n Py_DECREF(ret);\n PyDataMem_FREE(oneval);\n return NULL;\n }\n memcpy(oneval, buf, buf_len);\n Py_DECREF(ret);\n }\n if (PyErr_Occurred()) PyErr_Clear();\n\n ret2 = arr->descr->setitem(obj, oneval, arr);\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->itemsize;\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 *)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 { free(new_data); return NULL; }\n}\n\n/* end Helper functions */\n\n\nstatic PyObject *PyArray_New(PyTypeObject *, int nd, intp *, \n int, intp *, char *, 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. */\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/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\n\nstatic char *\nindex2ptr(PyArrayObject *mp, intp i) \n{\n\tif(mp->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n\tif (i==0 && mp->dimensions[0] > 0)\n\t\treturn mp->data;\n\t\n if (mp->nd>0 && i>0 && i < mp->dimensions[0]) {\n return mp->data+i*mp->strides[0];\n }\n PyErr_SetString(PyExc_IndexError,\"index out of bounds\");\n return NULL;\n}\n\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\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->copyswap;\n\tcopyswapn = dest->descr->copyswapn;\n\n elsize = dest->itemsize;\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->itemsize;\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\tPyArray_Typecode typecode;\n\n\n\ttypecode.type_num = dest->descr->type_num;\n\ttypecode.itemsize = dest->itemsize;\n\ttypecode.fortran = PyArray_ISFORTRAN(dest);\n\t\t\t\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n\t\t\t\t\t &typecode, 0,\n\t\t\t\t\t dest->nd, 0);\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\nstatic PyObject *\nPyArray_FromDimsAndDataAndDescr(int nd, int *d, \n PyArray_Descr *descr,\n char *data) {\n\tPyObject *ret;\n\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\n\tintp newd[MAX_DIMS];\n\t\n\tfor (i=0; itype_num, NULL, data, descr->elsize, \n\t\t\t CARRAY_FLAGS, NULL);\n#else\n\tret = PyArray_New(&PyArray_Type, nd, (intp *)d, \n descr->type_num, NULL, data, descr->elsize, \n\t\t\t CARRAY_FLAGS, NULL);\n#endif\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_FromDimsAndData(int nd, int *d, int type, char *data) \n{\n\tPyObject *ret;\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\t\n\tintp newd[MAX_DIMS];\n\n\tfor (i=0; iob_type, m1->nd, \n\t\t\t\t\t m1->dimensions,\n\t\t\t\t\t m1->descr->type_num,\n\t\t\t\t\t NULL, NULL, m1->itemsize,\n\t\t\t\t\t 0, (PyObject *)m1);\n\t\n if (PyArray_CopyInto(ret, m1) == -1) return NULL;\n\t\n return (PyObject *)ret;\n}\n\n\nstatic PyObject *array_big_item(PyArrayObject *, intp);\n\nstatic PyObject *\nPyArray_Scalar(char *data, int type_num, int itemsize, int swap)\n{\n PyArray_Descr *descr;\n\tPyTypeObject *type;\n\tPyObject *obj;\t\n\tchar *destptr;\n PyArray_CopySwapFunc *copyswap;\n\n descr = PyArray_DescrFromType(type_num);\n if (descr == NULL) return NULL;\n type = descr->typeobj;\n copyswap = descr->copyswap;\n\tif (type_num == PyArray_STRING) \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_ISFLEXIBLE(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 {\n\t\t\tdestptr = PyDataMem_NEW(itemsize);\n\t\t\tif (destptr == NULL) {\n\t\t\t\tPyObject_Del(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tif (type_num == PyArray_UNICODE) {\n\t\t\t\tPyUnicode_AS_UNICODE(obj) = \\\n\t\t\t\t\t(Py_UNICODE *)destptr;\n\t\t\t\t((PyUnicodeObject*)obj)->length = itemsize / \\\n\t\t\t\t\tsizeof(Py_UNICODE);\n\t\t\t\t((PyUnicodeObject*)obj)->hash = -1;\n\t\t\t}\n\t\t\telse {\n\t\t\t\t((PyVoidScalarObject *)obj)->obval = destptr;\n\t\t\t\t((PyVoidScalarObject *)obj)->ob_size = itemsize;\n\t\t\t}\n\t\t}\n\t}\n\telse {\n\t\tdestptr = &(((PyScalarObject*)obj)->obval);\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*/\nstatic PyObject *\nPyArray_ToScalar(char *data, PyArrayObject *arr)\n{\n\tint type_num = arr->descr->type_num;\n\tint itemsize = arr->itemsize;\n int swap = !(PyArray_ISNOTSWAPPED(arr));\n\n\treturn PyArray_Scalar(data, type_num, itemsize, swap);\n}\n\n\n/* Return Python scalar if 0-d array object is encountered */\n\nstatic PyObject *\nPyArray_Return(PyArrayObject *mp) \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((PyObject *)mp) && 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*/\nstatic int \nPyArray_RegisterDataType(PyTypeObject *type)\n{\n\tPyArray_Descr *descr;\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 = malloc(sizeof(PyArray_Descr));\n\tmemcpy(descr, PyArray_DescrFromType(PyArray_VOID), \n\t sizeof(PyArray_Descr));\n\ttypenum = PyArray_USERDEF + PyArray_NUMUSERTYPES;\n\tdescr->type_num = typenum;\n\tdescr->typeobj = 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 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 frees the copy of the Descr_table already there.\n places a pointer to the new one into the slot.\n*/\nstatic int\nPyArray_RegisterDescrForType(int typenum, PyArray_Descr *descr)\n{\n\tPyArray_Descr *old;\n\tint i;\n\n\tif (!PyTypeNum_ISUSERDEF(typenum)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"data type not registered\");\n\t\treturn -1;\n\t}\n\told = userdescrs[typenum-PyArray_USERDEF];\n\tdescr->typeobj = old->typeobj;\n\tdescr->type_num = typenum;\n\n#define _NULL_CHECK(member) \\\n\tif (descr->member == NULL) descr->member = old->member\n\n\tfor (i=0; imember == 0) descr->member = old->member\n\n\t_ZERO_CHECK(kind);\n\t_ZERO_CHECK(type);\n\t_ZERO_CHECK(elsize);\n\t_ZERO_CHECK(alignment);\n#undef _ZERO_CHECK\n\n\tfree(old);\n\tuserdescrs[typenum-PyArray_USERDEF] = descr;\n\treturn 0;\n}\n\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 n3 = strlen((const char *)sep);\n if (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 \"\\\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->itemsize,\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->itemsize,\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 = strlen((const char *)format);\n while(it->index < it->size) {\n obj = self->descr->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\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->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\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 if (PyArray_TYPE(self) == PyArray_OBJECT) {\n PyErr_SetString(PyExc_ValueError, \"a string for the data\"\\\n\t\t\t\t\"in an object array is not appropriate\");\n return NULL;\n }\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->itemsize;\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 != NULL)) {\n\t\t/* Free internal references if an Object array */\n\t\tPyArray_XDECREF(self);\n\n PyDataMem_FREE(self->data);\n }\n\t\n if (self->dimensions != NULL) {\n PyDimMem_FREE(self->dimensions); \n\t}\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\n\nstatic PyObject *\narray_big_item(PyArrayObject *self, intp i) \n{\n\tchar *item;\n\tPyArrayObject *r;\n\t\n\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\tr = (PyArrayObject *)PyArray_New(self->ob_type, \n\t\t\t\t\t self->nd-1, self->dimensions+1, \n\t\t\t\t\t self->descr->type_num, \n\t\t\t\t\t self->strides+1, item, \n\t\t\t\t\t self->itemsize, self->flags,\n\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\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->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, int *v)\n{\n\t*v = PyArray_PyIntAsInt(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, int length,\n int *start, int *stop, int *step,\n intp *slicelength)\n{\n\tint 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 int\nparse_subindex(PyObject *op, int *step_size, intp *n_steps, int max)\n{\n\tint 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\tint 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_PyIntAsInt(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, start, offset, n_add, n_pseudo;\n int step_size;\n\tintp n_steps;\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, *tup;\n\tint n1, n2, n3, val;\n\tint i;\n\n\ttup = PyTuple_New(mit->nd);\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\tPyTuple_SET_ITEM(tup, i++, PyInt_FromLong((long)val++));\n\tval = 0;\n\twhile(val < n1)\n\t\tPyTuple_SET_ITEM(tup, i++, PyInt_FromLong((long)val++));\n\tval = n1+n2;\n\twhile(val < n3)\n\t\tPyTuple_SET_ITEM(tup, i++, PyInt_FromLong((long)val++));\n\n\tnew = PyArray_Transpose(*ret, tup);\n\tPy_DECREF(tup);\n\tPy_DECREF(*ret);\n\t*ret = (PyArrayObject *)new;\n}\n\n\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\tret = (PyArrayObject *)\\\n\t\tPyArray_New(temp->ob_type, mit->nd, mit->dimensions, \n\t\t\t temp->descr->type_num, NULL, NULL, \n\t\t\t temp->itemsize, \n\t\t\t PyArray_ISFORTRAN(temp),\n\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\treturn NULL;\n\tindex = it->size;\n\tswap = ((temp->flags & NOTSWAPPED) != (ret->flags & NOTSWAPPED));\n copyswap = ret->descr->copyswap;\n\tPyArray_MapIterReset(mit);\n\twhile (index--) {\n copyswap(it->dataptr, mit->dataptr, swap, ret->itemsize);\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\tPyArray_Typecode typecode = {0, 0, 0};\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Unbound Map Iterator */\n\tif (mit->ait == NULL) return -1;\n\n\ttypecode.type_num = mit->ait->ao->descr->type_num;\n\ttypecode.itemsize = mit->ait->ao->itemsize;\n\n\tarr = PyArray_FromAny(op, &typecode, \n\t\t\t 0, 0, FORCECAST);\n\tif (arr == NULL) return -1;\n\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, (PyArrayObject **)&arr);\n\t\t}\n\t}\n\t\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) \n\t\treturn -1;\n\n\tindex = mit->size;\n\tswap = ((mit->ait->ao->flags & NOTSWAPPED) != \\\n\t\t(PyArray_FLAGS(arr) & NOTSWAPPED));\n\n copyswap = PyArray_DESCR(arr)->copyswap;\n\tPyArray_MapIterReset(mit);\n /* Need to decref OBJECT arrays */\n if (PyTypeNum_ISOBJECT(typecode.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 copyswap(mit->dataptr, NULL, swap, \n sizeof(PyObject *));\n PyArray_MapIterNext(mit);\n PyArray_ITER_NEXT(it);\n if (it->index == it->size)\n PyArray_ITER_RESET(it);\n }\n return 0;\n }\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\treturn 0;\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 0-dimensional arrays */\n\nstatic PyObject *\narray_subscript(PyArrayObject *self, PyObject *op) \n{\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n\tintp offset;\n int nd;\n\tintp i;\n PyArrayObject *other;\n\tPyArrayMapIterObject *mit;\n\n if (PyArray_IsScalar(op, Integer) || PyInt_Check(op) || \\\n PyLong_Check(op)) {\n intp value;\n value = PyArray_PyIntAsIntp(op);\n if (PyErr_Occurred())\n PyErr_Clear();\n else if (value >= 0) {\n if (value <= MAX_INT)\n return array_big_item(self, value);\n }\n else if (value < 0) {\n if (value >= -MAX_INT) {\n if (self->nd > 0) value += self->dimensions[0];\n return array_big_item(self, value);\n }\n }\n }\n\n\tif (PyArrayMapIter_Check(op)) {\n\t\tmit = (PyArrayMapIterObject *)op;\n\t\t/* bind to current array */\n\t\tPyArray_MapIterBind(mit, self);\n\t\t\n\t\t/* If the mapiterator was created with standard indexing\n\t\t behavior, fall through to view-based code */\n\t\tif (!mit->view) return PyArray_GetMap(mit);\n\t\top = mit->indexobj;\n\t}\n\telse { /* wrap arguments into a mapiter object */\n\t\tmit = (PyArrayMapIterObject *)PyArray_MapIterNew(op);\n\t\tif (mit == NULL) return NULL;\n\t\tif (!mit->view) { /* fancy indexing */\n\t\t\tPyArray_MapIterBind(mit, self);\n\t\t\tother = (PyArrayObject *)PyArray_GetMap(mit);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn (PyObject *)other;\n\t\t}\n\t\tPy_DECREF(mit);\n\t}\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\tif ((other = (PyArrayObject *)\t\t\t\t\t\\\n\t PyArray_New(self->ob_type, nd, dimensions, self->descr->type_num,\n\t\t\t strides, self->data+offset, \n\t\t\t self->itemsize, self->flags,\n\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 \narray_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op) \n{\n int ret;\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\n\tif (PyArrayMapIter_Check(index)) {\n\t\tmit = (PyArrayMapIterObject *)index;\n\t\t/* bind behavior to current array */\n\t\tPyArray_MapIterBind(mit, self);\n\t\t\t\n\t\t/* fall through if standard view-based map iterator */\n\t\tif (!mit->view) return PyArray_SetMap(mit, op);\n\t\tindex = mit->indexobj;\n\t}\n\telse {\n\t\tmit = (PyArrayMapIterObject *)PyArray_MapIterNew(index);\n\t\tif (mit == NULL) return -1;\n\t\tif (!mit->view) {\n\t\t\tPyArray_MapIterBind(mit, self);\n\t\t\tret = PyArray_SetMap(mit, op);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn ret;\n\t\t}\n\t\tPy_DECREF((PyObject*)mit);\n\t}\n\n\ti = PyArray_PyIntAsIntp(index);\n\tif (!error_converting(i)) {\n\t\treturn array_ass_big_item(self, i, op);\n\t}\n\tPyErr_Clear();\n\t\n\t/* Rest of standard (view-based) indexing */\n\n if ((tmp = (PyArrayObject *)array_subscript(self, index)) == NULL)\n return -1; \n ret = PyArray_CopyObject(tmp, op);\n Py_DECREF(tmp);\n\t\n return ret;\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 \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\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}\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}\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 PyObject *args, *ret;\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n args = Py_BuildValue(\"(OO)\", m1, m2);\n ret = PyObject_Call(op, args, NULL);\n Py_DECREF(args);\n return ret;\n}\n\nstatic PyObject *\nPyArray_GenericUnaryFunction(PyArrayObject *m1, PyObject *op) \n{\n PyObject *args, *ret;\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n args = Py_BuildValue(\"(O)\", m1);\n ret = PyObject_Call(op, args, NULL);\n Py_DECREF(args);\n return ret;\n}\n\nstatic PyObject *\nPyArray_GenericInplaceBinaryFunction(PyArrayObject *m1, \n\t\t\t\t PyObject *m2, PyObject *op) \n{\n PyObject *args, *ret;\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n args = Py_BuildValue(\"(OOO)\", m1, m2, m1);\n ret = PyObject_Call(op, args, NULL);\n Py_DECREF(args);\n return ret;\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_all_nonzero(PyArrayObject *mp) \n{\n\tintp index;\n\tPyArrayIterObject *it;\n\tBool anyTRUE = 0;\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->nonzero(it->dataptr, mp)) {\n\t\t\tanyTRUE = 1;\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 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->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->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->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->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->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_all_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 r = (PyArrayObject *)\\\n\t\tPyArray_New(self->ob_type, self->nd, self->dimensions, \n\t\t\t self->descr->type_num, self->strides, data,\n\t\t\t self->itemsize, 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 any(self == el) */\n\n return PyObject_RichCompareBool((PyObject *)self, el, Py_EQ);\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 *)realloc(*string, *max_n); }\n\t\n if (nd == 0) {\n\t\t\n if ((op = descr->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\tfree(string); return NULL; \n\t}\n\t\n\tif (PyArray_ISFLEXIBLE(self)) {\n\t\tchar buf[100];\n\t\tsnprintf(buf, sizeof(buf), \"%d\", self->itemsize);\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 free(string);\n return ret;\n}\n\nstatic PyObject *PyArray_StrFunction=NULL;\nstatic PyObject *PyArray_ReprFunction=NULL;\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\n\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) \n{\n PyObject *array_other, *result;\n\n switch (cmp_op) \n {\n case Py_LT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less);\n case Py_LE:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less_equal);\n case Py_EQ:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then return the integer\n\t\t\t object 0. This fixes code that used to\n\t\t\t allow equality comparisons between arrays\n\t\t\t and other objects which would give a result\n\t\t\t of 0\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n result = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.equal);\n /* If the comparison results in NULL, then the \n\t\t\t two array objects can not be compared together so \n\t\t\t return zero \n */\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n return result;\n case Py_NE:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then objects cannot be \n\t\t\t compared and cannot be equal, therefore, \n\t\t\t return True;\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n result = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.not_equal);\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n return result;\n case Py_GT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.greater);\n case Py_GE:\n return PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t other, \n\t\t\t\t\t \t n_ops.greater_equal);\n }\n return NULL;\n}\n\nstatic PyObject *\n_check_axis(PyArrayObject *arr, int *axis, int flags)\n{\n\tPyObject *temp;\n\tint n = arr->nd;\n\n\tif ((*axis >= MAX_DIMS) || (n==0)) {\n\t\ttemp = PyArray_Ravel(arr,0);\n\t\t*axis = 0;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_FromAny((PyObject *)arr, NULL, \n\t\t\t\t\t 0, 0, flags);\n\t\t\tif (temp == NULL) return NULL;\n\t\t}\n\t\telse {\n\t\t\tPy_INCREF(arr);\n\t\t\ttemp = (PyObject *)arr;\n\t\t}\n\t}\n\tif (*axis < 0) *axis += n;\n\tif ((*axis < 0) || (*axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", *axis);\n\t\tPy_DECREF(temp);\n\t\treturn NULL;\n\t}\n\treturn temp;\n}\n\n#include \"arraymethods.c\"\n\n/* Lifted from numarray */\nstatic PyObject *\nPyArray_IntTupleFromIntp(int len, intp *vals)\n{\n\tint i;\n PyObject *intTuple = PyTuple_New(len);\n if (!intTuple) goto fail;\n for(i=0; ind == 0) return 1;\n\tsd = ap->itemsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\n\t}\n\treturn 1;\n}\n\n\nstatic int \n_IsFortranContiguous(PyArrayObject *ap) \n{\n\tint sd;\n\tint i;\n\t\n\tif (ap->nd == 0) return 1;\n\tsd = ap->itemsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i=0; i< ap->nd; ++i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\n\t}\n\treturn 1;\n}\n\nstatic int\n_IsAligned(PyArrayObject *ap) \n{\n\tint i, alignment, aligned=1;\n\tintp ptr;\n\tint type = ap->descr->type_num;\n\n\tif ((type == PyArray_STRING) || (type == PyArray_VOID))\n\t\treturn 1;\n\n\talignment = ap->descr->alignment;\n\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\tPyBufferProcs *pb;\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\tpb = base->ob_type->tp_as_buffer;\n\tif (pb == NULL || pb->bf_getwritebuffer == NULL)\n\t\treturn FALSE;\n\t\n\treturn TRUE;\n}\n\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\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not \n walk outside of the memory implied by either numbytes or\n a single segment array of the provided dimensions and element size if\n numbytes is 0 */\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, \n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\t\n\tif (numbytes == 0) \n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\t\n\tfor (i=0; i numbytes) {\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\treturn TRUE;\n\t\n}\n\n\n/* This is the main array creation routine. */\n\n/* Flags argument has multiple related meanings \n depending on data and strides: \n\n If data is given, then flags is flags associated with data. \n If strides is not given, then a contiguous strides array will be created\n and the CONTIGUOUS bit will be set. If the flags argument \n has the FORTRAN bit set, then a FORTRAN-style strides array will be\n created (and of course the FORTRAN flag bit will be set). \n\n If data is not given but created here, then flags will be DEFAULT_FLAGS\n and a non-zero flags argument can be used to indicate a FORTRAN style\n array is desired. \n*/\n\nstatic intp\n_array_fill_strides(intp *strides, intp *dims, int nd, intp itemsize, \n\t\t int inflag, int *objflags) \n{\n\tint i;\n\t/* Only make Fortran strides if not contiguous as well */\n\tif ((inflag & FORTRAN) && !(inflag & CONTIGUOUS)) {\n\t\tfor (i=0; i 1) *objflags &= ~CONTIGUOUS;\n\t\telse *objflags |= CONTIGUOUS;\n\t}\n\telse {\n\t\tfor (i=nd-1;i>=0;i--) {\n\t\t\tstrides[i] = itemsize;\n\t\t\titemsize *= dims[i] ? dims[i] : 1;\n\t\t}\n\t\t*objflags |= CONTIGUOUS;\n\t\tif (nd > 1) *objflags &= ~FORTRAN;\n\t\telse *objflags |= FORTRAN;\n\t}\n\treturn itemsize;\n}\n\n\t\nstatic PyObject *\nPyArray_New(PyTypeObject *subtype, int nd, intp *dims, int type_num,\n intp *strides, char *data, int itemsize, int flags,\n\t PyObject *obj)\n{\n\tPyArrayObject *self;\n\tPyArray_Descr *descr;\n\tregister int i;\n\tintp sd, temp=-1;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\tif (descr == NULL) return NULL;\n\n\tif (nd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"number of dimensions must be >=0\");\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 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\treturn NULL;\n\t\t}\n\t}\n\t\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) return NULL;\t\n\tself->descr = descr;\n\tself->dimensions = 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\n\tif (PyTypeNum_ISFLEXIBLE(type_num)) {\n\t\tif (itemsize < 1) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"type must provide an itemsize\");\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn NULL;\n\t\t}\n\t\tself->itemsize = itemsize;\n\t\t/* Guarantee that these kind of arrays are never byteswapped\n\t\t unknowingly. \n\t\t*/\n\t\tif (type_num != PyArray_UNICODE)\n\t\t\tself->flags |= NOTSWAPPED;\n\t}\n\telse self->itemsize = descr->elsize; \n\t\t\n\tsd = self->itemsize;\n\t\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn PyErr_NoMemory();\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\tPyDimMem_FREE(self->dimensions);\n\t\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\t\treturn NULL;\n\t\t\t}\t\t\t\t\n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t}\n \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 (a.data) doesn't work\n\t\t as it should. */\n\n\t\tif (sd==0) sd = sizeof(intp);\n\n\t\tif ((data = PyDataMem_NEW(sd))==NULL) {\n\t\t\tPyDimMem_FREE(self->dimensions);\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn PyErr_NoMemory();\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\n\t\t/* It is bad to have unitialized OBJECT pointers */\n\t\t/* We shouldn't need to check for the OBJECT Letter\n\t\t but perhaps it's best. */\n\t\tif (type_num == PyArray_OBJECT || \\\n\t\t type_num == PyArray_OBJECTLTR) {\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\tself->nd = nd;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\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;\n\t\tif (temp==-1) { /* 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\tres = PyObject_CallMethod((PyObject *)self, \n\t\t\t\t\t \"__array_finalize__\",\n\t\t\t\t\t \"O\", obj);\n\t\tif (res == NULL) {\n\t\t\tPyDimMem_FREE(self->dimensions);\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn NULL;\n\t\t}\n\t\telse Py_DECREF(res);\n\t}\n\n\treturn (PyObject *)self;\n}\n\n\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\n newsize = PyArray_MultiplyList(new_dimensions, new_nd);\n\n if (newsize == 0) {\n PyErr_SetString(PyExc_ValueError, \n \"newsize is zero; cannot delete an array \"\\\n \"in this way\");\n return NULL;\n }\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 = (((PyObject *)self)->ob_refcnt);\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\n\t\t/* Reallocate space if needed */\n\t\tnew_data = PyDataMem_RENEW(self->data, \n\t\t\t\t\t newsize*(self->itemsize));\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->itemsize;\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->itemsize;\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 */\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; idataptr, fromptr, itemsize);\n\t\t\tPyArray_ITER_NEXT(iter);\n\t\t}\n\n\t\tPy_DECREF(iter);\n\t\tPy_DECREF(behaved);\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\", \"strides\", \n \"swap\", \"fortran\", NULL};\n\tint itemsize = 0;\n\tPyArray_Typecode typecode = {PyArray_NOTYPE, 0, 0};\n\tint type_num = PyArray_NOTYPE;\n PyArray_Dims dims = {NULL, 0};\n PyArray_Dims strides = {NULL, 0};\n PyArray_Chunk buffer;\n\tint fortran = 0;\n int swapped = 0;\n\tPyArrayObject *ret;\n\n\tbuffer.ptr = NULL; \n /* Usually called with shape and type\n but can also be called with buffer, strides, and swapped info\n */\n\n\t/* For now, let's just use this to create an empty, contiguous \n\t array of a specific type and shape. \n\t*/\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&O&ii\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &dims, \n PyArray_TypecodeConverter,\n\t\t\t\t\t &typecode, \n PyArray_BufferConverter,\n &buffer,\n &PyArray_IntpConverter, \n &strides,\n &swapped, &fortran)) \n\t\treturn NULL;\n\t\n if (typecode.type_num ==PyArray_NOTYPE) {\n\t\ttypecode.type_num = PyArray_DOUBLE;\n\t\ttypecode.itemsize = sizeof(double);\n\t}\n\ttype_num = typecode.type_num;\n\titemsize = typecode.itemsize;\n\n\n if (dims.ptr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"need to give a \"\\\n \"valid shape as the first argument\");\n goto fail;\n }\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)PyArray_New(subtype, (int)dims.len, \n dims.ptr, type_num,\n NULL, NULL, itemsize, \n fortran, NULL);\n \n if (ret == NULL) goto fail;\n if (type_num == PyArray_OBJECT) { /* place Py_None */\n PyArray_FillObjectArray(ret, Py_None);\n }\n }\n else { /* buffer given -- use it */\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = buffer.len / itemsize;\n }\n else if (buffer.len < itemsize* \\\n PyArray_MultiplyList(dims.ptr, dims.len)) {\n PyErr_SetString(PyExc_TypeError, \n \"buffer is too small for \" \\\n \"requested array\");\n goto fail;\n }\n if (strides.ptr != NULL) {\n\t\t\tif (strides.len != dims.len) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides, if given, must be \"\\\n\t\t\t\t\t\t\"the same length as shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CheckStrides(itemsize, strides.len, \n\t\t\t\t\t\t buffer.len,\n\t\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides is incompatible \"\\\n\t\t\t\t\t\t\"with shape of requested\"\\\n\t\t\t\t\t\t\"array and size of buffer\");\n\t\t\t\tgoto fail;\n\t\t\t}\n }\n if (type_num == PyArray_OBJECT) {\n PyErr_SetString(PyExc_TypeError, \"cannot construct \"\\\n \"an object array from buffer data\");\n goto fail;\n }\n /* get writeable and aligned */\n if (fortran) buffer.flags |= FORTRAN;\n if (!(swapped)) buffer.flags |= NOTSWAPPED;\n ret = (PyArrayObject *)PyArray_New(subtype, dims.len, \n dims.ptr, type_num,\n strides.ptr,\n (char *)buffer.ptr, \n itemsize, \n buffer.flags, NULL); \n if (ret == 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 PyArray_Return(ret);\n \n fail:\n if (dims.ptr) PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return NULL;\n}\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 static PyObject *module=NULL;\n\n if (module==NULL) {\n module = PyImport_ImportModule(\"scipy.base._internal\");\n if (module == NULL) return NULL;\n }\n return PyObject_CallMethod(module, \"flagsobj\", \"Oii\", \n self, self->flags, 0);\n}\n\n/*\nstatic int\narray_flags_set(PyArrayObject *self, PyObject *obj) \n{\n\tint flagback = self->flags;\n\n if (PyDict_Check(obj)) {\n PyObject *new;\n\t\tnew = PyDict_GetItemString(obj, \"ALIGNED\");\n\t\tif (new) {\n\t\t\tif (PyObject_Not(new)) self->flags &= ~ALIGNED;\n\t\t\telse if (_IsAligned(self)) self->flags |= ALIGNED;\n\t\t\telse {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"cannot set aligned flag of \" \\\n\t\t\t\t\t\t\"mis-aligned array to True\");\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t}\n new = PyDict_GetItemString(obj, \"UPDATEIFCOPY\");\n if (new) {\n if (PyObject_Not(new)) {\n self->flags &= ~UPDATEIFCOPY;\n Py_DECREF(self->base);\n self->base = NULL;\n }\n else {\n\t\t\t\tself->flags = flagback;\n PyErr_SetString(PyExc_ValueError, \n \"cannot set UPDATEIFCOPY \" \\\n \"flag to True\");\n return -1;\n }\n }\n new = PyDict_GetItemString(obj, \"WRITEABLE\");\n if (new) {\n\t\t\tif (PyObject_IsTrue(new)) {\n\t\t\t\tif (_IsWriteable(self)) {\n\t\t\t\t\tself->flags |= WRITEABLE;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tself->flags = flagback;\n\t\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\t\"cannot set \"\t\\\n\t\t\t\t\t\t\t\"WRITEABLE \"\t\\\n\t\t\t\t\t\t\t\"flag to True of \"\\\n\t\t\t\t\t\t\t\"this array \");\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n else\n self->flags &= ~WRITEABLE;\n }\n new = PyDict_GetItemString(obj, \"NOTSWAPPED\");\n if (new) {\n if (PyObject_IsTrue(new))\n self->flags |= NOTSWAPPED;\n else {\n self->flags &= ~NOTSWAPPED;\n\t\t\t}\n\t\t}\n return 0;\n }\n PyErr_SetString(PyExc_ValueError, \n \"object must be a dictionary\");\n return -1;\n}\n*/\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\tif (!PyTuple_Check(val)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"shape must be a tuple\");\n\t\treturn -1;\n\t}\n\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\n\t\n\tif (self->nd > 0) { /* Free old dimensions and strides */\n\t\tPyDimMem_FREE(self->dimensions);\n\t}\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;\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\treturn -1;\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->itemsize;\n\t\n\tif (!PyArray_CheckStrides(self->itemsize, self->nd, numbytes, \n\t\t\t\t self->dimensions, newstrides.ptr)) {\n\t\tPyErr_SetString(PyExc_ValueError, \"strides is not \"\\\n\t\t\t\t\"compatible with available memory\");\n\t\treturn -1;\n\t}\n\tmemcpy(self->strides, newstrides.ptr, sizeof(intp)*newstrides.len);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\treturn 0;\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->itemsize);\n}\n\nstatic PyObject *\narray_size_get(PyArrayObject *self)\n{\n\tlonglong size=PyArray_SIZE(self);\n\tif (size > MAX_INT || size < MIN_INT)\n\t\treturn PyLong_FromLongLong(size);\n\telse \n\t\treturn PyInt_FromLong((long) size);\n}\n\n\nstatic PyObject *\narray_typechar_get(PyArrayObject *self)\n{\n\tif PyArray_ISFLEXIBLE(self) \n\t\treturn PyString_FromFormat(\"%c%d\", (self->descr->type),\n\t\t\t\t\t self->itemsize);\n\telse \n\t\treturn PyString_FromStringAndSize(&(self->descr->type), 1);\n}\n\nstatic PyObject *\narray_typestr_get(PyArrayObject *self)\n{\n\tstatic char endians[] = \"<>\";\n\tchar endian;\n\tint which;\n\tunsigned long val = 1;\n\tchar *s;\n\tchar basic_=self->descr->kind;\n\n\ts = (char *)&val; /* s[0] == 0 implies big-endian */\n\twhich = (PyArray_ISNOTSWAPPED(self) ? 0 : 1);\n\tif (s[0] == 0) which = 1 - which;\n\tendian = endians[which]; \n\t\n\tif ((basic_==PyArray_VOIDLTR) || (basic_==PyArray_STRINGLTR) || \\\n\t (basic_==PyArray_OBJECTLTR) || (self->itemsize == 1))\n\t\treturn PyString_FromFormat(\"|%c%d\", basic_, self->itemsize);\n\telse\n\t\treturn PyString_FromFormat(\"%c%c%d\", endian, basic_,\n\t\t\t\t\t self->itemsize);\n}\n\nstatic PyObject *\narray_descr_get(PyArrayObject *self)\n{\n\tPyObject *res;\n\tPyObject *dobj;\n\n\t/* hand this off to the typeobject */\n\t/* or give default */\n\tif (PyArray_ISUSERDEF(self)) {\n\t\tres = PyObject_GetAttrString((PyObject *)self->descr->typeobj, \n\t\t\t\t\t \"__array_descr__\");\n\t\tif (res) return res;\n\t\tPyErr_Clear();\n\t}\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\n\nstatic PyObject *\narray_type_get(PyArrayObject *self)\n{\n\treturn PyArray_TypeObjectFromType(self->descr->type_num);\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*/\n\nstatic int\narray_type_set(PyArrayObject *self, PyObject *arg)\n{\n PyArray_Typecode newtype = {PyArray_NOTYPE, 0, 0};\n intp newdim;\n int index;\n char *msg = \"new type not compatible with array.\";\n\n if ((PyArray_TypecodeConverter(arg, &newtype) < 0) ||\n newtype.type_num == PyArray_NOTYPE) {\n PyErr_SetString(PyExc_TypeError, \"invalid type for array\");\n return -1;\n }\n if (!(PyArray_ISONESEGMENT(self) ||\t\t\\\n\t (newtype.itemsize != self->itemsize))) {\n PyErr_SetString(PyExc_ValueError, msg);\n return -1; \n }\n\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\n if (newtype.itemsize < self->itemsize) {\n /* if it is compatible increase the size of the dimension\n at end (or at the front for FORTRAN)\n */\n if (self->itemsize % newtype.itemsize != 0) {\n PyErr_SetString(PyExc_ValueError, msg);\n return -1;\n }\n newdim = self->itemsize / newtype.itemsize;\n\t\tself->dimensions[index] *= newdim;\n self->strides[index] = newtype.itemsize;\n\t}\n \n else if (newtype.itemsize > self->itemsize) {\n \n /* Determine if last (or first if FORTRAN) dimension\n is compatible */\n\n\t\tnewdim = self->dimensions[index] * self->itemsize;\n if ((newdim % newtype.itemsize) != 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, msg);\n return -1;\n }\n\t\t\n self->dimensions[index] = newdim / newtype.itemsize;\n self->strides[index] = newtype.itemsize;\n\t\t\n }\n\t\n \n /* fall through -- adjust type*/\n\n self->descr = PyArray_DescrFromType(newtype.type_num);\n self->itemsize = newtype.itemsize;\n PyArray_UpdateFlags(self, ALIGNED);\n return 0;\n\n}\n\n\n\nstatic PyObject *\narray_base_get(PyArrayObject *self)\n{\n\tif (self->base == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\telse {\n\t\tPy_INCREF(self->base);\n\t\treturn self->base;\n\t}\n}\n\n\nstatic PyObject *\narray_real_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *)ret;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n}\n\n\nstatic int\narray_real_set(PyArrayObject *self, PyObject *val)\n{\n\tPyArrayObject *ret;\n\tPyArrayObject *new;\n\tint rint;\n\n\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0);\n\tif (new == NULL) return -1;\n\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) 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\treturn rint;\n}\n\nstatic PyObject *\narray_imag_get(PyArrayObject *self)\n{\t\n\tPyArrayObject *ret;\n\tint itemsize;\n\tint typenum;\n PyArray_Typecode type;\n\t\n\ttype.type_num = self->descr->type_num;\n\ttype.itemsize = self->itemsize;\n\ttype.fortran = PyArray_ISFORTRAN(self);\n\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\titemsize = self->itemsize >> 1;\n\t\ttypenum = self->descr->type_num - PyArray_NUM_FLOATTYPE;\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 typenum,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data + itemsize,\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\tret = (PyArrayObject *)PyArray_Zeros(self->nd, \n\t\t\t\t\t\t self->dimensions, &type);\n\t\tret->flags &= ~WRITEABLE;\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic int\narray_imag_set(PyArrayObject *self, PyObject *val)\n{\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyArrayObject *ret;\n\t\tPyArrayObject *new;\n\t\tint rint;\n\n\t\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0); \n\t\tif (new == NULL) return -1;\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides+ \\\n\t\t\t\t\t\t (self->itemsize >> 1) ,\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) {\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_Typecode typecode;\n int swap;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode.type_num = self->descr->type_num;\n\ttypecode.itemsize = self->itemsize;\n\ttypecode.fortran = PyArray_ISFORTRAN(self);\n\t\n\tarr = PyArray_FromAny(val, &typecode, \n\t\t\t 0, 0, FORCECAST);\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->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 copyswap(selfit->dataptr, NULL, swap, \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->itemsize);\n copyswap(selfit->dataptr, NULL, swap, self->itemsize);\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\t{\"base\",\n\t (getter)array_base_get,\n\t NULL,\n\t \"base object\"},\n {\"dtype\", \n\t (getter)array_type_get, \n\t (setter)array_type_set,\n\t \"get array type class\"},\n\t{\"dtypechar\",\n\t (getter)array_typechar_get,\n\t NULL,\n\t \"get array type character code\"},\n\t{\"dtypestr\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"get array type string\"},\n {\"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_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\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\n\nstatic char Arraytype__doc__[] = \n \"A array object represents a multidimensional, homogeneous array\\n\"\n\t\" of basic values. Arrays are sequence, mapping and numeric\\n\"\n\t\" objects. More information is available in the scipy module and\\n\"\n\t\" by looking at the methods and attributes of an array.\";\n\nstatic PyTypeObject PyBigArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"scipy.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 \n offsetof(PyArrayObject, weakreflist), /*tp_weaklistoffset */\n\n /* Iterator support (use standard) */\n\n (getiterfunc)0, \t\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 0,\t /* tp_alloc */ \n (newfunc)array_new,\t\t /* tp_new */\n 0,\t \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 \"scipy.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) \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 if (PySequence_Length(s) == 0) \n\t\treturn 1;\n\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);\n\t\tif(d >= 0) d++;\n\t}\n Py_DECREF(e);\n return d;\n}\n\nstatic int\ndiscover_itemsize(PyObject *s, int nd, int *itemsize) \n{\n\tint n, r, i;\n\tPyObject *e;\n\t\n\tn = PyObject_Length(s);\n\n\tif ((nd == 0) || PyString_Check(s) ||\t\t\\\n\t PyUnicode_Check(s) || PyBuffer_Check(s)) {\n\t\tif PyUnicode_Check(s) \n\t\t\t*itemsize = MAX(*itemsize, sizeof(Py_UNICODE)*n);\n\t\telse\n\t\t\t*itemsize = MAX(*itemsize, n);\n\t\treturn 0;\n\t}\n\tfor (i=0; i n_lower) n_lower = d[1];\n }\n d[1] = n_lower;\n\t\n return 0;\n}\n\nstatic void\n_array_small_type(int chktype, int mintype, int chksize, int minsize, \n\t\t PyArray_Typecode *outtype)\n{\n\touttype->type_num = MAX(chktype, mintype);\n\tif (PyTypeNum_ISFLEXIBLE(outtype->type_num) &&\t\\\n\t PyTypeNum_ISFLEXIBLE(mintype)) {\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 == PyArray_STRING) {\n\t\t\touttype->itemsize = MAX(chksize, 2*minsize);\n\t\t}\n\t\telse {\n\t\t\touttype->itemsize = MAX(chksize, minsize);\n\t\t}\n\t}\n\telse {\n\t\touttype->itemsize = chksize;\n\t}\n\treturn;\t\n}\n\nstatic void\n_array_find_type(PyObject *op, PyArray_Typecode *minitype, \n\t\t PyArray_Typecode *outtype, int max)\n{\n int l;\n PyObject *ip;\n\tint chktype=0;\n\tint chksize=0;\n\tint mintype, minsize;\n\n\tif (minitype == NULL) {\n\t\tmintype = PyArray_BOOL;\n\t\tminsize = sizeof(Bool);\n\t}\n\telse {\n\t\tmintype = minitype->type_num;\n\t\tminsize = minitype->itemsize;\n\t}\n\n \n if (max < 0 || mintype == -1) goto deflt;\n\t\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_TYPE(op);\n\t\tchksize = PyArray_ITEMSIZE(op);\n\t\tgoto finish;\n\t}\n\t\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tPyArray_TypecodeFromScalar(op, outtype);\n\t\tchktype = outtype->type_num;\n\t\tchksize = outtype->itemsize;\n\t\tgoto finish;\n\t}\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_TYPE(ip);\n\t\t\tchksize = PyArray_ITEMSIZE(ip);\n\t\t\tgoto finish;\n\t\t}\n } \n\t\n\tif (PyObject_HasAttrString(op, \"__array_typestr__\")) {\n\t\tint swap=0, res;\n\t\tip = PyObject_GetAttrString(op, \"__array_typestr__\");\n\t\tif (ip && PyString_Check(ip)) {\n\t\t\tres = _array_typecode_fromstr(PyString_AS_STRING(ip), \n\t\t\t\t\t\t &swap, outtype); \n\t\t\tif (res >= 0) {\n\t\t\t\tPy_DECREF(ip);\n\t\t\t\tchktype = outtype->type_num;\n\t\t\t\tchksize = outtype->itemsize;\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t}\n\t\tPy_XDECREF(ip);\n\t}\n\n if (PyString_Check(op)) {\n\t\tchktype = PyArray_STRING;\n\t\tchksize = PyString_GET_SIZE(op);\n\t\tgoto finish;\n }\n\n\tif (PyUnicode_Check(op)) {\n\t\tchktype = PyArray_UNICODE;\n\t\tchksize = PyUnicode_GET_DATA_SIZE(op);\n\t\tgoto finish;\n\t}\n\n\tif (PyBuffer_Check(op)) {\n\t\tchktype = PyArray_VOID;\n\t\tchksize = op->ob_type->tp_as_sequence->sq_length(op);\n\t\tPyErr_Clear();\n\t\tgoto finish;\n\t}\n\n\tif (PyInstance_Check(op)) goto deflt;\n\t\n if (PySequence_Check(op)) {\n\t\tPyArray_Typecode newtype;\n\t\tnewtype.type_num = mintype;\n\t\tnewtype.itemsize = minsize;\n\t\tnewtype.fortran = 0;\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 && mintype == 0) {\n\t\t\tnewtype.type_num = PyArray_INTP;\n\t\t\tnewtype.itemsize = sizeof(intp);\n\t\t}\n while (--l >= 0) {\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\t_array_find_type(ip, &newtype, outtype, max-1);\n\t\t\t_array_small_type(outtype->type_num,\n\t\t\t\t\t newtype.type_num, \n\t\t\t\t\t outtype->itemsize,\n\t\t\t\t\t newtype.itemsize,\n\t\t\t\t\t &newtype);\n Py_DECREF(ip);\n }\n\t\tchktype = newtype.type_num;\n\t\tchksize = newtype.itemsize;\n\t\tgoto finish;\n }\n\t\n\tif (PyBool_Check(op)) {\n\t\tchktype = PyArray_BOOL;\n\t\tchksize = sizeof(Bool);\n\t\tgoto finish;\t\t\n\t}\n else if (PyInt_Check(op)) {\n\t\tchktype = PyArray_LONG;\n\t\tchksize = sizeof(long);\n\t\tgoto finish;\n } else if (PyFloat_Check(op)) {\n\t\tchktype = PyArray_DOUBLE;\n\t\tchksize = sizeof(double);\n\t\tgoto finish;\n\t} else if (PyComplex_Check(op)) {\n\t\tchktype = PyArray_CDOUBLE;\n\t\tchksize = sizeof(cdouble);\n\t\tgoto finish;\n\t}\n\n deflt:\n\tchktype = PyArray_OBJECT;\n\tchksize = sizeof(void *);\n\n finish:\n\t_array_small_type(chktype, mintype, chksize, minsize, \n\t\t\t outtype);\n\treturn;\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\" */ \nstatic PyObject *\nArray_FromScalar(PyObject *op, PyArray_Typecode *typecode) \n{\n PyArrayObject *ret;\n\tint itemsize; \n\tint type;\n\t\n\titemsize = typecode->itemsize;\n\ttype = typecode->type_num;\n\n\tif (itemsize == 0 && PyTypeNum_ISFLEXIBLE(type)) {\n\t\titemsize = PyObject_Length(op);\n\t}\n\n\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, 0, NULL, type,\n\t\t\t\t\t NULL, NULL, itemsize, 0, NULL);\n\n\tif (ret == NULL) return NULL;\n\n ret->descr->setitem(op, ret->data, ret);\n\t\n if (PyErr_Occurred()) {\n array_dealloc(ret);\n return NULL;\n } else {\n return (PyObject *)ret;\n }\n}\n\n\nstatic PyObject *\nArray_FromSequence(PyObject *s, PyArray_Typecode *typecode, int min_depth, \n\t\t int max_depth)\n{\n PyArrayObject *r;\n int nd;\n\tintp *d;\n\tint stop_at_string;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->itemsize;\n\t\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 if (!((nd=discover_depth(s, MAX_DIMS+1, stop_at_string)) > 0)) {\n\t\tif (nd==0)\n\t\t\treturn Array_FromScalar(s, typecode);\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid input sequence\");\n return NULL;\n }\n\t\n if ((max_depth && nd > max_depth) ||\t\\\n\t (min_depth && nd < min_depth)) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid number of dimensions\");\n return NULL;\n }\n\t\n\tif ((d=PyDimMem_NEW(nd)) == NULL) {\n\t\treturn PyErr_NoMemory();\n }\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) {\n\t\tPyDimMem_FREE(d);\n\t\treturn NULL;\n\t}\n\tif (itemsize == 0 && PyTypeNum_ISFLEXIBLE(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) {\n\t\t\tPyDimMem_FREE(d);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n r=(PyArrayObject*)PyArray_New(&PyArray_Type, nd, d, \n\t\t\t\t type, NULL, NULL,\n\t\t\t\t itemsize, \n\t\t\t\t typecode->fortran, NULL);\n\n PyDimMem_FREE(d);\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\n\nstatic int \nPyArray_ValidType(int type) \n{\n\tPyArray_Descr *descr;\n\t\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr==NULL) return 0;\n\treturn 1;\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->itemsize;\n\tint nels = PyArray_BUFSIZE;\n\tint el;\n\tint inswap, outswap=0;\n\tint obuf=!PyArray_ISCARRAY(out);\n\tint oelsize = out->itemsize;\n\tPyArray_VectorUnaryFunc *castfunc;\n PyArray_CopySwapFunc *in_csn;\n PyArray_CopySwapFunc *out_csn;\n\tint retval = -1;\n\n\tcastfunc = in->descr->cast[out->descr->type_num];\n in_csn = in->descr->copyswap;\n out_csn = out->descr->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\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\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->itemsize * 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\n/* For backward compatibility */\n\nstatic PyObject *\nPyArray_Cast(PyArrayObject *mp, int type_num) \n{\n\tPyArray_Typecode type;\n\tPyArray_Descr *descr;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\ttype.itemsize = descr->elsize;\n\ttype.type_num = descr->type_num;\n\ttype.fortran = 0;\n\t\n\treturn PyArray_CastToType(mp, &type);\n}\n\nstatic PyObject * \nPyArray_CastToType(PyArrayObject *mp, PyArray_Typecode *at) \n{\n\tPyObject *out;\n\tint ret;\n\n\tif ((mp->descr->type_num == at->type_num) && \\\n\t (at->itemsize==0 || mp->itemsize == at->itemsize) &&\n\t PyArray_ISBEHAVED_RO(mp)) {\n\t\tPy_INCREF(mp);\n\t\treturn (PyObject *)mp;\n\t}\n\t\t\n\tif (at->itemsize == 0) {\n\t\tif (mp->descr->type_num == PyArray_STRING &&\t\\\n\t\t at->type_num == PyArray_UNICODE)\n\t\t\tat->itemsize = mp->itemsize*sizeof(Py_UNICODE);\n\t\tif (mp->descr->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING) \n\t\t\tat->itemsize = mp->itemsize/sizeof(Py_UNICODE);\n\t\tif (at->type_num == PyArray_VOID)\n\t\t\tat->itemsize = mp->itemsize;\n\t}\n\n\tout = PyArray_New(mp->ob_type, mp->nd, \n\t\t\t mp->dimensions, \n\t\t\t at->type_num,\n\t\t\t NULL, NULL, at->itemsize, \n\t\t\t at->fortran, (PyObject *)mp);\n\tif (out == NULL) return NULL;\n\tret = PyArray_CastTo((PyArrayObject *)out, mp);\n\tif (ret != -1) return out;\n\n\tPy_DECREF(out);\n\treturn NULL;\n\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\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\tsimple = ((PyArray_ISCARRAY(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY(mp) && PyArray_ISFARRAY(out)));\n\t\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->itemsize * outsize;\n\t\tintp ncopies = outsize / mpsize;\n\n\t\twhile(ncopies--) {\n\t\t\tinptr = mp->data;\n\t\t\tmp->descr->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\nstatic PyObject *\narray_fromarray(PyArrayObject *arr, PyArray_Typecode *typecode, int flags) \n{\n\t\n\tPyArrayObject *ret=NULL;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->itemsize;\n\tint copy = 0;\n\tint arrflags;\n\tPyArray_Typecode oldtype;\n\tchar *msg = \"cannot copy back to a read-only array\";\n PyTypeObject *subtype;\n\n\toldtype.type_num = PyArray_TYPE(arr);\n\toldtype.itemsize = PyArray_ITEMSIZE(arr);\n\toldtype.fortran = 0;\n\n subtype = arr->ob_type;\n\n\tif (type == PyArray_NOTYPE) type = arr->descr->type_num;\n\tif (itemsize == 0) itemsize = arr->itemsize;\n\ttypecode->type_num = type;\n\ttypecode->itemsize = itemsize;\n\n\t/* Don't copy if sizes are compatible */\n\tif (PyArray_EquivalentTypes(&oldtype, typecode)) {\n\t\tarrflags = arr->flags;\n\n\t\tcopy = (flags & ENSURECOPY) || \\\n\t\t\t((flags & CONTIGUOUS) && (!(arrflags & CONTIGUOUS))) \\\n\t\t\t|| (PyArray_ITEMSIZE(arr) != itemsize) || \\\n\t\t\t((flags & ALIGNED) && (!(arrflags & ALIGNED))) || \\\n\t\t\t((flags & NOTSWAPPED) && (!(arrflags & NOTSWAPPED))) \\\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 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_New(subtype, \n\t\t\t\t\t arr->nd, \n\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t type,\n\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t itemsize,\n\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t (PyObject *)arr);\n\t\t\tif (PyArray_CopyInto(ret, arr) == -1) 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 ret = (PyArrayObject *) \\\n PyArray_New(&PyArray_Type,\n arr->nd,\n arr->dimensions,\n arr->descr->type_num,\n arr->strides,\n arr->data,\n arr->itemsize,\n arr->flags,NULL);\n if (ret == NULL) return NULL;\n ret->base = (PyObject *)arr;\n ret->flags &= ~UPDATEIFCOPY;\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_CanCastSafely(PyArray_TYPE(arr), type)) {\n if ((flags & UPDATEIFCOPY) && \\\n (!PyArray_ISWRITEABLE(arr))) {\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_New(subtype, arr->nd,\n arr->dimensions, typecode->type_num,\n NULL, NULL, typecode->itemsize,\n typecode->fortran, \n (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\nstatic int\n_array_typecode_fromstr(char *str, int *swap, PyArray_Typecode *type)\n{\n int type_num;\n char typechar;\n int size;\n unsigned long number = 1;\n char *s;\n char msg[] = \"unsupported typestring\";\n \n s = (char *)&number; /* s[0] == 0 implies big-endian */\n\n *swap = 0;\n\n if (str[0] == '<' || str[0] == '>') {\n\tif ((str[0] == '<') && (s[0] == 0)) *swap = 1;\n\telse if ((str[0] == '>') && (s[0] != 0)) *swap = 1;\n }\n str += 1;\n \n#define _MY_FAIL {\t\t\t\t \\\n\t PyErr_SetString(PyExc_ValueError, msg); \\\n\t return -1;\t\t\t \\\n }\t\t\n\n typechar = str[0];\n size = atoi(str + 1);\n switch (typechar) {\n case 'b':\n\t if (size == sizeof(Bool))\n\t\t type_num = PyArray_BOOL;\t \n\t else _MY_FAIL \n\t break;\t\t \n case 'u':\n if (size == sizeof(uintp))\n type_num = PyArray_UINTP;\n\t else if (size == sizeof(char))\n\t\t type_num = PyArray_UBYTE;\n\t else if (size == sizeof(short)) \n\t\t type_num = PyArray_USHORT;\n\t else if (size == sizeof(int)) \n\t\t type_num = PyArray_UINT;\n\t else if (size == sizeof(ulong)) \n\t\t type_num = PyArray_ULONG;\n\t else if (size == sizeof(ulonglong))\n\t\t type_num = PyArray_ULONGLONG;\n\t else _MY_FAIL\n\t break;\t\t \n case 'i':\n if (size == sizeof(intp))\n type_num = PyArray_INTP;\n\t else if (size == sizeof(char)) \n\t\t type_num = PyArray_BYTE;\n\t else if (size == sizeof(short)) \n\t\t type_num = PyArray_SHORT;\n\t else if (size == sizeof(int))\n\t\t type_num = PyArray_INT;\n\t else if (size == sizeof(long)) \n\t\t type_num = PyArray_LONG;\n\t else if (size == sizeof(longlong))\n\t\t type_num = PyArray_LONGLONG;\n\t else _MY_FAIL\n\t break;\t\t \n case 'f':\n\t if (size == sizeof(float))\n\t\t type_num = PyArray_FLOAT;\n\t else if (size == sizeof(double))\n\t\t type_num = PyArray_DOUBLE;\n\t else if (size == sizeof(longdouble))\n\t\t type_num = PyArray_LONGDOUBLE;\n\t else _MY_FAIL\n\t break;\n case 'c':\n\t if (size == sizeof(float)*2)\n\t\t type_num = PyArray_CFLOAT;\n\t else if (size == sizeof(double)*2)\n\t\t type_num = PyArray_CDOUBLE;\n\t else if (size == sizeof(longdouble)*2)\n\t\t type_num = PyArray_CLONGDOUBLE;\n\t else _MY_FAIL\n\t break;\n case 'O':\n\t if (size == sizeof(PyObject *))\n\t\t type_num = PyArray_OBJECT;\n\t else _MY_FAIL\n\t break;\n case 'S':\n\t type_num = PyArray_STRING;\n\t break;\n case 'U':\n\t type_num = PyArray_UNICODE;\n\t size *= sizeof(Py_UNICODE);\n\t break;\t \n case 'V':\n\t type_num = PyArray_VOID;\n\t break;\n default:\n\t _MY_FAIL\n }\n\n#undef _MY_FAIL\n\n type->type_num = type_num;\n type->itemsize = size;\n type->fortran = 0;\n return 0;\n}\n\nstatic PyObject *\narray_frominterface(PyObject *input, PyArray_Typecode *intype, int flags)\n{\n\tPyObject *attr=NULL, *item=NULL, *r;\n\tPyArrayObject *ret=NULL;\n\tPyArray_Typecode type;\n\tchar *data;\n\tint buffer_len;\n\tint res, i, n;\n\tintp dims[MAX_DIMS], strides[MAX_DIMS];\n\tint swap;\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\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) {Py_XDECREF(attr); return NULL;}\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t}\n\telse {\n\t\tif (PyTuple_GET_SIZE(attr) != 2) {\n\t\t\tPy_DECREF(attr);\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\treturn NULL;\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\tPy_DECREF(attr);\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\treturn NULL;\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 = PyObject_GetAttrString(input, \"__array_typestr__\");\n\tif (!PyString_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_typestr__ must be a string\");\n\t\tPy_DECREF(attr);\n\t\treturn NULL;\t\n\t}\n\tres = _array_typecode_fromstr(PyString_AS_STRING(attr), &swap, &type);\n\tPy_DECREF(attr);\n\tif (res < 0) return NULL;\n \n\tattr = PyObject_GetAttrString(input, \"__array_shape__\");\n\tif (!PyTuple_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_shape__ must be a tuple\");\n\t\tPy_DECREF(attr);\n\t\treturn NULL;\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\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\treturn NULL;\n\t\t}\n\t\tfor (i=0; istrides, strides, n*sizeof(intp));\n\t}\n\n\tif (swap) {\n\t\tPyObject *tmp;\n tmp = PyArray_Byteswap(ret, TRUE);\n\t\tPy_DECREF(tmp);\n\t}\n\n\tPyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n\tr = array_fromarray(ret, intype, flags);\n\tPy_DECREF(ret);\n\treturn r;\n}\n\nstatic PyObject *\narray_fromattr(PyObject *op, PyArray_Typecode *typecode, int flags) \n{\n PyObject *new, *r;\n\t \n if (typecode->type_num == PyArray_NOTYPE) {\n new = PyObject_CallMethod(op, \"__array__\", NULL);\n } else {\n\t\tPyArray_Descr *descr;\n\t\tPyObject *obj;\n\n\t\tdescr = PyArray_DescrFromType(typecode->type_num);\n\t\tif (PyTypeNum_ISFLEXIBLE(typecode->type_num)) {\n\t\t\tobj = PyString_FromFormat(\"%c%d\", descr->type,\n\t\t\t\t\t\t typecode->itemsize);\n\t\t}\n\t\telse { \n\t\t\tobj = (PyObject *)(descr->typeobj); Py_INCREF(obj);\n\t\t}\n\t\tnew = PyObject_CallMethod(op, \"__array__\", \"N\", obj);\n }\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 r = array_fromarray((PyArrayObject *)new, typecode, flags);\n Py_DECREF(new);\n return r;\n} \n\n\nstatic PyObject *\narray_fromobject(PyObject *op, PyArray_Typecode *typecode, int min_depth, \n\t\t int max_depth, int flags) \n{\n /* This is the main code to make a NumPy array from a Python\n Object. It is called from lot's of different places which\n is why there are so many checks. The comments try to\n explain some of the checks. */\n\n\tint type = typecode->type_num;\n PyObject *r=NULL;\n\n\t/* Is input object already an array? */\n\t/* This is where the flags are used */\n if (PyArray_Check(op)) \n\t\tr = array_fromarray((PyArrayObject *)op, typecode, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, typecode);\n\t}\n\telse if (PyObject_HasAttrString(op, \"__array__\")) {\n\t\t/* Code that returns the object to convert for a non\n\t\t multiarray input object from the __array__ attribute of the\n\t\t object. */\n r = array_fromattr(op, typecode, flags);\n\t}\n\telse if (PyObject_HasAttrString(op, \"__array_shape__\") &&\n\t\t PyObject_HasAttrString(op, \"__array_typestr__\")) {\n\t\tr = array_frominterface(op, typecode, flags);\n\t}\n\telse {\n\t\tif (type == PyArray_NOTYPE) {\n\t\t\t_array_find_type(op, NULL, typecode, MAX_DIMS);\n\t\t}\n\t\tif (PySequence_Check(op))\n\t\t\tr = Array_FromSequence(op, typecode, \n\t\t\t\t\t min_depth, max_depth);\n\t\telse\n\t\t\tr = Array_FromScalar(op, typecode);\n\t}\n\n /* If we didn't succed return NULL */\n if (r == NULL) return NULL;\n\t\n\t/* Be sure we succeed here */\n\t\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"internal error: array_fromobject \"\\\n\t\t\t\t\"not producing an array\");\n\t\tPy_DECREF(r);\n return NULL;\n }\n\n if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {\n Py_DECREF(r);\n PyErr_SetString(PyExc_ValueError, \n \"object of too small depth for desired array\");\n return NULL;\n }\n if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {\n Py_DECREF(r);\n PyErr_SetString(PyExc_ValueError, \n \"object too deep for desired array\");\n return NULL;\n }\n return r;\n}\n\nstatic void\nPyArray_ArrayType(PyObject *op, PyArray_Typecode *intype, \n\t\t PyArray_Typecode *outtype) \n{\n\t_array_find_type(op, intype, outtype, MAX_DIMS);\n\treturn;\n}\n\nstatic int \nPyArray_ObjectType(PyObject *op, int minimum_type) \n{\n\tPyArray_Typecode intype, outtype;\n\tintype.type_num = minimum_type;\n\t_array_find_type(op, &intype, &outtype, MAX_DIMS);\n\treturn outtype.type_num;\n}\n\n\n\n/* flags is any of \n CONTIGUOUS, \n FORTRAN, (or set typecode->fortran=1)\n ALIGNED, \n NOTSWAPPED, \n WRITEABLE, \n ENSURECOPY, \n UPDATEIFCOPY,\n FORCECAST,\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, NOTSWAPPED, and WRITEABLE\n and therefore it is redundant to include those as well. \n\n BEHAVED_FLAGS == ALIGNED | NOTSWAPPED | WRITEABLE\n BEHAVED_FLAGS_RO == ALIGNED | NOTSWAPPED\n CARRAY_FLAGS = CONTIGUOUS | BEHAVED_FLAGS\n FARRAY_FLAGS = FORTRAN | BEHAVED_FLAGS\n \n By default, the returned array will be a copy of the object, \n (C) contiguous in memory, aligned, notswapped, and writeable.\n \n So CONTIGUOUS | ENSURECOPY passed in means that the returned\n array does not have to be CONTIGUOUS or a COPY but should be\n ALIGNED, NOTSWAPPED and WRITEABLE. \n\n typecode->fortran can be set to request a\n fortran-contiguous array. Fortran arrays are always behaved (aligned, \n notswapped, and writeable) and not (C) CONTIGUOUS. Note that either\n FORTRAN in the flag or typecode->fortran = 1 is enough to request\n a FORTRAN-style array. \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\nstatic PyObject *\nPyArray_FromAny(PyObject *op, PyArray_Typecode *typecode, int min_depth, \n\t\tint max_depth, int requires) \n{\n \tPyArray_Typecode mine = {PyArray_NOTYPE, 0, 0};\n\tPyArray_Typecode *type;\n\t\n\tif (typecode == NULL) type = &mine;\n\telse type = typecode;\n\t\t\n\tif (requires & ENSURECOPY) {\n\t\trequires |= DEFAULT_FLAGS;\n\t}\n\t/* Ensure that type->fortran and flags & FORTRAN are the\n\t same */\n\tif (requires & FORTRAN) typecode->fortran = 1;\n\tif (type->fortran == 1) {\n\t\trequires |= FARRAY_FLAGS;\n\t\tif (min_depth > 2) requires &= ~CONTIGUOUS;\n\t}\n\n\t/* make sure itemsize is not 0 unless warranted. */\n\tif ((type->itemsize == 0) && (type->type_num != PyArray_NOTYPE)) {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(type->type_num);\n\t\tif (descr != NULL) type->itemsize = descr->elsize;\n\t\telse return NULL;\n\t}\n\t\n\treturn array_fromobject(op, type, min_depth, max_depth, \n\t\t\t\trequires);\t\n}\n\n/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0, 0) */\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\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);\n Py_DECREF(op);\n return new;\n}\n\n/* These are all compressed into a single API */\n/* Deprecated calls -- Use PyArray_FromAny */\n\nstatic PyObject *\nPyArray_FromObject(PyObject *op, int type, int min_depth, int max_depth) \n{\n\tPyArray_Typecode typecode = {0, 0, 0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth,\n\t\t\t max_depth, BEHAVED_FLAGS | ENSUREARRAY);\n}\n\nstatic PyObject *\nPyArray_ContiguousFromObject(PyObject *op, int type, int min_depth, \n\t\t\t int max_depth) \n{\n\tPyArray_Typecode typecode = {0, 0, 0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth,\n\t\t\t max_depth, DEFAULT_FLAGS | ENSUREARRAY);\n}\n\nstatic PyObject *\nPyArray_CopyFromObject(PyObject *op, int type, int min_depth, \n\t\t int max_depth) \n{\n\tPyArray_Typecode typecode = {0, 0, 0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth, max_depth,\n\t\t\t ENSURECOPY | ENSUREARRAY);\n}\n\n/* End of deprecated */\n\nstatic PyObject *\nPyArray_ContiguousFromAny(PyObject *op, int type, int min_depth, \n\t\t\t int max_depth)\n{\n\tPyArray_Typecode typecode = {0,0,0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth,\n\t\t\t max_depth, DEFAULT_FLAGS);\n}\t\n\nstatic int \nPyArray_CanCastSafely(int fromtype, int totype) \n{\n\tPyArray_Descr *from, *to;\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\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 (to->elsize > from->elsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (to->elsize >= from->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (from->elsize < 8)\n return (to->elsize > from->elsize);\n else\n return (to->elsize >= from->elsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (from->elsize < 8)\n return ((to->elsize >> 1) > from->elsize);\n else\n return ((to->elsize >> 1) >= from->elsize);\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 (to->elsize > from->elsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (to->elsize >= from->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (from->elsize < 8)\n return (to->elsize > from->elsize);\n else\n return (to->elsize >= from->elsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (from->elsize < 8)\n return ((to->elsize >> 1) > from->elsize);\n else\n return ((to->elsize >> 1) >= from->elsize);\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 ((to->elsize >> 1) >= from->elsize);\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\nstatic Bool\nPyArray_CanCastTo(PyArray_Typecode *from, PyArray_Typecode *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->itemsize <= to->itemsize);\n\t\t\t}\n\t\t\telse if (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->itemsize * sizeof(Py_UNICODE)\\\n\t\t\t\t <= to->itemsize);\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->itemsize <= to->itemsize);\n\t\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 scipy's arraymap ****/\n/* and Python's array iterator ***/\n \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 = PyObject_GC_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 PyObject_GC_Track(it);\n return (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 PyObject_GC_UnTrack(it);\n Py_XDECREF(it->ao);\n PyObject_GC_Del(it);\n }\n\nstatic int\narrayiter_traverse(PyArrayIterObject *it, visitproc visit, void *arg)\n{\n if (it->ao != NULL)\n return visit((PyObject *)(it->ao), arg);\n return 0;\n}\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->itemsize;\n\tr = PyArray_New(self->ao->ob_type, 1, &count, \n\t\t\tself->ao->descr->type_num, NULL, NULL,\n\t\t\titemsize, 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->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->itemsize;\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\tr = PyArray_New(self->ao->ob_type, ind->nd, ind->dimensions,\n\t\t\tself->ao->descr->type_num, NULL, \n\t\t\tNULL, self->ao->itemsize, \n\t\t\t0, (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)->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\tint i;\n\tPyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tint 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\t\t\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\n\t/* Tuples 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\tr = PyArray_New(self->ao->ob_type, 1, &ii, \n\t\t\t\t\tself->ao->descr->type_num, NULL, \n\t\t\t\t\tNULL, self->ao->itemsize, 0,\n\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 */\n\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->itemsize;\n\t\tr = PyArray_New(self->ao->ob_type, 1, &n_steps, \n\t\t\t\tself->ao->descr->type_num, NULL, NULL,\n\t\t\t\tsize, 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)->copyswap;\n\t\twhile(n_steps--) {\n copyswap(dptr, self->dataptr, swap, size);\n\t\t\tfor(i=0; i< step_size; i++) \n\t\t\t\tPyArray_ITER_NEXT(self);\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\tif (PyArray_IsScalar(ind, Integer) || PyList_Check(ind)) {\n\t\tobj = PyArray_FromAny(ind, &indtype, 0, 0, FORCECAST);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tr = iter_subscript_Bool(self, (PyArrayObject *)obj);\n\t\t} \n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, &indtype, 0, 0, \n\t\t\t\t\t FORCECAST | BEHAVED_FLAGS);\n\t\t\tif (new==NULL) goto fail;\n\t\t\tobj = new;\n\t\t\tr = iter_subscript_int(self, (PyArrayObject *)obj);\n\t\t}\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\t\"unsupported iterator index\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPy_DECREF(obj);\n\t\treturn r;\n\t}\n\n\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\n fail:\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->itemsize;\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->copyswap;\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(self->dataptr, val->dataptr, swap,\n itemsize);\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t\tPyArray_ITER_NEXT(val);\n\t\tif (val->index==val->size) \n\t\t\tPyArray_ITER_RESET(val);\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_Typecode typecode;\n\tintp num;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\titemsize = typecode.itemsize = self->ao->itemsize;\n\ttypecode.type_num = self->ao->descr->type_num;\n copyswap = self->ao->descr->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\n\nstatic int\niter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val) \n{\n\tint i;\n\tPyObject *arrval=NULL;\n\tPyArrayIterObject *val_it=NULL;\n\tPyArray_Typecode type;\n\tPyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tint swap;\n\tint itemsize;\n\tint start, step_size;\n\tintp n_steps;\n\tPyObject *obj;\n PyArray_CopySwapFunc *copyswap;\n\t\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\ti = iter_ass_subscript(self, ind, val);\n\t\tPy_DECREF(ind);\n\t\treturn i;\n\t}\n\t\n\ttype.type_num = self->ao->descr->type_num;\n\titemsize = type.itemsize = self->ao->itemsize;\n\t\n\tarrval = PyArray_FromAny(val, &type, 0, 0, 0);\n\tif (arrval==NULL) return -1;\n\tval_it = (PyArrayIterObject *)PyArray_IterNew(arrval);\n\tif (val_it==NULL) goto fail;\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\n copyswap = PyArray_DESCR(arrval)->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\tgoto succeed;\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 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 copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, itemsize);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\tgoto succeed;\n\t\t}\n\t\twhile(n_steps--) {\n copyswap(self->dataptr, val_it->dataptr,\n swap, itemsize);\n\t\t\tfor(i=0; i < step_size; i++) \n\t\t\t\tPyArray_ITER_NEXT(self);\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\tgoto succeed;\n\t} \n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tif (PyArray_IsScalar(ind, Integer))\n\t\tobj = PyArray_FromScalar(ind, &indtype);\n\telse if (PyList_Check(ind)) {\n\t\tobj = PyArray_FromAny(ind, &indtype, 0, 0, FORCECAST);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tif (iter_ass_sub_Bool(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto fail;\n\t\t} \n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, &indtype, 0, 0, \n\t\t\t\t\t FORCECAST | BEHAVED_FLAGS);\n\t\t\tif (new==NULL) goto fail;\n\t\t\tPy_DECREF(obj);\n\t\t\tobj = new;\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 fail;\n\t\t}\n\t\telse goto fail;\n\t\tPy_DECREF(obj);\n\t\tgoto succeed;\n\t}\n\n\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\tgoto fail;\n\n succeed:\n\tPy_DECREF(val_it);\n\tPy_DECREF(arrval);\n\treturn 0;\n\n fail:\n\tPy_XDECREF(val_it);\n\tPy_XDECREF(arrval);\n\treturn -1;\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 if (PyArray_ISCONTIGUOUS(it->ao)) {\n r = PyArray_New(it->ao->ob_type, 1, &size, \n\t\t\t\tit->ao->descr->type_num,\n NULL, it->ao->data, it->ao->itemsize, \n\t\t\t\tit->ao->flags,\n (PyObject *)it->ao); \n\t\tif (r==NULL) return NULL;\n }\n else {\n r = PyArray_New(it->ao->ob_type, 1, &size, \n\t\t\t\tit->ao->descr->type_num,\n NULL, NULL, it->ao->itemsize, 0, \n (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\n\nstatic PyTypeObject PyArrayIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"scipy.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 | Py_TPFLAGS_HAVE_GC,/* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)arrayiter_traverse,\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)arrayiter_next,\t\t/* tp_iternext */\n iter_methods,\t\t\t\t/* tp_methods */\n};\n\n/** END of Array Iterator **/\n\n\n\n/*********************** Subscript Array Iterator *************************\n * *\n * This object handles subscript behavior for array objects. *\n * It is an iterator object with a next method *\n * It abstracts the n-dimensional mapping behavior to make the looping *\n * code more understandable (maybe) *\n * and so that indexing can be set up ahead of time *\n */ \n\n/* This checks the args for any fancy indexing objects */\n\n#define SOBJ_NOTFANCY 0 \n#define SOBJ_ISFANCY 1\n#define SOBJ_BADARRAY 2\n#define SOBJ_TOOMANY 3\n#define SOBJ_LISTTUP 4\n\nstatic int\nfancy_indexing_check(PyObject *args)\n{\n\tint i, n;\n\tPyObject *obj;\n\tint retval = SOBJ_NOTFANCY;\n\n\tif (PyTuple_Check(args)) {\n\t\tn = PyTuple_GET_SIZE(args);\n\t\tif (n >= MAX_DIMS) return SOBJ_TOOMANY;\n\t\tfor (i=0; i=MAX_DIMS) return SOBJ_ISFANCY;\n\t\tfor (i=0; i SOBJ_ISFANCY) return retval;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* convert an indexing object to an INTP indexing array iterator\n if possible -- otherwise, it is a Slice or Ellipsis object\n and has to be interpreted on bind to a particular \n array so leave it NULL for now.\n */\nstatic int\n_convert_obj(PyObject *obj, PyArrayIterObject **iter)\n{\n\tPyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tPyObject *arr;\n\n\tif (PySlice_Check(obj) || (obj == Py_Ellipsis))\n\t\t*iter = NULL;\n\telse {\n\t\tarr = PyArray_FromAny(obj, &indtype, 0, 0, FORCECAST);\n\t\tif (arr == NULL) return -1;\n\t\t*iter = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (*iter == NULL) return -1;\n\t}\n\treturn 0;\n}\n\n/* Adjust dimensionality and strides for index object iterators \n --- i.e. broadcast\n */\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->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->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=NULL, *obj=NULL;\n\tint i, j, n, curraxis, ellipexp, noellip;\n\tPyArrayIterObject *it;\n\tintp dimsize;\n\tintp *indptr;\n\n\t/* Remove old binding if any */\n\tPy_XDECREF(mit->ait);\n\tmit->ait = NULL;\n\n\tPy_XDECREF(mit->subspace);\n\tmit->subspace = NULL;\n\t\n\tsubnd = arr->nd - mit->numiter;\n\tif (subnd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"too many indices for array\");\n\t\treturn;\n\t}\n\n\tmit->ait = (PyArrayIterObject *)PyArray_IterNew((PyObject *)arr);\n\tif (mit->ait == NULL) return;\n\n\t/* If this is just a view, then do nothing more */\n\t/* views are handled by just adjusting the strides\n\t and dimensions of the object.\n\t*/\n\t \n\tif (mit->view) return;\n\n\t/* no subspace iteration needed. 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\tif (mit->subspace == NULL) goto fail;\n\tPy_DECREF(sub);\n\n\t/* Expand dimensions of result */\n\tn = mit->subspace->ao->nd;\n\tfor (i=0; idimensions[mit->nd+i] = mit->subspace->ao->dimensions[i];\n\tmit->nd += n;\n\n\t/* Now, we still need to interpret the ellipsis and slice objects \n\t to determine which axes the indexing arrays are referring to\n\t*/\n\tn = PyTuple_GET_SIZE(mit->indexobj);\n\n\t/* The number of dimensions an ellipsis takes up */\n\tellipexp = arr->nd - n + 1;\n\t/* Now fill in iteraxes -- remember indexing arrays have been \n converted to 0's in mit->indexobj */\n\tcurraxis = 0;\n\tj = 0;\n\tnoellip = 1; /* Only expand the first ellipsis */\n\tmemset(mit->bscoord, 0, sizeof(intp)*arr->nd);\n\tfor (i=0; iindexobj, i);\n\t\tif (PyInt_Check(obj) || PyLong_Check(obj)) \n\t\t\tmit->iteraxes[j++] = curraxis++;\n\t\telse if (noellip && obj == Py_Ellipsis) {\n\t\t\tcurraxis += ellipexp;\n\t\t\tnoellip = 0;\n\t\t}\n\t\telse {\n\t\t\tint start=0;\n\t\t\tint 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}\t\t\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn;\n\n fail:\n\tPy_XDECREF(sub);\n\tPy_XDECREF(mit->ait);\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_Typecode typecode = {PyArray_BOOL, 0, 0};\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\tba = (PyArrayObject *)PyArray_FromAny(myBool, &typecode, 0, 0, \n\t\t\t\t\t CARRAY_FLAGS);\n\tif (ba == NULL) return -1;\n\tnd = ba->nd;\n\tfor (j=0; jdata;\n\tcount = 0;\n\n\t/* pre-determine how many nonzero entries there are */\n\tfor (i=0; iao->data;\n\t\tcoords[j] = 0;\n\t\tdims_m1[j] = ba->dimensions[j]-1;\n\t}\n\n\tptr = (Bool *)ba->data;\n\n\tif (count == 0) return nd;\n\n\t/* Loop through the Boolean array and copy coordinates\n\t for non-zero entries */\n\tfor (i=0; i=0; j--) {\n\t\t\tif (coords[j] < dims_m1[j]) {\n\t\t\t\tcoords[j]++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcoords[j] = 0;\n\t\t\t}\n\t\t}\n\t}\n\treturn nd;\n\n fail:\n\tfor (j=0; jiters[i] = NULL;\n \tmit->view = 0;\n \tmit->index = 0;\n \tmit->ait = NULL;\n \tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tfancy = fancy_indexing_check(indexobj);\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\tif (fancy == SOBJ_NOTFANCY) { /* bail out */\n\t\tmit->view = 1;\n\t\tgoto ret;\n\t}\n\n\tif (fancy == SOBJ_BADARRAY) {\n\t\tPyErr_SetString(PyExc_TypeError,\t\t\t\\\n\t\t\t\t\"arrays used as indexes must be of \" \\\n\t\t\t\t\"integer type\");\n\t\tgoto fail;\n\t}\n\tif (fancy == SOBJ_TOOMANY) {\n\t\tPyErr_SetString(PyExc_TypeError, \"too many indicies\");\n\t\tgoto fail;\n\t}\n\n\tif (fancy == SOBJ_LISTTUP) {\n\t\tPyObject *newobj;\n\t\tnewobj = PySequence_Tuple(indexobj);\n\t\tif (newobj == NULL) goto fail;\n\t\tPy_DECREF(indexobj);\n\t\tindexobj = newobj;\n\t\tmit->indexobj = indexobj;\n\t}\n\n#undef SOBJ_NOTFANCY \n#undef SOBJ_ISFANCY \n#undef SOBJ_BADARRAY \n#undef SOBJ_TOOMANY \n#undef SOBJ_LISTTUP \n\n\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\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 (PyList_Check(indexobj) || PyArray_Check(indexobj)) {\n\t\tmit->numiter = 1;\n\t\tarr = PyArray_FromAny(indexobj, &indtype, 0, 0, FORCECAST);\n\t\tif (arr == NULL) goto fail;\n\t\tmit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (mit->iters[0] == NULL) 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(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\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = new;\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\t/* Store the number of iterators actually converted */\n\t\t/* These will be mapped to actual axes at bind time */\n\t\tif (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)\n\t\t\tgoto fail;\n\t}\n\n ret:\n PyObject_GC_Track(mit);\n return (PyObject *)mit;\n \n fail:\n\tPy_XDECREF(arr);\n\tPy_XDECREF(mit->indexobj);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n PyObject_GC_Del(mit);\n\treturn NULL;\n}\n\n\n/* return unbound mapiter object */\n\nstatic PyObject *\narraymapiter_new(PyTypeObject *type, PyObject *args, PyObject *kwds) \n{\n\tPyObject *newtup, *res;\n\tint n;\n\n\tif (!PyTuple_Check(args)) {\n\t\tPyErr_BadInternalCall();\n\t\treturn NULL;\n\t}\n\n\tn = PyTuple_GET_SIZE(args);\n\t\n\tif (n < 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"must be initialized with >= 1 argument\");\n\t\treturn NULL;\n\t}\n\t\n\tif (n > 1) {\n\t\tnewtup = PyTuple_GetSlice(args, 0, n);\n\t\tif (newtup == NULL) return NULL;\n\t\tres = PyArray_MapIterNew(newtup);\n\t\tPy_DECREF(newtup);\n\t}\n\telse { /* n == 1 */\n\t\tnewtup = PyTuple_GET_ITEM(args, 0);\n\t\tres = PyArray_MapIterNew(newtup);\n\t}\n\n\treturn res; \t\n}\n\n\n/* Returns a 0-dim array holding the element desired */\n/*\nstatic PyObject *\narraymapiter_next(PyArrayMapIterObject *mit)\n{\n\tPyObject *ret;\n\tif (mit->ait == NULL) return NULL;\n\tif (mit->view) return NULL;\n\tif (mit->index < mit->size) {\n\t\tret = PyArray_ToScalar(mit->dataptr, mit->ait->ao);\n\t\tPyArray_MapIterNext(mit);\n\t\treturn ret;\n\t}\n return NULL;\n}\n*/\n\nstatic void\narraymapiter_dealloc(PyArrayMapIterObject *mit)\n{\n\tint i;\n PyObject_GC_UnTrack(mit);\n Py_XDECREF(mit->ait);\n\tPy_XDECREF(mit->indexobj);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n PyObject_GC_Del(mit);\n}\n\nstatic int\narraymapiter_traverse(PyArrayMapIterObject *mit, visitproc visit, void *arg)\n{\n\tint ret, i;\n if (mit->ait != NULL)\n if ((ret = visit((PyObject *)(mit->ait), arg)) != 0) \n\t\t\treturn ret;\t\n\n\tif (mit->iters != NULL) \n\t\tfor (i=0; inumiter; i++) \n\t\t\tif (mit->iters[i] != NULL) \n\t\t\t\tif ((ret=visit((PyObject *)mit->iters[i], \n\t\t\t\t\t arg)) != 0)\n\t\t\t\t\treturn ret;\n\n\tif (mit->indexobj != NULL)\n\t\tif ((ret = visit(mit->indexobj, arg)) != 0) return ret;\n\t\n return 0;\n}\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 MapIterNew must be \n that does not work. 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 char doc_mapiter_bind[] = \"obj.bind(a)\\n Bind an array to the \"\\\n\t\"mapiter object\";\n\nstatic PyObject *\nmapiter_bind(PyArrayMapIterObject *mit, PyObject *args)\n{\n\tPyArrayObject *arr;\n\n if (!PyArg_ParseTuple(args, \"O!\", &PyArray_Type, &arr)) return NULL;\n\n \tPyArray_MapIterBind(mit, arr);\n\n\tif (mit->ait == NULL) return NULL;\n\t\n \tPyArray_MapIterReset(mit);\n\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyMethodDef mapiter_methods[] = {\n\t{\"bind\", (PyCFunction)mapiter_bind, 1, doc_mapiter_bind},\n {NULL,\t\tNULL}\t\t\n};\n*/\n\n\nstatic PyTypeObject PyArrayMapIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"scipy.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 | Py_TPFLAGS_HAVE_GC,/* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)arraymapiter_traverse,\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, /*arraymapiter_next,*/\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 (newfunc)arraymapiter_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n\n};\n\n/** END of Subscript Iterator **/\n\n\n\n", "source_code_before": " /*\n Provide multidimensional arrays as a basic object type in python. \n\nBased on Original Numeric implementation\nCopyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\nwith contributions from many Numeric Python developers 1995-2004 *\n\nHeavily modified in 2005 with inspiration from Numarray \n\nby\n\nTravis Oliphant\nAssistant Professor at\nBrigham Young University \n\nmaintainer email: oliphant.travis@ieee.org\n\nNumarray design (which provided guidance) by \nSpace Science Telescope Institute \n (J. Todd Miller, Perry Greenfield, Rick White)\n\n*/\n\n/* $Id: arrayobject.c,v 1.59 2005/09/14 00:14:00 teoliphant Exp $ */\n\n/*\n#include \"Python.h\"\n#include \"structmember.h\"\n\n#define _MULTIARRAYMODULE\n#include \"Numeric3/arrayobject.h\"\n*/\n\n/* Helper functions */\n\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\n\nstatic intp\nPyArray_PyIntAsIntp(PyObject *o)\n{\n\tlonglong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr=NULL;\n\tPyArray_Typecode typecode = {PyArray_INTP, 0, 0};\n\tintp ret;\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\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\tarr = PyArray_CastToType((PyArrayObject *)o, &typecode);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tarr = PyArray_FromScalar(o, &typecode);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((intp *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\t\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONGLONG != SIZEOF_PY_INTPTR_T)\n\tif ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C intp\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (intp) long_value;\n}\n\n\nstatic PyObject *array_int(PyArrayObject *v);\n\nstatic int\nPyArray_PyIntAsInt(PyObject *o)\n{\n\tlong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr=NULL;\n\tPyArray_Typecode typecode = {PyArray_INT, 0, 0};\n\tint ret;\n\t\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\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\tarr = PyArray_CastToType((PyArrayObject *)o, &typecode);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tarr = PyArray_FromScalar(o, &typecode);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((int *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t} else if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONG != SIZEOF_INT)\n\tif ((long_value < INT_MIN) || (long_value > INT_MAX)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C int\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (int) long_value;\n}\n\n\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\nstatic char *\nPyArray_Zero(PyArrayObject *arr)\n{\n char *zeroval;\n char *buf;\n int buf_len;\n PyObject *obj, *ret;\n\n zeroval = PyDataMem_NEW(arr->itemsize);\n if (zeroval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n if (PyArray_ISOBJECT(arr)) {\n obj=PyInt_FromLong((long) 0);\n memcpy(zeroval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return zeroval;\n }\n ret = PyObject_GetAttrString((PyObject *)arr, \"_zero\");\n if (ret != NULL) {\n if (PyObject_AsReadBuffer(ret, (const void **)&buf, \n &buf_len) < 0) {\n PyErr_SetString(PyExc_ValueError, \n \"_zero not returning \" \\\n \"writeable buffer\");\n Py_DECREF(ret);\n return NULL;\n }\n memcpy(zeroval, buf, buf_len);\n Py_DECREF(ret);\n }\n if (PyErr_Occurred()) PyErr_Clear();\n memset(zeroval, 0, arr->itemsize);\n return zeroval;\n}\n\nstatic char *\nPyArray_One(PyArrayObject *arr)\n{\n char *oneval;\n char *buf;\n int buf_len, ret2;\n PyObject *obj, *ret;\n\n oneval = PyDataMem_NEW(arr->itemsize);\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 ret = PyObject_GetAttrString((PyObject *)arr, \"_one\");\n if (ret != NULL) {\n if (PyObject_AsReadBuffer(ret, (const void **)&buf, \n &buf_len) < 0) {\n PyErr_SetString(PyExc_ValueError, \n \"_one not returning \" \\\n \"writeable buffer\");\n Py_DECREF(ret);\n PyDataMem_FREE(oneval);\n return NULL;\n }\n memcpy(oneval, buf, buf_len);\n Py_DECREF(ret);\n }\n if (PyErr_Occurred()) PyErr_Clear();\n\n ret2 = arr->descr->setitem(obj, oneval, arr);\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->itemsize;\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 *)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 { free(new_data); return NULL; }\n}\n\n/* end Helper functions */\n\n\nstatic PyObject *PyArray_New(PyTypeObject *, int nd, intp *, \n int, intp *, char *, 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. */\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/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\n\nstatic char *\nindex2ptr(PyArrayObject *mp, intp i) \n{\n\tif (i==0 && (mp->nd == 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\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\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->copyswap;\n\tcopyswapn = dest->descr->copyswapn;\n\n elsize = dest->itemsize;\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->itemsize;\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\tPyArray_Typecode typecode;\n\n\n\ttypecode.type_num = dest->descr->type_num;\n\ttypecode.itemsize = dest->itemsize;\n\ttypecode.fortran = PyArray_ISFORTRAN(dest);\n\t\t\t\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n\t\t\t\t\t &typecode, 0,\n\t\t\t\t\t dest->nd, 0);\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\nstatic PyObject *\nPyArray_FromDimsAndDataAndDescr(int nd, int *d, \n PyArray_Descr *descr,\n char *data) {\n\tPyObject *ret;\n\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\n\tintp newd[MAX_DIMS];\n\t\n\tfor (i=0; itype_num, NULL, data, descr->elsize, \n\t\t\t CARRAY_FLAGS, NULL);\n#else\n\tret = PyArray_New(&PyArray_Type, nd, (intp *)d, \n descr->type_num, NULL, data, descr->elsize, \n\t\t\t CARRAY_FLAGS, NULL);\n#endif\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_FromDimsAndData(int nd, int *d, int type, char *data) \n{\n\tPyObject *ret;\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\t\n\tintp newd[MAX_DIMS];\n\n\tfor (i=0; iob_type, m1->nd, \n\t\t\t\t\t m1->dimensions,\n\t\t\t\t\t m1->descr->type_num,\n\t\t\t\t\t NULL, NULL, m1->itemsize,\n\t\t\t\t\t 0, (PyObject *)m1);\n\t\n if (PyArray_CopyInto(ret, m1) == -1) return NULL;\n\t\n return (PyObject *)ret;\n}\n\n\nstatic PyObject *array_big_item(PyArrayObject *, intp);\n\nstatic PyObject *\nPyArray_Scalar(char *data, int type_num, int itemsize, int swap)\n{\n PyArray_Descr *descr;\n\tPyTypeObject *type;\n\tPyObject *obj;\t\n\tchar *destptr;\n PyArray_CopySwapFunc *copyswap;\n\n descr = PyArray_DescrFromType(type_num);\n if (descr == NULL) return NULL;\n type = descr->typeobj;\n copyswap = descr->copyswap;\n\tif (type_num == PyArray_STRING) \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_ISFLEXIBLE(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 {\n\t\t\tdestptr = PyDataMem_NEW(itemsize);\n\t\t\tif (destptr == NULL) {\n\t\t\t\tPyObject_Del(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tif (type_num == PyArray_UNICODE) {\n\t\t\t\tPyUnicode_AS_UNICODE(obj) = \\\n\t\t\t\t\t(Py_UNICODE *)destptr;\n\t\t\t\t((PyUnicodeObject*)obj)->length = itemsize / \\\n\t\t\t\t\tsizeof(Py_UNICODE);\n\t\t\t\t((PyUnicodeObject*)obj)->hash = -1;\n\t\t\t}\n\t\t\telse {\n\t\t\t\t((PyVoidScalarObject *)obj)->obval = destptr;\n\t\t\t\t((PyVoidScalarObject *)obj)->ob_size = itemsize;\n\t\t\t}\n\t\t}\n\t}\n\telse {\n\t\tdestptr = &(((PyScalarObject*)obj)->obval);\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*/\nstatic PyObject *\nPyArray_ToScalar(char *data, PyArrayObject *arr)\n{\n\tint type_num = arr->descr->type_num;\n\tint itemsize = arr->itemsize;\n int swap = !(PyArray_ISNOTSWAPPED(arr));\n\n\treturn PyArray_Scalar(data, type_num, itemsize, swap);\n}\n\n\n/* Return Python scalar if 0-d array object is encountered */\n\nstatic PyObject *\nPyArray_Return(PyArrayObject *mp) \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((PyObject *)mp) && 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*/\nstatic int \nPyArray_RegisterDataType(PyTypeObject *type)\n{\n\tPyArray_Descr *descr;\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 = malloc(sizeof(PyArray_Descr));\n\tmemcpy(descr, PyArray_DescrFromType(PyArray_VOID), \n\t sizeof(PyArray_Descr));\n\ttypenum = PyArray_USERDEF + PyArray_NUMUSERTYPES;\n\tdescr->type_num = typenum;\n\tdescr->typeobj = 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 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 frees the copy of the Descr_table already there.\n places a pointer to the new one into the slot.\n*/\nstatic int\nPyArray_RegisterDescrForType(int typenum, PyArray_Descr *descr)\n{\n\tPyArray_Descr *old;\n\tint i;\n\n\tif (!PyTypeNum_ISUSERDEF(typenum)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"data type not registered\");\n\t\treturn -1;\n\t}\n\told = userdescrs[typenum-PyArray_USERDEF];\n\tdescr->typeobj = old->typeobj;\n\tdescr->type_num = typenum;\n\n#define _NULL_CHECK(member) \\\n\tif (descr->member == NULL) descr->member = old->member\n\n\tfor (i=0; imember == 0) descr->member = old->member\n\n\t_ZERO_CHECK(kind);\n\t_ZERO_CHECK(type);\n\t_ZERO_CHECK(elsize);\n\t_ZERO_CHECK(alignment);\n#undef _ZERO_CHECK\n\n\tfree(old);\n\tuserdescrs[typenum-PyArray_USERDEF] = descr;\n\treturn 0;\n}\n\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 n3 = strlen((const char *)sep);\n if (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 \"\\\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->itemsize,\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->itemsize,\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 = strlen((const char *)format);\n while(it->index < it->size) {\n obj = self->descr->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\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->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\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 if (PyArray_TYPE(self) == PyArray_OBJECT) {\n PyErr_SetString(PyExc_ValueError, \"a string for the data\"\\\n\t\t\t\t\"in an object array is not appropriate\");\n return NULL;\n }\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->itemsize;\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 != NULL)) {\n\t\t/* Free internal references if an Object array */\n\t\tPyArray_XDECREF(self);\n\n PyDataMem_FREE(self->data);\n }\n\t\n if (self->dimensions != NULL) {\n PyDimMem_FREE(self->dimensions); \n\t}\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\n\nstatic PyObject *\narray_big_item(PyArrayObject *self, intp i) \n{\n\tchar *item;\n\tPyArrayObject *r;\n\t\n\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\tr = (PyArrayObject *)PyArray_New(self->ob_type, \n\t\t\t\t\t self->nd-1, self->dimensions+1, \n\t\t\t\t\t self->descr->type_num, \n\t\t\t\t\t self->strides+1, item, \n\t\t\t\t\t self->itemsize, self->flags,\n\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\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->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, int *v)\n{\n\t*v = PyArray_PyIntAsInt(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, int length,\n int *start, int *stop, int *step,\n intp *slicelength)\n{\n\tint 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 int\nparse_subindex(PyObject *op, int *step_size, intp *n_steps, int max)\n{\n\tint 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\tint 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_PyIntAsInt(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, start, offset, n_add, n_pseudo;\n int step_size;\n\tintp n_steps;\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, *tup;\n\tint n1, n2, n3, val;\n\tint i;\n\n\ttup = PyTuple_New(mit->nd);\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\tPyTuple_SET_ITEM(tup, i++, PyInt_FromLong((long)val++));\n\tval = 0;\n\twhile(val < n1)\n\t\tPyTuple_SET_ITEM(tup, i++, PyInt_FromLong((long)val++));\n\tval = n1+n2;\n\twhile(val < n3)\n\t\tPyTuple_SET_ITEM(tup, i++, PyInt_FromLong((long)val++));\n\n\tnew = PyArray_Transpose(*ret, tup);\n\tPy_DECREF(tup);\n\tPy_DECREF(*ret);\n\t*ret = (PyArrayObject *)new;\n}\n\n\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\tret = (PyArrayObject *)\\\n\t\tPyArray_New(temp->ob_type, mit->nd, mit->dimensions, \n\t\t\t temp->descr->type_num, NULL, NULL, \n\t\t\t temp->itemsize, \n\t\t\t PyArray_ISFORTRAN(temp),\n\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\treturn NULL;\n\tindex = it->size;\n\tswap = ((temp->flags & NOTSWAPPED) != (ret->flags & NOTSWAPPED));\n copyswap = ret->descr->copyswap;\n\tPyArray_MapIterReset(mit);\n\twhile (index--) {\n copyswap(it->dataptr, mit->dataptr, swap, ret->itemsize);\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\tPyArray_Typecode typecode = {0, 0, 0};\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Unbound Map Iterator */\n\tif (mit->ait == NULL) return -1;\n\n\ttypecode.type_num = mit->ait->ao->descr->type_num;\n\ttypecode.itemsize = mit->ait->ao->itemsize;\n\n\tarr = PyArray_FromAny(op, &typecode, \n\t\t\t 0, 0, FORCECAST);\n\tif (arr == NULL) return -1;\n\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, (PyArrayObject **)&arr);\n\t\t}\n\t}\n\t\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) \n\t\treturn -1;\n\n\tindex = mit->size;\n\tswap = ((mit->ait->ao->flags & NOTSWAPPED) != \\\n\t\t(PyArray_FLAGS(arr) & NOTSWAPPED));\n\n copyswap = PyArray_DESCR(arr)->copyswap;\n\tPyArray_MapIterReset(mit);\n /* Need to decref OBJECT arrays */\n if (PyTypeNum_ISOBJECT(typecode.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 copyswap(mit->dataptr, NULL, swap, \n sizeof(PyObject *));\n PyArray_MapIterNext(mit);\n PyArray_ITER_NEXT(it);\n if (it->index == it->size)\n PyArray_ITER_RESET(it);\n }\n return 0;\n }\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\treturn 0;\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 0-dimensional arrays */\n\nstatic PyObject *\narray_subscript(PyArrayObject *self, PyObject *op) \n{\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n\tintp offset;\n int nd;\n\tintp i;\n PyArrayObject *other;\n\tPyArrayMapIterObject *mit;\n\n if (PyArray_IsScalar(op, Integer) || PyInt_Check(op) || \\\n PyLong_Check(op)) {\n intp value;\n value = PyArray_PyIntAsIntp(op);\n if (PyErr_Occurred())\n PyErr_Clear();\n else if (value >= 0) {\n if (value <= MAX_INT)\n return array_big_item(self, value);\n }\n else if (value < 0) {\n if (value >= -MAX_INT) {\n if (self->nd > 0) value += self->dimensions[0];\n return array_big_item(self, value);\n }\n }\n }\n\n\tif (PyArrayMapIter_Check(op)) {\n\t\tmit = (PyArrayMapIterObject *)op;\n\t\t/* bind to current array */\n\t\tPyArray_MapIterBind(mit, self);\n\t\t\n\t\t/* If the mapiterator was created with standard indexing\n\t\t behavior, fall through to view-based code */\n\t\tif (!mit->view) return PyArray_GetMap(mit);\n\t\top = mit->indexobj;\n\t}\n\telse { /* wrap arguments into a mapiter object */\n\t\tmit = (PyArrayMapIterObject *)PyArray_MapIterNew(op);\n\t\tif (mit == NULL) return NULL;\n\t\tif (!mit->view) { /* fancy indexing */\n\t\t\tPyArray_MapIterBind(mit, self);\n\t\t\tother = (PyArrayObject *)PyArray_GetMap(mit);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn (PyObject *)other;\n\t\t}\n\t\tPy_DECREF(mit);\n\t}\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\tif ((other = (PyArrayObject *)\t\t\t\t\t\\\n\t PyArray_New(self->ob_type, nd, dimensions, self->descr->type_num,\n\t\t\t strides, self->data+offset, \n\t\t\t self->itemsize, self->flags,\n\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 \narray_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op) \n{\n int ret;\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\n\tif (PyArrayMapIter_Check(index)) {\n\t\tmit = (PyArrayMapIterObject *)index;\n\t\t/* bind behavior to current array */\n\t\tPyArray_MapIterBind(mit, self);\n\t\t\t\n\t\t/* fall through if standard view-based map iterator */\n\t\tif (!mit->view) return PyArray_SetMap(mit, op);\n\t\tindex = mit->indexobj;\n\t}\n\telse {\n\t\tmit = (PyArrayMapIterObject *)PyArray_MapIterNew(index);\n\t\tif (mit == NULL) return -1;\n\t\tif (!mit->view) {\n\t\t\tPyArray_MapIterBind(mit, self);\n\t\t\tret = PyArray_SetMap(mit, op);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn ret;\n\t\t}\n\t\tPy_DECREF((PyObject*)mit);\n\t}\n\n\ti = PyArray_PyIntAsIntp(index);\n\tif (!error_converting(i)) {\n\t\treturn array_ass_big_item(self, i, op);\n\t}\n\tPyErr_Clear();\n\t\n\t/* Rest of standard (view-based) indexing */\n\n if ((tmp = (PyArrayObject *)array_subscript(self, index)) == NULL)\n return -1; \n ret = PyArray_CopyObject(tmp, op);\n Py_DECREF(tmp);\n\t\n return ret;\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 \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\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}\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}\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 PyObject *args, *ret;\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n args = Py_BuildValue(\"(OO)\", m1, m2);\n ret = PyObject_Call(op, args, NULL);\n Py_DECREF(args);\n return ret;\n}\n\nstatic PyObject *\nPyArray_GenericUnaryFunction(PyArrayObject *m1, PyObject *op) \n{\n PyObject *args, *ret;\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n args = Py_BuildValue(\"(O)\", m1);\n ret = PyObject_Call(op, args, NULL);\n Py_DECREF(args);\n return ret;\n}\n\nstatic PyObject *\nPyArray_GenericInplaceBinaryFunction(PyArrayObject *m1, \n\t\t\t\t PyObject *m2, PyObject *op) \n{\n PyObject *args, *ret;\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n args = Py_BuildValue(\"(OOO)\", m1, m2, m1);\n ret = PyObject_Call(op, args, NULL);\n Py_DECREF(args);\n return ret;\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_all_nonzero(PyArrayObject *mp) \n{\n\tintp index;\n\tPyArrayIterObject *it;\n\tBool anyTRUE = 0;\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->nonzero(it->dataptr, mp)) {\n\t\t\tanyTRUE = 1;\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 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->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->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->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->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->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_all_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 r = (PyArrayObject *)\\\n\t\tPyArray_New(self->ob_type, self->nd, self->dimensions, \n\t\t\t self->descr->type_num, self->strides, data,\n\t\t\t self->itemsize, 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 any(self == el) */\n\n return PyObject_RichCompareBool((PyObject *)self, el, Py_EQ);\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 *)realloc(*string, *max_n); }\n\t\n if (nd == 0) {\n\t\t\n if ((op = descr->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\tfree(string); return NULL; \n\t}\n\t\n\tif (PyArray_ISFLEXIBLE(self)) {\n\t\tchar buf[100];\n\t\tsnprintf(buf, sizeof(buf), \"%d\", self->itemsize);\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 free(string);\n return ret;\n}\n\nstatic PyObject *PyArray_StrFunction=NULL;\nstatic PyObject *PyArray_ReprFunction=NULL;\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\n\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) \n{\n PyObject *array_other, *result;\n\n switch (cmp_op) \n {\n case Py_LT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less);\n case Py_LE:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less_equal);\n case Py_EQ:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then return the integer\n\t\t\t object 0. This fixes code that used to\n\t\t\t allow equality comparisons between arrays\n\t\t\t and other objects which would give a result\n\t\t\t of 0\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n result = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.equal);\n /* If the comparison results in NULL, then the \n\t\t\t two array objects can not be compared together so \n\t\t\t return zero \n */\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n return result;\n case Py_NE:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then objects cannot be \n\t\t\t compared and cannot be equal, therefore, \n\t\t\t return True;\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n result = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.not_equal);\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n return result;\n case Py_GT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.greater);\n case Py_GE:\n return PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t other, \n\t\t\t\t\t \t n_ops.greater_equal);\n }\n return NULL;\n}\n\nstatic PyObject *\n_check_axis(PyArrayObject *arr, int *axis, int flags)\n{\n\tPyObject *temp;\n\tint n = arr->nd;\n\n\tif ((*axis >= MAX_DIMS) || (n==0)) {\n\t\ttemp = PyArray_Ravel(arr,0);\n\t\t*axis = 0;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_FromAny((PyObject *)arr, NULL, \n\t\t\t\t\t 0, 0, flags);\n\t\t\tif (temp == NULL) return NULL;\n\t\t}\n\t\telse {\n\t\t\tPy_INCREF(arr);\n\t\t\ttemp = (PyObject *)arr;\n\t\t}\n\t}\n\tif (*axis < 0) *axis += n;\n\tif ((*axis < 0) || (*axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", *axis);\n\t\tPy_DECREF(temp);\n\t\treturn NULL;\n\t}\n\treturn temp;\n}\n\n#include \"arraymethods.c\"\n\n/* Lifted from numarray */\nstatic PyObject *\nPyArray_IntTupleFromIntp(int len, intp *vals)\n{\n\tint i;\n PyObject *intTuple = PyTuple_New(len);\n if (!intTuple) goto fail;\n for(i=0; ind == 0) return 1;\n\tsd = ap->itemsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\n\t}\n\treturn 1;\n}\n\n\nstatic int \n_IsFortranContiguous(PyArrayObject *ap) \n{\n\tint sd;\n\tint i;\n\t\n\tif (ap->nd == 0) return 1;\n\tsd = ap->itemsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i=0; i< ap->nd; ++i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\n\t}\n\treturn 1;\n}\n\nstatic int\n_IsAligned(PyArrayObject *ap) \n{\n\tint i, alignment, aligned=1;\n\tintp ptr;\n\tint type = ap->descr->type_num;\n\n\tif ((type == PyArray_STRING) || (type == PyArray_VOID))\n\t\treturn 1;\n\n\talignment = ap->descr->alignment;\n\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\tPyBufferProcs *pb;\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\tpb = base->ob_type->tp_as_buffer;\n\tif (pb == NULL || pb->bf_getwritebuffer == NULL)\n\t\treturn FALSE;\n\t\n\treturn TRUE;\n}\n\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\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not \n walk outside of the memory implied by either numbytes or\n a single segment array of the provided dimensions and element size if\n numbytes is 0 */\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, \n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\t\n\tif (numbytes == 0) \n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\t\n\tfor (i=0; i numbytes) {\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\treturn TRUE;\n\t\n}\n\n\n/* This is the main array creation routine. */\n\n/* Flags argument has multiple related meanings \n depending on data and strides: \n\n If data is given, then flags is flags associated with data. \n If strides is not given, then a contiguous strides array will be created\n and the CONTIGUOUS bit will be set. If the flags argument \n has the FORTRAN bit set, then a FORTRAN-style strides array will be\n created (and of course the FORTRAN flag bit will be set). \n\n If data is not given but created here, then flags will be DEFAULT_FLAGS\n and a non-zero flags argument can be used to indicate a FORTRAN style\n array is desired. \n*/\n\nstatic intp\n_array_fill_strides(intp *strides, intp *dims, int nd, intp itemsize, \n\t\t int inflag, int *objflags) \n{\n\tint i;\n\t/* Only make Fortran strides if not contiguous as well */\n\tif ((inflag & FORTRAN) && !(inflag & CONTIGUOUS)) {\n\t\tfor (i=0; i 1) *objflags &= ~CONTIGUOUS;\n\t\telse *objflags |= CONTIGUOUS;\n\t}\n\telse {\n\t\tfor (i=nd-1;i>=0;i--) {\n\t\t\tstrides[i] = itemsize;\n\t\t\titemsize *= dims[i] ? dims[i] : 1;\n\t\t}\n\t\t*objflags |= CONTIGUOUS;\n\t\tif (nd > 1) *objflags &= ~FORTRAN;\n\t\telse *objflags |= FORTRAN;\n\t}\n\treturn itemsize;\n}\n\n\t\nstatic PyObject *\nPyArray_New(PyTypeObject *subtype, int nd, intp *dims, int type_num,\n intp *strides, char *data, int itemsize, int flags,\n\t PyObject *obj)\n{\n\tPyArrayObject *self;\n\tPyArray_Descr *descr;\n\tregister int i;\n\tintp sd, temp=-1;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\tif (descr == NULL) return NULL;\n\n\tif (nd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"number of dimensions must be >=0\");\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 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\treturn NULL;\n\t\t}\n\t}\n\t\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) return NULL;\t\n\tself->descr = descr;\n\tself->dimensions = 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\n\tif (PyTypeNum_ISFLEXIBLE(type_num)) {\n\t\tif (itemsize < 1) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"type must provide an itemsize\");\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn NULL;\n\t\t}\n\t\tself->itemsize = itemsize;\n\t\t/* Guarantee that these kind of arrays are never byteswapped\n\t\t unknowingly. \n\t\t*/\n\t\tif (type_num != PyArray_UNICODE)\n\t\t\tself->flags |= NOTSWAPPED;\n\t}\n\telse self->itemsize = descr->elsize; \n\t\t\n\tsd = self->itemsize;\n\t\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn PyErr_NoMemory();\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\tPyDimMem_FREE(self->dimensions);\n\t\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\t\treturn NULL;\n\t\t\t}\t\t\t\t\n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t}\n \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 (a.data) doesn't work\n\t\t as it should. */\n\n\t\tif (sd==0) sd = sizeof(intp);\n\n\t\tif ((data = PyDataMem_NEW(sd))==NULL) {\n\t\t\tPyDimMem_FREE(self->dimensions);\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn PyErr_NoMemory();\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\n\t\t/* It is bad to have unitialized OBJECT pointers */\n\t\t/* We shouldn't need to check for the OBJECT Letter\n\t\t but perhaps it's best. */\n\t\tif (type_num == PyArray_OBJECT || \\\n\t\t type_num == PyArray_OBJECTLTR) {\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\tself->nd = nd;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\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;\n\t\tif (temp==-1) { /* 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\tres = PyObject_CallMethod((PyObject *)self, \n\t\t\t\t\t \"__array_finalize__\",\n\t\t\t\t\t \"O\", obj);\n\t\tif (res == NULL) {\n\t\t\tPyDimMem_FREE(self->dimensions);\n\t\t\tself->ob_type->tp_free((PyObject *)self);\n\t\t\treturn NULL;\n\t\t}\n\t\telse Py_DECREF(res);\n\t}\n\n\treturn (PyObject *)self;\n}\n\n\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\n newsize = PyArray_MultiplyList(new_dimensions, new_nd);\n\n if (newsize == 0) {\n PyErr_SetString(PyExc_ValueError, \n \"newsize is zero; cannot delete an array \"\\\n \"in this way\");\n return NULL;\n }\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 = (((PyObject *)self)->ob_refcnt);\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\n\t\t/* Reallocate space if needed */\n\t\tnew_data = PyDataMem_RENEW(self->data, \n\t\t\t\t\t newsize*(self->itemsize));\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->itemsize;\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->itemsize;\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 */\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; idataptr, fromptr, itemsize);\n\t\t\tPyArray_ITER_NEXT(iter);\n\t\t}\n\n\t\tPy_DECREF(iter);\n\t\tPy_DECREF(behaved);\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\", \"strides\", \n \"swap\", \"fortran\", NULL};\n\tint itemsize = 0;\n\tPyArray_Typecode typecode = {PyArray_NOTYPE, 0, 0};\n\tint type_num = PyArray_NOTYPE;\n PyArray_Dims dims = {NULL, 0};\n PyArray_Dims strides = {NULL, 0};\n PyArray_Chunk buffer;\n\tint fortran = 0;\n int swapped = 0;\n\tPyArrayObject *ret;\n\n\tbuffer.ptr = NULL; \n /* Usually called with shape and type\n but can also be called with buffer, strides, and swapped info\n */\n\n\t/* For now, let's just use this to create an empty, contiguous \n\t array of a specific type and shape. \n\t*/\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&O&ii\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &dims, \n PyArray_TypecodeConverter,\n\t\t\t\t\t &typecode, \n PyArray_BufferConverter,\n &buffer,\n &PyArray_IntpConverter, \n &strides,\n &swapped, &fortran)) \n\t\treturn NULL;\n\t\n if (typecode.type_num ==PyArray_NOTYPE) {\n\t\ttypecode.type_num = PyArray_DOUBLE;\n\t\ttypecode.itemsize = sizeof(double);\n\t}\n\ttype_num = typecode.type_num;\n\titemsize = typecode.itemsize;\n\n\n if (dims.ptr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"need to give a \"\\\n \"valid shape as the first argument\");\n goto fail;\n }\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)PyArray_New(subtype, (int)dims.len, \n dims.ptr, type_num,\n NULL, NULL, itemsize, \n fortran, NULL);\n \n if (ret == NULL) goto fail;\n if (type_num == PyArray_OBJECT) { /* place Py_None */\n PyArray_FillObjectArray(ret, Py_None);\n }\n }\n else { /* buffer given -- use it */\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = buffer.len / itemsize;\n }\n else if (buffer.len < itemsize* \\\n PyArray_MultiplyList(dims.ptr, dims.len)) {\n PyErr_SetString(PyExc_TypeError, \n \"buffer is too small for \" \\\n \"requested array\");\n goto fail;\n }\n if (strides.ptr != NULL) {\n\t\t\tif (strides.len != dims.len) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides, if given, must be \"\\\n\t\t\t\t\t\t\"the same length as shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CheckStrides(itemsize, strides.len, \n\t\t\t\t\t\t buffer.len,\n\t\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides is incompatible \"\\\n\t\t\t\t\t\t\"with shape of requested\"\\\n\t\t\t\t\t\t\"array and size of buffer\");\n\t\t\t\tgoto fail;\n\t\t\t}\n }\n if (type_num == PyArray_OBJECT) {\n PyErr_SetString(PyExc_TypeError, \"cannot construct \"\\\n \"an object array from buffer data\");\n goto fail;\n }\n /* get writeable and aligned */\n if (fortran) buffer.flags |= FORTRAN;\n if (!(swapped)) buffer.flags |= NOTSWAPPED;\n ret = (PyArrayObject *)PyArray_New(subtype, dims.len, \n dims.ptr, type_num,\n strides.ptr,\n (char *)buffer.ptr, \n itemsize, \n buffer.flags, NULL); \n if (ret == 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 PyArray_Return(ret);\n \n fail:\n if (dims.ptr) PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return NULL;\n}\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 static PyObject *module=NULL;\n\n if (module==NULL) {\n module = PyImport_ImportModule(\"scipy.base._internal\");\n if (module == NULL) return NULL;\n }\n return PyObject_CallMethod(module, \"flagsobj\", \"Oii\", \n self, self->flags, 0);\n}\n\n/*\nstatic int\narray_flags_set(PyArrayObject *self, PyObject *obj) \n{\n\tint flagback = self->flags;\n\n if (PyDict_Check(obj)) {\n PyObject *new;\n\t\tnew = PyDict_GetItemString(obj, \"ALIGNED\");\n\t\tif (new) {\n\t\t\tif (PyObject_Not(new)) self->flags &= ~ALIGNED;\n\t\t\telse if (_IsAligned(self)) self->flags |= ALIGNED;\n\t\t\telse {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"cannot set aligned flag of \" \\\n\t\t\t\t\t\t\"mis-aligned array to True\");\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t}\n new = PyDict_GetItemString(obj, \"UPDATEIFCOPY\");\n if (new) {\n if (PyObject_Not(new)) {\n self->flags &= ~UPDATEIFCOPY;\n Py_DECREF(self->base);\n self->base = NULL;\n }\n else {\n\t\t\t\tself->flags = flagback;\n PyErr_SetString(PyExc_ValueError, \n \"cannot set UPDATEIFCOPY \" \\\n \"flag to True\");\n return -1;\n }\n }\n new = PyDict_GetItemString(obj, \"WRITEABLE\");\n if (new) {\n\t\t\tif (PyObject_IsTrue(new)) {\n\t\t\t\tif (_IsWriteable(self)) {\n\t\t\t\t\tself->flags |= WRITEABLE;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tself->flags = flagback;\n\t\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\t\"cannot set \"\t\\\n\t\t\t\t\t\t\t\"WRITEABLE \"\t\\\n\t\t\t\t\t\t\t\"flag to True of \"\\\n\t\t\t\t\t\t\t\"this array \");\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n else\n self->flags &= ~WRITEABLE;\n }\n new = PyDict_GetItemString(obj, \"NOTSWAPPED\");\n if (new) {\n if (PyObject_IsTrue(new))\n self->flags |= NOTSWAPPED;\n else {\n self->flags &= ~NOTSWAPPED;\n\t\t\t}\n\t\t}\n return 0;\n }\n PyErr_SetString(PyExc_ValueError, \n \"object must be a dictionary\");\n return -1;\n}\n*/\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\tif (!PyTuple_Check(val)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"shape must be a tuple\");\n\t\treturn -1;\n\t}\n\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\n\t\n\tif (self->nd > 0) { /* Free old dimensions and strides */\n\t\tPyDimMem_FREE(self->dimensions);\n\t}\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;\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\treturn -1;\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->itemsize;\n\t\n\tif (!PyArray_CheckStrides(self->itemsize, self->nd, numbytes, \n\t\t\t\t self->dimensions, newstrides.ptr)) {\n\t\tPyErr_SetString(PyExc_ValueError, \"strides is not \"\\\n\t\t\t\t\"compatible with available memory\");\n\t\treturn -1;\n\t}\n\tmemcpy(self->strides, newstrides.ptr, sizeof(intp)*newstrides.len);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\treturn 0;\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->itemsize);\n}\n\nstatic PyObject *\narray_size_get(PyArrayObject *self)\n{\n\tlonglong size=PyArray_SIZE(self);\n\tif (size > MAX_INT || size < MIN_INT)\n\t\treturn PyLong_FromLongLong(size);\n\telse \n\t\treturn PyInt_FromLong((long) size);\n}\n\n\nstatic PyObject *\narray_typechar_get(PyArrayObject *self)\n{\n\tif PyArray_ISFLEXIBLE(self) \n\t\treturn PyString_FromFormat(\"%c%d\", (self->descr->type),\n\t\t\t\t\t self->itemsize);\n\telse \n\t\treturn PyString_FromStringAndSize(&(self->descr->type), 1);\n}\n\nstatic PyObject *\narray_typestr_get(PyArrayObject *self)\n{\n\tstatic char endians[] = \"<>\";\n\tchar endian;\n\tint which;\n\tunsigned long val = 1;\n\tchar *s;\n\tchar basic_=self->descr->kind;\n\n\ts = (char *)&val; /* s[0] == 0 implies big-endian */\n\twhich = (PyArray_ISNOTSWAPPED(self) ? 0 : 1);\n\tif (s[0] == 0) which = 1 - which;\n\tendian = endians[which]; \n\t\n\tif ((basic_==PyArray_VOIDLTR) || (basic_==PyArray_STRINGLTR) || \\\n\t (basic_==PyArray_OBJECTLTR) || (self->itemsize == 1))\n\t\treturn PyString_FromFormat(\"|%c%d\", basic_, self->itemsize);\n\telse\n\t\treturn PyString_FromFormat(\"%c%c%d\", endian, basic_,\n\t\t\t\t\t self->itemsize);\n}\n\nstatic PyObject *\narray_descr_get(PyArrayObject *self)\n{\n\tPyObject *res;\n\tPyObject *dobj;\n\n\t/* hand this off to the typeobject */\n\t/* or give default */\n\tif (PyArray_ISUSERDEF(self)) {\n\t\tres = PyObject_GetAttrString((PyObject *)self->descr->typeobj, \n\t\t\t\t\t \"__array_descr__\");\n\t\tif (res) return res;\n\t\tPyErr_Clear();\n\t}\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\n\nstatic PyObject *\narray_type_get(PyArrayObject *self)\n{\n\treturn PyArray_TypeObjectFromType(self->descr->type_num);\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*/\n\nstatic int\narray_type_set(PyArrayObject *self, PyObject *arg)\n{\n PyArray_Typecode newtype = {PyArray_NOTYPE, 0, 0};\n intp newdim;\n int index;\n char *msg = \"new type not compatible with array.\";\n\n if ((PyArray_TypecodeConverter(arg, &newtype) < 0) ||\n newtype.type_num == PyArray_NOTYPE) {\n PyErr_SetString(PyExc_TypeError, \"invalid type for array\");\n return -1;\n }\n if (!(PyArray_ISONESEGMENT(self) ||\t\t\\\n\t (newtype.itemsize != self->itemsize))) {\n PyErr_SetString(PyExc_ValueError, msg);\n return -1; \n }\n\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\n if (newtype.itemsize < self->itemsize) {\n /* if it is compatible increase the size of the dimension\n at end (or at the front for FORTRAN)\n */\n if (self->itemsize % newtype.itemsize != 0) {\n PyErr_SetString(PyExc_ValueError, msg);\n return -1;\n }\n newdim = self->itemsize / newtype.itemsize;\n\t\tself->dimensions[index] *= newdim;\n self->strides[index] = newtype.itemsize;\n\t}\n \n else if (newtype.itemsize > self->itemsize) {\n \n /* Determine if last (or first if FORTRAN) dimension\n is compatible */\n\n\t\tnewdim = self->dimensions[index] * self->itemsize;\n if ((newdim % newtype.itemsize) != 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, msg);\n return -1;\n }\n\t\t\n self->dimensions[index] = newdim / newtype.itemsize;\n self->strides[index] = newtype.itemsize;\n\t\t\n }\n\t\n \n /* fall through -- adjust type*/\n\n self->descr = PyArray_DescrFromType(newtype.type_num);\n self->itemsize = newtype.itemsize;\n PyArray_UpdateFlags(self, ALIGNED);\n return 0;\n\n}\n\n\n\nstatic PyObject *\narray_base_get(PyArrayObject *self)\n{\n\tif (self->base == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\telse {\n\t\tPy_INCREF(self->base);\n\t\treturn self->base;\n\t}\n}\n\n\nstatic PyObject *\narray_real_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *)ret;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n}\n\n\nstatic int\narray_real_set(PyArrayObject *self, PyObject *val)\n{\n\tPyArrayObject *ret;\n\tPyArrayObject *new;\n\tint rint;\n\n\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0);\n\tif (new == NULL) return -1;\n\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) 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\treturn rint;\n}\n\nstatic PyObject *\narray_imag_get(PyArrayObject *self)\n{\t\n\tPyArrayObject *ret;\n\tint itemsize;\n\tint typenum;\n PyArray_Typecode type;\n\t\n\ttype.type_num = self->descr->type_num;\n\ttype.itemsize = self->itemsize;\n\ttype.fortran = PyArray_ISFORTRAN(self);\n\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\titemsize = self->itemsize >> 1;\n\t\ttypenum = self->descr->type_num - PyArray_NUM_FLOATTYPE;\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 typenum,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data + itemsize,\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\tret = (PyArrayObject *)PyArray_Zeros(self->nd, \n\t\t\t\t\t\t self->dimensions, &type);\n\t\tret->flags &= ~WRITEABLE;\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic int\narray_imag_set(PyArrayObject *self, PyObject *val)\n{\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyArrayObject *ret;\n\t\tPyArrayObject *new;\n\t\tint rint;\n\n\t\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0); \n\t\tif (new == NULL) return -1;\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides+ \\\n\t\t\t\t\t\t (self->itemsize >> 1) ,\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) {\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_Typecode typecode;\n int swap;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode.type_num = self->descr->type_num;\n\ttypecode.itemsize = self->itemsize;\n\ttypecode.fortran = PyArray_ISFORTRAN(self);\n\t\n\tarr = PyArray_FromAny(val, &typecode, \n\t\t\t 0, 0, FORCECAST);\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->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 copyswap(selfit->dataptr, NULL, swap, \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->itemsize);\n copyswap(selfit->dataptr, NULL, swap, self->itemsize);\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\t{\"base\",\n\t (getter)array_base_get,\n\t NULL,\n\t \"base object\"},\n {\"dtype\", \n\t (getter)array_type_get, \n\t (setter)array_type_set,\n\t \"get array type class\"},\n\t{\"dtypechar\",\n\t (getter)array_typechar_get,\n\t NULL,\n\t \"get array type character code\"},\n\t{\"dtypestr\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"get array type string\"},\n {\"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_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\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\n\nstatic char Arraytype__doc__[] = \n \"A array object represents a multidimensional, homogeneous array\\n\"\n\t\" of basic values. Arrays are sequence, mapping and numeric\\n\"\n\t\" objects. More information is available in the scipy module and\\n\"\n\t\" by looking at the methods and attributes of an array.\";\n\nstatic PyTypeObject PyBigArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"scipy.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 \n offsetof(PyArrayObject, weakreflist), /*tp_weaklistoffset */\n\n /* Iterator support (use standard) */\n\n (getiterfunc)0, \t\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 0,\t /* tp_alloc */ \n (newfunc)array_new,\t\t /* tp_new */\n 0,\t \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 \"scipy.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) \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 if (PySequence_Length(s) == 0) \n\t\treturn 1;\n\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);\n\t\tif(d >= 0) d++;\n\t}\n Py_DECREF(e);\n return d;\n}\n\nstatic int\ndiscover_itemsize(PyObject *s, int nd, int *itemsize) \n{\n\tint n, r, i;\n\tPyObject *e;\n\t\n\tn = PyObject_Length(s);\n\n\tif ((nd == 0) || PyString_Check(s) ||\t\t\\\n\t PyUnicode_Check(s) || PyBuffer_Check(s)) {\n\t\tif PyUnicode_Check(s) \n\t\t\t*itemsize = MAX(*itemsize, sizeof(Py_UNICODE)*n);\n\t\telse\n\t\t\t*itemsize = MAX(*itemsize, n);\n\t\treturn 0;\n\t}\n\tfor (i=0; i n_lower) n_lower = d[1];\n }\n d[1] = n_lower;\n\t\n return 0;\n}\n\nstatic void\n_array_small_type(int chktype, int mintype, int chksize, int minsize, \n\t\t PyArray_Typecode *outtype)\n{\n\touttype->type_num = MAX(chktype, mintype);\n\tif (PyTypeNum_ISFLEXIBLE(outtype->type_num) &&\t\\\n\t PyTypeNum_ISFLEXIBLE(mintype)) {\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 == PyArray_STRING) {\n\t\t\touttype->itemsize = MAX(chksize, 2*minsize);\n\t\t}\n\t\telse {\n\t\t\touttype->itemsize = MAX(chksize, minsize);\n\t\t}\n\t}\n\telse {\n\t\touttype->itemsize = chksize;\n\t}\n\treturn;\t\n}\n\nstatic void\n_array_find_type(PyObject *op, PyArray_Typecode *minitype, \n\t\t PyArray_Typecode *outtype, int max)\n{\n int l;\n PyObject *ip;\n\tint chktype=0;\n\tint chksize=0;\n\tint mintype, minsize;\n\n\tif (minitype == NULL) {\n\t\tmintype = PyArray_BOOL;\n\t\tminsize = sizeof(Bool);\n\t}\n\telse {\n\t\tmintype = minitype->type_num;\n\t\tminsize = minitype->itemsize;\n\t}\n\n \n if (max < 0 || mintype == -1) goto deflt;\n\t\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_TYPE(op);\n\t\tchksize = PyArray_ITEMSIZE(op);\n\t\tgoto finish;\n\t}\n\t\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tPyArray_TypecodeFromScalar(op, outtype);\n\t\tchktype = outtype->type_num;\n\t\tchksize = outtype->itemsize;\n\t\tgoto finish;\n\t}\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_TYPE(ip);\n\t\t\tchksize = PyArray_ITEMSIZE(ip);\n\t\t\tgoto finish;\n\t\t}\n } \n\t\n\tif (PyObject_HasAttrString(op, \"__array_typestr__\")) {\n\t\tint swap=0, res;\n\t\tip = PyObject_GetAttrString(op, \"__array_typestr__\");\n\t\tif (ip && PyString_Check(ip)) {\n\t\t\tres = _array_typecode_fromstr(PyString_AS_STRING(ip), \n\t\t\t\t\t\t &swap, outtype); \n\t\t\tif (res >= 0) {\n\t\t\t\tPy_DECREF(ip);\n\t\t\t\tchktype = outtype->type_num;\n\t\t\t\tchksize = outtype->itemsize;\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t}\n\t\tPy_XDECREF(ip);\n\t}\n\n if (PyString_Check(op)) {\n\t\tchktype = PyArray_STRING;\n\t\tchksize = PyString_GET_SIZE(op);\n\t\tgoto finish;\n }\n\n\tif (PyUnicode_Check(op)) {\n\t\tchktype = PyArray_UNICODE;\n\t\tchksize = PyUnicode_GET_DATA_SIZE(op);\n\t\tgoto finish;\n\t}\n\n\tif (PyBuffer_Check(op)) {\n\t\tchktype = PyArray_VOID;\n\t\tchksize = op->ob_type->tp_as_sequence->sq_length(op);\n\t\tPyErr_Clear();\n\t\tgoto finish;\n\t}\n\n\tif (PyInstance_Check(op)) goto deflt;\n\t\n if (PySequence_Check(op)) {\n\t\tPyArray_Typecode newtype;\n\t\tnewtype.type_num = mintype;\n\t\tnewtype.itemsize = minsize;\n\t\tnewtype.fortran = 0;\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 && mintype == 0) {\n\t\t\tnewtype.type_num = PyArray_INTP;\n\t\t\tnewtype.itemsize = sizeof(intp);\n\t\t}\n while (--l >= 0) {\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\t_array_find_type(ip, &newtype, outtype, max-1);\n\t\t\t_array_small_type(outtype->type_num,\n\t\t\t\t\t newtype.type_num, \n\t\t\t\t\t outtype->itemsize,\n\t\t\t\t\t newtype.itemsize,\n\t\t\t\t\t &newtype);\n Py_DECREF(ip);\n }\n\t\tchktype = newtype.type_num;\n\t\tchksize = newtype.itemsize;\n\t\tgoto finish;\n }\n\t\n\tif (PyBool_Check(op)) {\n\t\tchktype = PyArray_BOOL;\n\t\tchksize = sizeof(Bool);\n\t\tgoto finish;\t\t\n\t}\n else if (PyInt_Check(op)) {\n\t\tchktype = PyArray_LONG;\n\t\tchksize = sizeof(long);\n\t\tgoto finish;\n } else if (PyFloat_Check(op)) {\n\t\tchktype = PyArray_DOUBLE;\n\t\tchksize = sizeof(double);\n\t\tgoto finish;\n\t} else if (PyComplex_Check(op)) {\n\t\tchktype = PyArray_CDOUBLE;\n\t\tchksize = sizeof(cdouble);\n\t\tgoto finish;\n\t}\n\n deflt:\n\tchktype = PyArray_OBJECT;\n\tchksize = sizeof(void *);\n\n finish:\n\t_array_small_type(chktype, mintype, chksize, minsize, \n\t\t\t outtype);\n\treturn;\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\" */ \nstatic PyObject *\nArray_FromScalar(PyObject *op, PyArray_Typecode *typecode) \n{\n PyArrayObject *ret;\n\tint itemsize; \n\tint type;\n\t\n\titemsize = typecode->itemsize;\n\ttype = typecode->type_num;\n\n\tif (itemsize == 0 && PyTypeNum_ISFLEXIBLE(type)) {\n\t\titemsize = PyObject_Length(op);\n\t}\n\n\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, 0, NULL, type,\n\t\t\t\t\t NULL, NULL, itemsize, 0, NULL);\n\n\tif (ret == NULL) return NULL;\n\n ret->descr->setitem(op, ret->data, ret);\n\t\n if (PyErr_Occurred()) {\n array_dealloc(ret);\n return NULL;\n } else {\n return (PyObject *)ret;\n }\n}\n\n\nstatic PyObject *\nArray_FromSequence(PyObject *s, PyArray_Typecode *typecode, int min_depth, \n\t\t int max_depth)\n{\n PyArrayObject *r;\n int nd;\n\tintp *d;\n\tint stop_at_string;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->itemsize;\n\t\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 if (!((nd=discover_depth(s, MAX_DIMS+1, stop_at_string)) > 0)) {\n\t\tif (nd==0)\n\t\t\treturn Array_FromScalar(s, typecode);\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid input sequence\");\n return NULL;\n }\n\t\n if ((max_depth && nd > max_depth) ||\t\\\n\t (min_depth && nd < min_depth)) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid number of dimensions\");\n return NULL;\n }\n\t\n\tif ((d=PyDimMem_NEW(nd)) == NULL) {\n\t\treturn PyErr_NoMemory();\n }\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) {\n\t\tPyDimMem_FREE(d);\n\t\treturn NULL;\n\t}\n\tif (itemsize == 0 && PyTypeNum_ISFLEXIBLE(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) {\n\t\t\tPyDimMem_FREE(d);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n r=(PyArrayObject*)PyArray_New(&PyArray_Type, nd, d, \n\t\t\t\t type, NULL, NULL,\n\t\t\t\t itemsize, \n\t\t\t\t typecode->fortran, NULL);\n\n PyDimMem_FREE(d);\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\n\nstatic int \nPyArray_ValidType(int type) \n{\n\tPyArray_Descr *descr;\n\t\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr==NULL) return 0;\n\treturn 1;\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->itemsize;\n\tint nels = PyArray_BUFSIZE;\n\tint el;\n\tint inswap, outswap=0;\n\tint obuf=!PyArray_ISCARRAY(out);\n\tint oelsize = out->itemsize;\n\tPyArray_VectorUnaryFunc *castfunc;\n PyArray_CopySwapFunc *in_csn;\n PyArray_CopySwapFunc *out_csn;\n\tint retval = -1;\n\n\tcastfunc = in->descr->cast[out->descr->type_num];\n in_csn = in->descr->copyswap;\n out_csn = out->descr->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\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\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->itemsize * 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\n/* For backward compatibility */\n\nstatic PyObject *\nPyArray_Cast(PyArrayObject *mp, int type_num) \n{\n\tPyArray_Typecode type;\n\tPyArray_Descr *descr;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\ttype.itemsize = descr->elsize;\n\ttype.type_num = descr->type_num;\n\ttype.fortran = 0;\n\t\n\treturn PyArray_CastToType(mp, &type);\n}\n\nstatic PyObject * \nPyArray_CastToType(PyArrayObject *mp, PyArray_Typecode *at) \n{\n\tPyObject *out;\n\tint ret;\n\n\tif ((mp->descr->type_num == at->type_num) && \\\n\t (at->itemsize==0 || mp->itemsize == at->itemsize) &&\n\t PyArray_ISBEHAVED_RO(mp)) {\n\t\tPy_INCREF(mp);\n\t\treturn (PyObject *)mp;\n\t}\n\t\t\n\tif (at->itemsize == 0) {\n\t\tif (mp->descr->type_num == PyArray_STRING &&\t\\\n\t\t at->type_num == PyArray_UNICODE)\n\t\t\tat->itemsize = mp->itemsize*sizeof(Py_UNICODE);\n\t\tif (mp->descr->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING) \n\t\t\tat->itemsize = mp->itemsize/sizeof(Py_UNICODE);\n\t\tif (at->type_num == PyArray_VOID)\n\t\t\tat->itemsize = mp->itemsize;\n\t}\n\n\tout = PyArray_New(mp->ob_type, mp->nd, \n\t\t\t mp->dimensions, \n\t\t\t at->type_num,\n\t\t\t NULL, NULL, at->itemsize, \n\t\t\t at->fortran, (PyObject *)mp);\n\tif (out == NULL) return NULL;\n\tret = PyArray_CastTo((PyArrayObject *)out, mp);\n\tif (ret != -1) return out;\n\n\tPy_DECREF(out);\n\treturn NULL;\n\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\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\tsimple = ((PyArray_ISCARRAY(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY(mp) && PyArray_ISFARRAY(out)));\n\t\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->itemsize * outsize;\n\t\tintp ncopies = outsize / mpsize;\n\n\t\twhile(ncopies--) {\n\t\t\tinptr = mp->data;\n\t\t\tmp->descr->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\nstatic PyObject *\narray_fromarray(PyArrayObject *arr, PyArray_Typecode *typecode, int flags) \n{\n\t\n\tPyArrayObject *ret=NULL;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->itemsize;\n\tint copy = 0;\n\tint arrflags;\n\tPyArray_Typecode oldtype;\n\tchar *msg = \"cannot copy back to a read-only array\";\n PyTypeObject *subtype;\n\n\toldtype.type_num = PyArray_TYPE(arr);\n\toldtype.itemsize = PyArray_ITEMSIZE(arr);\n\toldtype.fortran = 0;\n\n subtype = arr->ob_type;\n\n\tif (type == PyArray_NOTYPE) type = arr->descr->type_num;\n\tif (itemsize == 0) itemsize = arr->itemsize;\n\ttypecode->type_num = type;\n\ttypecode->itemsize = itemsize;\n\n\t/* Don't copy if sizes are compatible */\n\tif (PyArray_EquivalentTypes(&oldtype, typecode)) {\n\t\tarrflags = arr->flags;\n\n\t\tcopy = (flags & ENSURECOPY) || \\\n\t\t\t((flags & CONTIGUOUS) && (!(arrflags & CONTIGUOUS))) \\\n\t\t\t|| (PyArray_ITEMSIZE(arr) != itemsize) || \\\n\t\t\t((flags & ALIGNED) && (!(arrflags & ALIGNED))) || \\\n\t\t\t((flags & NOTSWAPPED) && (!(arrflags & NOTSWAPPED))) \\\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 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_New(subtype, \n\t\t\t\t\t arr->nd, \n\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t type,\n\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t itemsize,\n\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t (PyObject *)arr);\n\t\t\tif (PyArray_CopyInto(ret, arr) == -1) 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 ret = (PyArrayObject *) \\\n PyArray_New(&PyArray_Type,\n arr->nd,\n arr->dimensions,\n arr->descr->type_num,\n arr->strides,\n arr->data,\n arr->itemsize,\n arr->flags,NULL);\n if (ret == NULL) return NULL;\n ret->base = (PyObject *)arr;\n ret->flags &= ~UPDATEIFCOPY;\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_CanCastSafely(PyArray_TYPE(arr), type)) {\n if ((flags & UPDATEIFCOPY) && \\\n (!PyArray_ISWRITEABLE(arr))) {\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_New(subtype, arr->nd,\n arr->dimensions, typecode->type_num,\n NULL, NULL, typecode->itemsize,\n typecode->fortran, \n (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\nstatic int\n_array_typecode_fromstr(char *str, int *swap, PyArray_Typecode *type)\n{\n int type_num;\n char typechar;\n int size;\n unsigned long number = 1;\n char *s;\n char msg[] = \"unsupported typestring\";\n \n s = (char *)&number; /* s[0] == 0 implies big-endian */\n\n *swap = 0;\n\n if (str[0] == '<' || str[0] == '>') {\n\tif ((str[0] == '<') && (s[0] == 0)) *swap = 1;\n\telse if ((str[0] == '>') && (s[0] != 0)) *swap = 1;\n }\n str += 1;\n \n#define _MY_FAIL {\t\t\t\t \\\n\t PyErr_SetString(PyExc_ValueError, msg); \\\n\t return -1;\t\t\t \\\n }\t\t\n\n typechar = str[0];\n size = atoi(str + 1);\n switch (typechar) {\n case 'b':\n\t if (size == sizeof(Bool))\n\t\t type_num = PyArray_BOOL;\t \n\t else _MY_FAIL \n\t break;\t\t \n case 'u':\n if (size == sizeof(uintp))\n type_num = PyArray_UINTP;\n\t else if (size == sizeof(char))\n\t\t type_num = PyArray_UBYTE;\n\t else if (size == sizeof(short)) \n\t\t type_num = PyArray_USHORT;\n\t else if (size == sizeof(int)) \n\t\t type_num = PyArray_UINT;\n\t else if (size == sizeof(ulong)) \n\t\t type_num = PyArray_ULONG;\n\t else if (size == sizeof(ulonglong))\n\t\t type_num = PyArray_ULONGLONG;\n\t else _MY_FAIL\n\t break;\t\t \n case 'i':\n if (size == sizeof(intp))\n type_num = PyArray_INTP;\n\t else if (size == sizeof(char)) \n\t\t type_num = PyArray_BYTE;\n\t else if (size == sizeof(short)) \n\t\t type_num = PyArray_SHORT;\n\t else if (size == sizeof(int))\n\t\t type_num = PyArray_INT;\n\t else if (size == sizeof(long)) \n\t\t type_num = PyArray_LONG;\n\t else if (size == sizeof(longlong))\n\t\t type_num = PyArray_LONGLONG;\n\t else _MY_FAIL\n\t break;\t\t \n case 'f':\n\t if (size == sizeof(float))\n\t\t type_num = PyArray_FLOAT;\n\t else if (size == sizeof(double))\n\t\t type_num = PyArray_DOUBLE;\n\t else if (size == sizeof(longdouble))\n\t\t type_num = PyArray_LONGDOUBLE;\n\t else _MY_FAIL\n\t break;\n case 'c':\n\t if (size == sizeof(float)*2)\n\t\t type_num = PyArray_CFLOAT;\n\t else if (size == sizeof(double)*2)\n\t\t type_num = PyArray_CDOUBLE;\n\t else if (size == sizeof(longdouble)*2)\n\t\t type_num = PyArray_CLONGDOUBLE;\n\t else _MY_FAIL\n\t break;\n case 'O':\n\t if (size == sizeof(PyObject *))\n\t\t type_num = PyArray_OBJECT;\n\t else _MY_FAIL\n\t break;\n case 'S':\n\t type_num = PyArray_STRING;\n\t break;\n case 'U':\n\t type_num = PyArray_UNICODE;\n\t size *= sizeof(Py_UNICODE);\n\t break;\t \n case 'V':\n\t type_num = PyArray_VOID;\n\t break;\n default:\n\t _MY_FAIL\n }\n\n#undef _MY_FAIL\n\n type->type_num = type_num;\n type->itemsize = size;\n type->fortran = 0;\n return 0;\n}\n\nstatic PyObject *\narray_frominterface(PyObject *input, PyArray_Typecode *intype, int flags)\n{\n\tPyObject *attr=NULL, *item=NULL, *r;\n\tPyArrayObject *ret=NULL;\n\tPyArray_Typecode type;\n\tchar *data;\n\tint buffer_len;\n\tint res, i, n;\n\tintp dims[MAX_DIMS], strides[MAX_DIMS];\n\tint swap;\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\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) {Py_XDECREF(attr); return NULL;}\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t}\n\telse {\n\t\tif (PyTuple_GET_SIZE(attr) != 2) {\n\t\t\tPy_DECREF(attr);\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\treturn NULL;\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\tPy_DECREF(attr);\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\treturn NULL;\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 = PyObject_GetAttrString(input, \"__array_typestr__\");\n\tif (!PyString_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_typestr__ must be a string\");\n\t\tPy_DECREF(attr);\n\t\treturn NULL;\t\n\t}\n\tres = _array_typecode_fromstr(PyString_AS_STRING(attr), &swap, &type);\n\tPy_DECREF(attr);\n\tif (res < 0) return NULL;\n \n\tattr = PyObject_GetAttrString(input, \"__array_shape__\");\n\tif (!PyTuple_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_shape__ must be a tuple\");\n\t\tPy_DECREF(attr);\n\t\treturn NULL;\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\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\treturn NULL;\n\t\t}\n\t\tfor (i=0; istrides, strides, n*sizeof(intp));\n\t}\n\n\tif (swap) {\n\t\tPyObject *tmp;\n tmp = PyArray_Byteswap(ret, TRUE);\n\t\tPy_DECREF(tmp);\n\t}\n\n\tPyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n\tr = array_fromarray(ret, intype, flags);\n\tPy_DECREF(ret);\n\treturn r;\n}\n\nstatic PyObject *\narray_fromattr(PyObject *op, PyArray_Typecode *typecode, int flags) \n{\n PyObject *new, *r;\n\t \n if (typecode->type_num == PyArray_NOTYPE) {\n new = PyObject_CallMethod(op, \"__array__\", NULL);\n } else {\n\t\tPyArray_Descr *descr;\n\t\tPyObject *obj;\n\n\t\tdescr = PyArray_DescrFromType(typecode->type_num);\n\t\tif (PyTypeNum_ISFLEXIBLE(typecode->type_num)) {\n\t\t\tobj = PyString_FromFormat(\"%c%d\", descr->type,\n\t\t\t\t\t\t typecode->itemsize);\n\t\t}\n\t\telse { \n\t\t\tobj = (PyObject *)(descr->typeobj); Py_INCREF(obj);\n\t\t}\n\t\tnew = PyObject_CallMethod(op, \"__array__\", \"N\", obj);\n }\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 r = array_fromarray((PyArrayObject *)new, typecode, flags);\n Py_DECREF(new);\n return r;\n} \n\n\nstatic PyObject *\narray_fromobject(PyObject *op, PyArray_Typecode *typecode, int min_depth, \n\t\t int max_depth, int flags) \n{\n /* This is the main code to make a NumPy array from a Python\n Object. It is called from lot's of different places which\n is why there are so many checks. The comments try to\n explain some of the checks. */\n\n\tint type = typecode->type_num;\n PyObject *r=NULL;\n\n\t/* Is input object already an array? */\n\t/* This is where the flags are used */\n if (PyArray_Check(op)) \n\t\tr = array_fromarray((PyArrayObject *)op, typecode, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, typecode);\n\t}\n\telse if (PyObject_HasAttrString(op, \"__array__\")) {\n\t\t/* Code that returns the object to convert for a non\n\t\t multiarray input object from the __array__ attribute of the\n\t\t object. */\n r = array_fromattr(op, typecode, flags);\n\t}\n\telse if (PyObject_HasAttrString(op, \"__array_shape__\") &&\n\t\t PyObject_HasAttrString(op, \"__array_typestr__\")) {\n\t\tr = array_frominterface(op, typecode, flags);\n\t}\n\telse {\n\t\tif (type == PyArray_NOTYPE) {\n\t\t\t_array_find_type(op, NULL, typecode, MAX_DIMS);\n\t\t}\n\t\tif (PySequence_Check(op))\n\t\t\tr = Array_FromSequence(op, typecode, \n\t\t\t\t\t min_depth, max_depth);\n\t\telse\n\t\t\tr = Array_FromScalar(op, typecode);\n\t}\n\n /* If we didn't succed return NULL */\n if (r == NULL) return NULL;\n\t\n\t/* Be sure we succeed here */\n\t\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"internal error: array_fromobject \"\\\n\t\t\t\t\"not producing an array\");\n\t\tPy_DECREF(r);\n return NULL;\n }\n\n if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {\n Py_DECREF(r);\n PyErr_SetString(PyExc_ValueError, \n \"object of too small depth for desired array\");\n return NULL;\n }\n if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {\n Py_DECREF(r);\n PyErr_SetString(PyExc_ValueError, \n \"object too deep for desired array\");\n return NULL;\n }\n return r;\n}\n\nstatic void\nPyArray_ArrayType(PyObject *op, PyArray_Typecode *intype, \n\t\t PyArray_Typecode *outtype) \n{\n\t_array_find_type(op, intype, outtype, MAX_DIMS);\n\treturn;\n}\n\nstatic int \nPyArray_ObjectType(PyObject *op, int minimum_type) \n{\n\tPyArray_Typecode intype, outtype;\n\tintype.type_num = minimum_type;\n\t_array_find_type(op, &intype, &outtype, MAX_DIMS);\n\treturn outtype.type_num;\n}\n\n\n\n/* flags is any of \n CONTIGUOUS, \n FORTRAN, (or set typecode->fortran=1)\n ALIGNED, \n NOTSWAPPED, \n WRITEABLE, \n ENSURECOPY, \n UPDATEIFCOPY,\n FORCECAST,\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, NOTSWAPPED, and WRITEABLE\n and therefore it is redundant to include those as well. \n\n BEHAVED_FLAGS == ALIGNED | NOTSWAPPED | WRITEABLE\n BEHAVED_FLAGS_RO == ALIGNED | NOTSWAPPED\n CARRAY_FLAGS = CONTIGUOUS | BEHAVED_FLAGS\n FARRAY_FLAGS = FORTRAN | BEHAVED_FLAGS\n \n By default, the returned array will be a copy of the object, \n (C) contiguous in memory, aligned, notswapped, and writeable.\n \n So CONTIGUOUS | ENSURECOPY passed in means that the returned\n array does not have to be CONTIGUOUS or a COPY but should be\n ALIGNED, NOTSWAPPED and WRITEABLE. \n\n typecode->fortran can be set to request a\n fortran-contiguous array. Fortran arrays are always behaved (aligned, \n notswapped, and writeable) and not (C) CONTIGUOUS. Note that either\n FORTRAN in the flag or typecode->fortran = 1 is enough to request\n a FORTRAN-style array. \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\nstatic PyObject *\nPyArray_FromAny(PyObject *op, PyArray_Typecode *typecode, int min_depth, \n\t\tint max_depth, int requires) \n{\n \tPyArray_Typecode mine = {PyArray_NOTYPE, 0, 0};\n\tPyArray_Typecode *type;\n\t\n\tif (typecode == NULL) type = &mine;\n\telse type = typecode;\n\t\t\n\tif (requires & ENSURECOPY) {\n\t\trequires |= DEFAULT_FLAGS;\n\t}\n\t/* Ensure that type->fortran and flags & FORTRAN are the\n\t same */\n\tif (requires & FORTRAN) typecode->fortran = 1;\n\tif (type->fortran == 1) {\n\t\trequires |= FARRAY_FLAGS;\n\t\tif (min_depth > 2) requires &= ~CONTIGUOUS;\n\t}\n\n\t/* make sure itemsize is not 0 unless warranted. */\n\tif ((type->itemsize == 0) && (type->type_num != PyArray_NOTYPE)) {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(type->type_num);\n\t\tif (descr != NULL) type->itemsize = descr->elsize;\n\t\telse return NULL;\n\t}\n\t\n\treturn array_fromobject(op, type, min_depth, max_depth, \n\t\t\t\trequires);\t\n}\n\n/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0, 0) */\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\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);\n Py_DECREF(op);\n return new;\n}\n\n/* These are all compressed into a single API */\n/* Deprecated calls -- Use PyArray_FromAny */\n\nstatic PyObject *\nPyArray_FromObject(PyObject *op, int type, int min_depth, int max_depth) \n{\n\tPyArray_Typecode typecode = {0, 0, 0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth,\n\t\t\t max_depth, BEHAVED_FLAGS | ENSUREARRAY);\n}\n\nstatic PyObject *\nPyArray_ContiguousFromObject(PyObject *op, int type, int min_depth, \n\t\t\t int max_depth) \n{\n\tPyArray_Typecode typecode = {0, 0, 0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth,\n\t\t\t max_depth, DEFAULT_FLAGS | ENSUREARRAY);\n}\n\nstatic PyObject *\nPyArray_CopyFromObject(PyObject *op, int type, int min_depth, \n\t\t int max_depth) \n{\n\tPyArray_Typecode typecode = {0, 0, 0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth, max_depth,\n\t\t\t ENSURECOPY | ENSUREARRAY);\n}\n\n/* End of deprecated */\n\nstatic PyObject *\nPyArray_ContiguousFromAny(PyObject *op, int type, int min_depth, \n\t\t\t int max_depth)\n{\n\tPyArray_Typecode typecode = {0,0,0};\n\ttypecode.type_num = type;\n return PyArray_FromAny(op, &typecode, min_depth,\n\t\t\t max_depth, DEFAULT_FLAGS);\n}\t\n\nstatic int \nPyArray_CanCastSafely(int fromtype, int totype) \n{\n\tPyArray_Descr *from, *to;\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\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 (to->elsize > from->elsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (to->elsize >= from->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (from->elsize < 8)\n return (to->elsize > from->elsize);\n else\n return (to->elsize >= from->elsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (from->elsize < 8)\n return ((to->elsize >> 1) > from->elsize);\n else\n return ((to->elsize >> 1) >= from->elsize);\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 (to->elsize > from->elsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (to->elsize >= from->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (from->elsize < 8)\n return (to->elsize > from->elsize);\n else\n return (to->elsize >= from->elsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (from->elsize < 8)\n return ((to->elsize >> 1) > from->elsize);\n else\n return ((to->elsize >> 1) >= from->elsize);\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 ((to->elsize >> 1) >= from->elsize);\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\nstatic Bool\nPyArray_CanCastTo(PyArray_Typecode *from, PyArray_Typecode *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->itemsize <= to->itemsize);\n\t\t\t}\n\t\t\telse if (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->itemsize * sizeof(Py_UNICODE)\\\n\t\t\t\t <= to->itemsize);\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->itemsize <= to->itemsize);\n\t\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 scipy's arraymap ****/\n/* and Python's array iterator ***/\n \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 = PyObject_GC_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 PyObject_GC_Track(it);\n return (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 PyObject_GC_UnTrack(it);\n Py_XDECREF(it->ao);\n PyObject_GC_Del(it);\n }\n\nstatic int\narrayiter_traverse(PyArrayIterObject *it, visitproc visit, void *arg)\n{\n if (it->ao != NULL)\n return visit((PyObject *)(it->ao), arg);\n return 0;\n}\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->itemsize;\n\tr = PyArray_New(self->ao->ob_type, 1, &count, \n\t\t\tself->ao->descr->type_num, NULL, NULL,\n\t\t\titemsize, 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->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->itemsize;\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\tr = PyArray_New(self->ao->ob_type, ind->nd, ind->dimensions,\n\t\t\tself->ao->descr->type_num, NULL, \n\t\t\tNULL, self->ao->itemsize, \n\t\t\t0, (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)->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\tint i;\n\tPyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tint 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\t\t\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\n\t/* Tuples 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\tr = PyArray_New(self->ao->ob_type, 1, &ii, \n\t\t\t\t\tself->ao->descr->type_num, NULL, \n\t\t\t\t\tNULL, self->ao->itemsize, 0,\n\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 */\n\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->itemsize;\n\t\tr = PyArray_New(self->ao->ob_type, 1, &n_steps, \n\t\t\t\tself->ao->descr->type_num, NULL, NULL,\n\t\t\t\tsize, 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)->copyswap;\n\t\twhile(n_steps--) {\n copyswap(dptr, self->dataptr, swap, size);\n\t\t\tfor(i=0; i< step_size; i++) \n\t\t\t\tPyArray_ITER_NEXT(self);\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\tif (PyArray_IsScalar(ind, Integer) || PyList_Check(ind)) {\n\t\tobj = PyArray_FromAny(ind, &indtype, 0, 0, FORCECAST);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tr = iter_subscript_Bool(self, (PyArrayObject *)obj);\n\t\t} \n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, &indtype, 0, 0, \n\t\t\t\t\t FORCECAST | BEHAVED_FLAGS);\n\t\t\tif (new==NULL) goto fail;\n\t\t\tobj = new;\n\t\t\tr = iter_subscript_int(self, (PyArrayObject *)obj);\n\t\t}\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\t\"unsupported iterator index\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPy_DECREF(obj);\n\t\treturn r;\n\t}\n\n\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\n fail:\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->itemsize;\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->copyswap;\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(self->dataptr, val->dataptr, swap,\n itemsize);\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t\tPyArray_ITER_NEXT(val);\n\t\tif (val->index==val->size) \n\t\t\tPyArray_ITER_RESET(val);\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_Typecode typecode;\n\tintp num;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\titemsize = typecode.itemsize = self->ao->itemsize;\n\ttypecode.type_num = self->ao->descr->type_num;\n copyswap = self->ao->descr->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\n\nstatic int\niter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val) \n{\n\tint i;\n\tPyObject *arrval=NULL;\n\tPyArrayIterObject *val_it=NULL;\n\tPyArray_Typecode type;\n\tPyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tint swap;\n\tint itemsize;\n\tint start, step_size;\n\tintp n_steps;\n\tPyObject *obj;\n PyArray_CopySwapFunc *copyswap;\n\t\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\ti = iter_ass_subscript(self, ind, val);\n\t\tPy_DECREF(ind);\n\t\treturn i;\n\t}\n\t\n\ttype.type_num = self->ao->descr->type_num;\n\titemsize = type.itemsize = self->ao->itemsize;\n\t\n\tarrval = PyArray_FromAny(val, &type, 0, 0, 0);\n\tif (arrval==NULL) return -1;\n\tval_it = (PyArrayIterObject *)PyArray_IterNew(arrval);\n\tif (val_it==NULL) goto fail;\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\n copyswap = PyArray_DESCR(arrval)->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\tgoto succeed;\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 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 copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, itemsize);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\tgoto succeed;\n\t\t}\n\t\twhile(n_steps--) {\n copyswap(self->dataptr, val_it->dataptr,\n swap, itemsize);\n\t\t\tfor(i=0; i < step_size; i++) \n\t\t\t\tPyArray_ITER_NEXT(self);\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\tgoto succeed;\n\t} \n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tif (PyArray_IsScalar(ind, Integer))\n\t\tobj = PyArray_FromScalar(ind, &indtype);\n\telse if (PyList_Check(ind)) {\n\t\tobj = PyArray_FromAny(ind, &indtype, 0, 0, FORCECAST);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tif (iter_ass_sub_Bool(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto fail;\n\t\t} \n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, &indtype, 0, 0, \n\t\t\t\t\t FORCECAST | BEHAVED_FLAGS);\n\t\t\tif (new==NULL) goto fail;\n\t\t\tPy_DECREF(obj);\n\t\t\tobj = new;\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 fail;\n\t\t}\n\t\telse goto fail;\n\t\tPy_DECREF(obj);\n\t\tgoto succeed;\n\t}\n\n\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\tgoto fail;\n\n succeed:\n\tPy_DECREF(val_it);\n\tPy_DECREF(arrval);\n\treturn 0;\n\n fail:\n\tPy_XDECREF(val_it);\n\tPy_XDECREF(arrval);\n\treturn -1;\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 if (PyArray_ISCONTIGUOUS(it->ao)) {\n r = PyArray_New(it->ao->ob_type, 1, &size, \n\t\t\t\tit->ao->descr->type_num,\n NULL, it->ao->data, it->ao->itemsize, \n\t\t\t\tit->ao->flags,\n (PyObject *)it->ao); \n\t\tif (r==NULL) return NULL;\n }\n else {\n r = PyArray_New(it->ao->ob_type, 1, &size, \n\t\t\t\tit->ao->descr->type_num,\n NULL, NULL, it->ao->itemsize, 0, \n (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\n\nstatic PyTypeObject PyArrayIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"scipy.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 | Py_TPFLAGS_HAVE_GC,/* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)arrayiter_traverse,\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)arrayiter_next,\t\t/* tp_iternext */\n iter_methods,\t\t\t\t/* tp_methods */\n};\n\n/** END of Array Iterator **/\n\n\n\n/*********************** Subscript Array Iterator *************************\n * *\n * This object handles subscript behavior for array objects. *\n * It is an iterator object with a next method *\n * It abstracts the n-dimensional mapping behavior to make the looping *\n * code more understandable (maybe) *\n * and so that indexing can be set up ahead of time *\n */ \n\n/* This checks the args for any fancy indexing objects */\n\n#define SOBJ_NOTFANCY 0 \n#define SOBJ_ISFANCY 1\n#define SOBJ_BADARRAY 2\n#define SOBJ_TOOMANY 3\n#define SOBJ_LISTTUP 4\n\nstatic int\nfancy_indexing_check(PyObject *args)\n{\n\tint i, n;\n\tPyObject *obj;\n\tint retval = SOBJ_NOTFANCY;\n\n\tif (PyTuple_Check(args)) {\n\t\tn = PyTuple_GET_SIZE(args);\n\t\tif (n >= MAX_DIMS) return SOBJ_TOOMANY;\n\t\tfor (i=0; i=MAX_DIMS) return SOBJ_ISFANCY;\n\t\tfor (i=0; i SOBJ_ISFANCY) return retval;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* convert an indexing object to an INTP indexing array iterator\n if possible -- otherwise, it is a Slice or Ellipsis object\n and has to be interpreted on bind to a particular \n array so leave it NULL for now.\n */\nstatic int\n_convert_obj(PyObject *obj, PyArrayIterObject **iter)\n{\n\tPyArray_Typecode indtype = {PyArray_INTP, 0, 0};\n\tPyObject *arr;\n\n\tif (PySlice_Check(obj) || (obj == Py_Ellipsis))\n\t\t*iter = NULL;\n\telse {\n\t\tarr = PyArray_FromAny(obj, &indtype, 0, 0, FORCECAST);\n\t\tif (arr == NULL) return -1;\n\t\t*iter = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (*iter == NULL) return -1;\n\t}\n\treturn 0;\n}\n\n/* Adjust dimensionality and strides for index object iterators \n --- i.e. broadcast\n */\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->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->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=NULL, *obj=NULL;\n\tint i, j, n, curraxis, ellipexp, noellip;\n\tPyArrayIterObject *it;\n\tintp dimsize;\n\tintp *indptr;\n\n\t/* Remove old binding if any */\n\tPy_XDECREF(mit->ait);\n\tmit->ait = NULL;\n\n\tPy_XDECREF(mit->subspace);\n\tmit->subspace = NULL;\n\t\n\tsubnd = arr->nd - mit->numiter;\n\tif (subnd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"too many indices for array\");\n\t\treturn;\n\t}\n\n\tmit->ait = (PyArrayIterObject *)PyArray_IterNew((PyObject *)arr);\n\tif (mit->ait == NULL) return;\n\n\t/* If this is just a view, then do nothing more */\n\t/* views are handled by just adjusting the strides\n\t and dimensions of the object.\n\t*/\n\t \n\tif (mit->view) return;\n\n\t/* no subspace iteration needed. 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\tif (mit->subspace == NULL) goto fail;\n\tPy_DECREF(sub);\n\n\t/* Expand dimensions of result */\n\tn = mit->subspace->ao->nd;\n\tfor (i=0; idimensions[mit->nd+i] = mit->subspace->ao->dimensions[i];\n\tmit->nd += n;\n\n\t/* Now, we still need to interpret the ellipsis and slice objects \n\t to determine which axes the indexing arrays are referring to\n\t*/\n\tn = PyTuple_GET_SIZE(mit->indexobj);\n\n\t/* The number of dimensions an ellipsis takes up */\n\tellipexp = arr->nd - n + 1;\n\t/* Now fill in iteraxes -- remember indexing arrays have been \n converted to 0's in mit->indexobj */\n\tcurraxis = 0;\n\tj = 0;\n\tnoellip = 1; /* Only expand the first ellipsis */\n\tmemset(mit->bscoord, 0, sizeof(intp)*arr->nd);\n\tfor (i=0; iindexobj, i);\n\t\tif (PyInt_Check(obj) || PyLong_Check(obj)) \n\t\t\tmit->iteraxes[j++] = curraxis++;\n\t\telse if (noellip && obj == Py_Ellipsis) {\n\t\t\tcurraxis += ellipexp;\n\t\t\tnoellip = 0;\n\t\t}\n\t\telse {\n\t\t\tint start=0;\n\t\t\tint 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}\t\t\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn;\n\n fail:\n\tPy_XDECREF(sub);\n\tPy_XDECREF(mit->ait);\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_Typecode typecode = {PyArray_BOOL, 0, 0};\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\tba = (PyArrayObject *)PyArray_FromAny(myBool, &typecode, 0, 0, \n\t\t\t\t\t CARRAY_FLAGS);\n\tif (ba == NULL) return -1;\n\tnd = ba->nd;\n\tfor (j=0; jdata;\n\tcount = 0;\n\n\t/* pre-determine how many nonzero entries there are */\n\tfor (i=0; iao->data;\n\t\tcoords[j] = 0;\n\t\tdims_m1[j] = ba->dimensions[j]-1;\n\t}\n\n\tptr = (Bool *)ba->data;\n\n\tif (count == 0) return nd;\n\n\t/* Loop through the Boolean array and copy coordinates\n\t for non-zero entries */\n\tfor (i=0; i=0; j--) {\n\t\t\tif (coords[j] < dims_m1[j]) {\n\t\t\t\tcoords[j]++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcoords[j] = 0;\n\t\t\t}\n\t\t}\n\t}\n\treturn nd;\n\n fail:\n\tfor (j=0; jiters[i] = NULL;\n \tmit->view = 0;\n \tmit->index = 0;\n \tmit->ait = NULL;\n \tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tfancy = fancy_indexing_check(indexobj);\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\tif (fancy == SOBJ_NOTFANCY) { /* bail out */\n\t\tmit->view = 1;\n\t\tgoto ret;\n\t}\n\n\tif (fancy == SOBJ_BADARRAY) {\n\t\tPyErr_SetString(PyExc_TypeError,\t\t\t\\\n\t\t\t\t\"arrays used as indexes must be of \" \\\n\t\t\t\t\"integer type\");\n\t\tgoto fail;\n\t}\n\tif (fancy == SOBJ_TOOMANY) {\n\t\tPyErr_SetString(PyExc_TypeError, \"too many indicies\");\n\t\tgoto fail;\n\t}\n\n\tif (fancy == SOBJ_LISTTUP) {\n\t\tPyObject *newobj;\n\t\tnewobj = PySequence_Tuple(indexobj);\n\t\tif (newobj == NULL) goto fail;\n\t\tPy_DECREF(indexobj);\n\t\tindexobj = newobj;\n\t\tmit->indexobj = indexobj;\n\t}\n\n#undef SOBJ_NOTFANCY \n#undef SOBJ_ISFANCY \n#undef SOBJ_BADARRAY \n#undef SOBJ_TOOMANY \n#undef SOBJ_LISTTUP \n\n\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\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 (PyList_Check(indexobj) || PyArray_Check(indexobj)) {\n\t\tmit->numiter = 1;\n\t\tarr = PyArray_FromAny(indexobj, &indtype, 0, 0, FORCECAST);\n\t\tif (arr == NULL) goto fail;\n\t\tmit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (mit->iters[0] == NULL) 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(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\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = new;\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\t/* Store the number of iterators actually converted */\n\t\t/* These will be mapped to actual axes at bind time */\n\t\tif (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)\n\t\t\tgoto fail;\n\t}\n\n ret:\n PyObject_GC_Track(mit);\n return (PyObject *)mit;\n \n fail:\n\tPy_XDECREF(arr);\n\tPy_XDECREF(mit->indexobj);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n PyObject_GC_Del(mit);\n\treturn NULL;\n}\n\n\n/* return unbound mapiter object */\n\nstatic PyObject *\narraymapiter_new(PyTypeObject *type, PyObject *args, PyObject *kwds) \n{\n\tPyObject *newtup, *res;\n\tint n;\n\n\tif (!PyTuple_Check(args)) {\n\t\tPyErr_BadInternalCall();\n\t\treturn NULL;\n\t}\n\n\tn = PyTuple_GET_SIZE(args);\n\t\n\tif (n < 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"must be initialized with >= 1 argument\");\n\t\treturn NULL;\n\t}\n\t\n\tif (n > 1) {\n\t\tnewtup = PyTuple_GetSlice(args, 0, n);\n\t\tif (newtup == NULL) return NULL;\n\t\tres = PyArray_MapIterNew(newtup);\n\t\tPy_DECREF(newtup);\n\t}\n\telse { /* n == 1 */\n\t\tnewtup = PyTuple_GET_ITEM(args, 0);\n\t\tres = PyArray_MapIterNew(newtup);\n\t}\n\n\treturn res; \t\n}\n\n\n/* Returns a 0-dim array holding the element desired */\n/*\nstatic PyObject *\narraymapiter_next(PyArrayMapIterObject *mit)\n{\n\tPyObject *ret;\n\tif (mit->ait == NULL) return NULL;\n\tif (mit->view) return NULL;\n\tif (mit->index < mit->size) {\n\t\tret = PyArray_ToScalar(mit->dataptr, mit->ait->ao);\n\t\tPyArray_MapIterNext(mit);\n\t\treturn ret;\n\t}\n return NULL;\n}\n*/\n\nstatic void\narraymapiter_dealloc(PyArrayMapIterObject *mit)\n{\n\tint i;\n PyObject_GC_UnTrack(mit);\n Py_XDECREF(mit->ait);\n\tPy_XDECREF(mit->indexobj);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n PyObject_GC_Del(mit);\n}\n\nstatic int\narraymapiter_traverse(PyArrayMapIterObject *mit, visitproc visit, void *arg)\n{\n\tint ret, i;\n if (mit->ait != NULL)\n if ((ret = visit((PyObject *)(mit->ait), arg)) != 0) \n\t\t\treturn ret;\t\n\n\tif (mit->iters != NULL) \n\t\tfor (i=0; inumiter; i++) \n\t\t\tif (mit->iters[i] != NULL) \n\t\t\t\tif ((ret=visit((PyObject *)mit->iters[i], \n\t\t\t\t\t arg)) != 0)\n\t\t\t\t\treturn ret;\n\n\tif (mit->indexobj != NULL)\n\t\tif ((ret = visit(mit->indexobj, arg)) != 0) return ret;\n\t\n return 0;\n}\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 MapIterNew must be \n that does not work. 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 char doc_mapiter_bind[] = \"obj.bind(a)\\n Bind an array to the \"\\\n\t\"mapiter object\";\n\nstatic PyObject *\nmapiter_bind(PyArrayMapIterObject *mit, PyObject *args)\n{\n\tPyArrayObject *arr;\n\n if (!PyArg_ParseTuple(args, \"O!\", &PyArray_Type, &arr)) return NULL;\n\n \tPyArray_MapIterBind(mit, arr);\n\n\tif (mit->ait == NULL) return NULL;\n\t\n \tPyArray_MapIterReset(mit);\n\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyMethodDef mapiter_methods[] = {\n\t{\"bind\", (PyCFunction)mapiter_bind, 1, doc_mapiter_bind},\n {NULL,\t\tNULL}\t\t\n};\n*/\n\n\nstatic PyTypeObject PyArrayMapIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"scipy.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 | Py_TPFLAGS_HAVE_GC,/* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)arraymapiter_traverse,\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, /*arraymapiter_next,*/\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 (newfunc)arraymapiter_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n\n};\n\n/** END of Subscript Iterator **/\n\n\n\n", "methods": [ { "name": "PyArray_PyIntAsIntp", "long_name": "PyArray_PyIntAsIntp( PyObject * o)", "filename": "arrayobject.c", "nloc": 59, "complexity": 19, "token_count": 385, "parameters": [ "o" ], "start_line": 40, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 64, "top_nesting_level": 0 }, { "name": "PyArray_PyIntAsInt", "long_name": "PyArray_PyIntAsInt( PyObject * o)", "filename": "arrayobject.c", "nloc": 57, "complexity": 19, "token_count": 389, "parameters": [ "o" ], "start_line": 109, "end_line": 169, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 61, "top_nesting_level": 0 }, { "name": "PyArray_GetPriority", "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", "filename": "arrayobject.c", "nloc": 17, "complexity": 5, "token_count": 86, "parameters": [ "obj", "default_" ], "start_line": 173, "end_line": 191, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "PyArray_Zero", "long_name": "PyArray_Zero( PyArrayObject * arr)", "filename": "arrayobject.c", "nloc": 34, "complexity": 6, "token_count": 190, "parameters": [ "arr" ], "start_line": 208, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "PyArray_One", "long_name": "PyArray_One( PyArrayObject * arr)", "filename": "arrayobject.c", "nloc": 40, "complexity": 7, "token_count": 222, "parameters": [ "arr" ], "start_line": 246, "end_line": 289, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "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": 295, "end_line": 345, "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": 368, "end_line": 399, "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": 213, "parameters": [ "src" ], "start_line": 402, "end_line": 436, "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": 449, "end_line": 471, "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": 474, "end_line": 495, "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": 499, "end_line": 537, "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": 542, "end_line": 562, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "index2ptr", "long_name": "index2ptr( PyArrayObject * mp , intp i)", "filename": "arrayobject.c", "nloc": 15, "complexity": 7, "token_count": 98, "parameters": [ "mp", "i" ], "start_line": 570, "end_line": 585, "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": 588, "end_line": 596, "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": 427, "parameters": [ "dest", "src" ], "start_line": 609, "end_line": 689, "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": 16, "complexity": 2, "token_count": 98, "parameters": [ "dest", "src_object" ], "start_line": 693, "end_line": 712, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "PyArray_FromDimsAndDataAndDescr", "long_name": "PyArray_FromDimsAndDataAndDescr( int nd , int * d , PyArray_Descr * descr , char * data)", "filename": "arrayobject.c", "nloc": 15, "complexity": 3, "token_count": 121, "parameters": [ "nd", "d", "descr", "data" ], "start_line": 720, "end_line": 739, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "PyArray_FromDimsAndData", "long_name": "PyArray_FromDimsAndData( int nd , int * d , int type , char * data)", "filename": "arrayobject.c", "nloc": 14, "complexity": 3, "token_count": 112, "parameters": [ "nd", "d", "type", "data" ], "start_line": 743, "end_line": 760, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "PyArray_FromDims", "long_name": "PyArray_FromDims( int nd , int * d , int type)", "filename": "arrayobject.c", "nloc": 14, "complexity": 5, "token_count": 133, "parameters": [ "nd", "d", "type" ], "start_line": 764, "end_line": 781, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "PyArray_Copy", "long_name": "PyArray_Copy( PyArrayObject * m1)", "filename": "arrayobject.c", "nloc": 11, "complexity": 2, "token_count": 77, "parameters": [ "m1" ], "start_line": 787, "end_line": 799, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "PyArray_Scalar", "long_name": "PyArray_Scalar( char * data , int type_num , int itemsize , int swap)", "filename": "arrayobject.c", "nloc": 48, "complexity": 8, "token_count": 289, "parameters": [ "data", "type_num", "itemsize", "swap" ], "start_line": 805, "end_line": 854, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "top_nesting_level": 0 }, { "name": "PyArray_ToScalar", "long_name": "PyArray_ToScalar( char * data , PyArrayObject * arr)", "filename": "arrayobject.c", "nloc": 7, "complexity": 1, "token_count": 51, "parameters": [ "data", "arr" ], "start_line": 861, "end_line": 868, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_Return", "long_name": "PyArray_Return( PyArrayObject * mp)", "filename": "arrayobject.c", "nloc": 17, "complexity": 5, "token_count": 85, "parameters": [ "mp" ], "start_line": 874, "end_line": 893, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "PyArray_RegisterDataType", "long_name": "PyArray_RegisterDataType( PyTypeObject * type)", "filename": "arrayobject.c", "nloc": 31, "complexity": 6, "token_count": 177, "parameters": [ "type" ], "start_line": 904, "end_line": 936, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "PyArray_RegisterDescrForType", "long_name": "PyArray_RegisterDescrForType( int typenum , PyArray_Descr * descr)", "filename": "arrayobject.c", "nloc": 32, "complexity": 3, "token_count": 167, "parameters": [ "typenum", "descr" ], "start_line": 946, "end_line": 989, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "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": 16, "token_count": 577, "parameters": [ "self", "fp", "sep", "format" ], "start_line": 993, "end_line": 1084, "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": 24, "complexity": 5, "token_count": 151, "parameters": [ "self" ], "start_line": 1087, "end_line": 1115, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "PyArray_ToString", "long_name": "PyArray_ToString( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 34, "complexity": 6, "token_count": 191, "parameters": [ "self" ], "start_line": 1118, "end_line": 1153, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "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": 1162, "end_line": 1199, "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": 1206, "end_line": 1214, "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": 22, "complexity": 4, "token_count": 150, "parameters": [ "self", "i" ], "start_line": 1218, "end_line": 1242, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "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": 1245, "end_line": 1248, "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": 27, "complexity": 8, "token_count": 177, "parameters": [ "self", "i", "v" ], "start_line": 1252, "end_line": 1282, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "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": 1288, "end_line": 1291, "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 , int * v)", "filename": "arrayobject.c", "nloc": 9, "complexity": 2, "token_count": 40, "parameters": [ "o", "v" ], "start_line": 1297, "end_line": 1305, "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 , int length , int * start , int * stop , int * step , intp * slicelength)", "filename": "arrayobject.c", "nloc": 45, "complexity": 24, "token_count": 376, "parameters": [ "r", "length", "start", "stop", "step", "slicelength" ], "start_line": 1311, "end_line": 1361, "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 , int * step_size , intp * n_steps , int max)", "filename": "arrayobject.c", "nloc": 45, "complexity": 11, "token_count": 223, "parameters": [ "op", "step_size", "n_steps", "max" ], "start_line": 1368, "end_line": 1413, "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": 89, "complexity": 20, "token_count": 540, "parameters": [ "self", "op", "dimensions", "strides", "offset_ptr" ], "start_line": 1417, "end_line": 1512, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 96, "top_nesting_level": 0 }, { "name": "_swap_axes", "long_name": "_swap_axes( PyArrayMapIterObject * mit , PyArrayObject ** ret)", "filename": "arrayobject.c", "nloc": 24, "complexity": 4, "token_count": 187, "parameters": [ "mit", "ret" ], "start_line": 1515, "end_line": 1549, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "PyArray_GetMap", "long_name": "PyArray_GetMap( PyArrayMapIterObject * mit)", "filename": "arrayobject.c", "nloc": 36, "complexity": 8, "token_count": 252, "parameters": [ "mit" ], "start_line": 1554, "end_line": 1603, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "top_nesting_level": 0 }, { "name": "PyArray_SetMap", "long_name": "PyArray_SetMap( PyArrayMapIterObject * mit , PyObject * op)", "filename": "arrayobject.c", "nloc": 50, "complexity": 12, "token_count": 392, "parameters": [ "mit", "op" ], "start_line": 1606, "end_line": 1665, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 60, "top_nesting_level": 0 }, { "name": "array_subscript", "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", "filename": "arrayobject.c", "nloc": 62, "complexity": 19, "token_count": 420, "parameters": [ "self", "op" ], "start_line": 1686, "end_line": 1762, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 77, "top_nesting_level": 0 }, { "name": "array_ass_sub", "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", "filename": "arrayobject.c", "nloc": 44, "complexity": 9, "token_count": 252, "parameters": [ "self", "index", "op" ], "start_line": 1775, "end_line": 1828, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "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": 1836, "end_line": 1839, "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": 1858, "end_line": 1870, "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": 1873, "end_line": 1888, "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": 1892, "end_line": 1901, "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": 1904, "end_line": 1915, "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": 1983, "end_line": 2016, "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": 2023, "end_line": 2062, "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": 23, "complexity": 5, "token_count": 136, "parameters": [ "m1", "op", "axis", "rtype" ], "start_line": 2065, "end_line": 2087, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "PyArray_GenericAccumulateFunction", "long_name": "PyArray_GenericAccumulateFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", "filename": "arrayobject.c", "nloc": 23, "complexity": 5, "token_count": 136, "parameters": [ "m1", "op", "axis", "rtype" ], "start_line": 2091, "end_line": 2113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "PyArray_GenericBinaryFunction", "long_name": "PyArray_GenericBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", "filename": "arrayobject.c", "nloc": 12, "complexity": 2, "token_count": 69, "parameters": [ "m1", "m2", "op" ], "start_line": 2117, "end_line": 2128, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_GenericUnaryFunction", "long_name": "PyArray_GenericUnaryFunction( PyArrayObject * m1 , PyObject * op)", "filename": "arrayobject.c", "nloc": 12, "complexity": 2, "token_count": 63, "parameters": [ "m1", "op" ], "start_line": 2131, "end_line": 2142, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_GenericInplaceBinaryFunction", "long_name": "PyArray_GenericInplaceBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", "filename": "arrayobject.c", "nloc": 13, "complexity": 2, "token_count": 71, "parameters": [ "m1", "m2", "op" ], "start_line": 2145, "end_line": 2157, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 2160, "end_line": 2163, "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": 2166, "end_line": 2169, "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": 2172, "end_line": 2175, "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": 2178, "end_line": 2181, "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": 2184, "end_line": 2187, "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": 2190, "end_line": 2193, "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": 2196, "end_line": 2199, "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": 2202, "end_line": 2205, "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": 2208, "end_line": 2211, "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": 2214, "end_line": 2217, "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": 2220, "end_line": 2223, "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": 2226, "end_line": 2229, "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": 2232, "end_line": 2235, "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": 2238, "end_line": 2241, "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": 2244, "end_line": 2247, "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": 2250, "end_line": 2253, "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": 2256, "end_line": 2259, "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": 2262, "end_line": 2265, "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": 2268, "end_line": 2271, "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": 2274, "end_line": 2277, "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": 2280, "end_line": 2283, "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": 2286, "end_line": 2289, "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": 2292, "end_line": 2295, "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": 2298, "end_line": 2301, "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": 2304, "end_line": 2307, "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": 2310, "end_line": 2313, "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": 2316, "end_line": 2319, "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": 2322, "end_line": 2326, "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": 2329, "end_line": 2333, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "array_all_nonzero", "long_name": "array_all_nonzero( PyArrayObject * mp)", "filename": "arrayobject.c", "nloc": 18, "complexity": 4, "token_count": 93, "parameters": [ "mp" ], "start_line": 2337, "end_line": 2355, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "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": 2358, "end_line": 2373, "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": 143, "parameters": [ "v" ], "start_line": 2377, "end_line": 2403, "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": 143, "parameters": [ "v" ], "start_line": 2406, "end_line": 2431, "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": 124, "parameters": [ "v" ], "start_line": 2434, "end_line": 2456, "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": 124, "parameters": [ "v" ], "start_line": 2459, "end_line": 2481, "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": 124, "parameters": [ "v" ], "start_line": 2484, "end_line": 2506, "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": 2509, "end_line": 2513, "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": 34, "complexity": 11, "token_count": 258, "parameters": [ "self", "ilow", "ihigh" ], "start_line": 2574, "end_line": 2612, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "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": 2616, "end_line": 2637, "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": 4, "complexity": 1, "token_count": 26, "parameters": [ "self", "el" ], "start_line": 2640, "end_line": 2645, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "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": 308, "parameters": [ "string", "n", "max_n", "data", "nd", "dimensions", "strides", "self" ], "start_line": 2666, "end_line": 2713, "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": 222, "parameters": [ "self" ], "start_line": 2716, "end_line": 2752, "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": 2758, "end_line": 2775, "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": 2778, "end_line": 2790, "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": 2793, "end_line": 2805, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "array_richcompare", "long_name": "array_richcompare( PyArrayObject * self , PyObject * other , int cmp_op)", "filename": "arrayobject.c", "nloc": 61, "complexity": 13, "token_count": 273, "parameters": [ "self", "other", "cmp_op" ], "start_line": 2809, "end_line": 2886, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 78, "top_nesting_level": 0 }, { "name": "_check_axis", "long_name": "_check_axis( PyArrayObject * arr , int * axis , int flags)", "filename": "arrayobject.c", "nloc": 29, "complexity": 8, "token_count": 164, "parameters": [ "arr", "axis", "flags" ], "start_line": 2889, "end_line": 2918, "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": 17, "complexity": 4, "token_count": 91, "parameters": [ "len", "vals" ], "start_line": 2924, "end_line": 2940, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "PyArray_IntpFromSequence", "long_name": "PyArray_IntpFromSequence( PyObject * seq , intp * vals , int maxvals)", "filename": "arrayobject.c", "nloc": 21, "complexity": 7, "token_count": 161, "parameters": [ "seq", "vals", "maxvals" ], "start_line": 2945, "end_line": 2968, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "_IsContiguous", "long_name": "_IsContiguous( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 14, "complexity": 6, "token_count": 109, "parameters": [ "ap" ], "start_line": 2974, "end_line": 2990, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_IsFortranContiguous", "long_name": "_IsFortranContiguous( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 14, "complexity": 6, "token_count": 107, "parameters": [ "ap" ], "start_line": 2994, "end_line": 3010, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_IsAligned", "long_name": "_IsAligned( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 14, "complexity": 4, "token_count": 110, "parameters": [ "ap" ], "start_line": 3013, "end_line": 3029, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_IsWriteable", "long_name": "_IsWriteable( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 16, "complexity": 8, "token_count": 109, "parameters": [ "ap" ], "start_line": 3032, "end_line": 3065, "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": 22, "complexity": 9, "token_count": 129, "parameters": [ "ret", "flagmask" ], "start_line": 3069, "end_line": 3091, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "PyArray_CheckStrides", "long_name": "PyArray_CheckStrides( int elsize , int nd , intp numbytes , intp * dims , intp * newstrides)", "filename": "arrayobject.c", "nloc": 13, "complexity": 4, "token_count": 84, "parameters": [ "elsize", "nd", "numbytes", "dims", "newstrides" ], "start_line": 3098, "end_line": 3113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "_array_fill_strides", "long_name": "_array_fill_strides( intp * strides , intp * dims , int nd , intp itemsize , int inflag , int * objflags)", "filename": "arrayobject.c", "nloc": 24, "complexity": 9, "token_count": 171, "parameters": [ "strides", "dims", "nd", "itemsize", "inflag", "objflags" ], "start_line": 3133, "end_line": 3157, "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 , char * data , int itemsize , int flags , PyObject * obj)", "filename": "arrayobject.c", "nloc": 117, "complexity": 27, "token_count": 713, "parameters": [ "subtype", "nd", "dims", "type_num", "strides", "data", "itemsize", "flags", "obj" ], "start_line": 3161, "end_line": 3311, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 151, "top_nesting_level": 0 }, { "name": "PyArray_Resize", "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape)", "filename": "arrayobject.c", "nloc": 87, "complexity": 15, "token_count": 501, "parameters": [ "self", "newshape" ], "start_line": 3316, "end_line": 3421, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 106, "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": 3426, "end_line": 3443, "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": 47, "complexity": 7, "token_count": 261, "parameters": [ "arr", "obj" ], "start_line": 3446, "end_line": 3498, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "top_nesting_level": 0 }, { "name": "array_new", "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", "filename": "arrayobject.c", "nloc": 100, "complexity": 20, "token_count": 589, "parameters": [ "subtype", "args", "kwds" ], "start_line": 3501, "end_line": 3616, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 116, "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": 3623, "end_line": 3626, "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": 10, "complexity": 3, "token_count": 57, "parameters": [ "self" ], "start_line": 3629, "end_line": 3639, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "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": 3712, "end_line": 3715, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "array_shape_set", "long_name": "array_shape_set( PyArrayObject * self , PyObject * val)", "filename": "arrayobject.c", "nloc": 33, "complexity": 6, "token_count": 206, "parameters": [ "self", "val" ], "start_line": 3719, "end_line": 3753, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "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": 3757, "end_line": 3760, "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": 32, "complexity": 7, "token_count": 209, "parameters": [ "self", "obj" ], "start_line": 3763, "end_line": 3796, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "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": 3800, "end_line": 3807, "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": 3810, "end_line": 3818, "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": 3822, "end_line": 3828, "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": 3831, "end_line": 3845, "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": 3848, "end_line": 3892, "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": 19, "parameters": [ "self" ], "start_line": 3896, "end_line": 3899, "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": 8, "complexity": 3, "token_count": 42, "parameters": [ "self" ], "start_line": 3902, "end_line": 3909, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "array_typechar_get", "long_name": "array_typechar_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 8, "complexity": 2, "token_count": 47, "parameters": [ "self" ], "start_line": 3913, "end_line": 3920, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "array_typestr_get", "long_name": "array_typestr_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 19, "complexity": 7, "token_count": 141, "parameters": [ "self" ], "start_line": 3923, "end_line": 3943, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "array_descr_get", "long_name": "array_descr_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 19, "complexity": 5, "token_count": 128, "parameters": [ "self" ], "start_line": 3946, "end_line": 3968, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "array_type_get", "long_name": "array_type_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 4, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 3972, "end_line": 3975, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "array_type_set", "long_name": "array_type_set( PyArrayObject * self , PyObject * arg)", "filename": "arrayobject.c", "nloc": 41, "complexity": 10, "token_count": 294, "parameters": [ "self", "arg" ], "start_line": 3987, "end_line": 4045, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 59, "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": 4050, "end_line": 4060, "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": 4064, "end_line": 4089, "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": 31, "complexity": 4, "token_count": 177, "parameters": [ "self", "val" ], "start_line": 4093, "end_line": 4125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "array_imag_get", "long_name": "array_imag_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 34, "complexity": 3, "token_count": 200, "parameters": [ "self" ], "start_line": 4128, "end_line": 4163, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "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": 203, "parameters": [ "self", "val" ], "start_line": 4166, "end_line": 4203, "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": 4206, "end_line": 4209, "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": 51, "complexity": 9, "token_count": 368, "parameters": [ "self", "val" ], "start_line": 4212, "end_line": 4266, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 55, "top_nesting_level": 0 }, { "name": "discover_depth", "long_name": "discover_depth( PyObject * s , int max , int stop_at_string)", "filename": "arrayobject.c", "nloc": 23, "complexity": 14, "token_count": 169, "parameters": [ "s", "max", "stop_at_string" ], "start_line": 4441, "end_line": 4466, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "discover_itemsize", "long_name": "discover_itemsize( PyObject * s , int nd , int * itemsize)", "filename": "arrayobject.c", "nloc": 21, "complexity": 9, "token_count": 161, "parameters": [ "s", "nd", "itemsize" ], "start_line": 4469, "end_line": 4491, "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": 4498, "end_line": 4524, "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( int chktype , int mintype , int chksize , int minsize , PyArray_Typecode * outtype)", "filename": "arrayobject.c", "nloc": 19, "complexity": 5, "token_count": 100, "parameters": [ "chktype", "mintype", "chksize", "minsize", "outtype" ], "start_line": 4527, "end_line": 4547, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "_array_find_type", "long_name": "_array_find_type( PyObject * op , PyArray_Typecode * minitype , PyArray_Typecode * outtype , int max)", "filename": "arrayobject.c", "nloc": 126, "complexity": 28, "token_count": 671, "parameters": [ "op", "minitype", "outtype", "max" ], "start_line": 4550, "end_line": 4691, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 142, "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": 4694, "end_line": 4717, "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_Typecode * typecode)", "filename": "arrayobject.c", "nloc": 21, "complexity": 5, "token_count": 132, "parameters": [ "op", "typecode" ], "start_line": 4721, "end_line": 4747, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 0 }, { "name": "Array_FromSequence", "long_name": "Array_FromSequence( PyObject * s , PyArray_Typecode * typecode , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 51, "complexity": 17, "token_count": 313, "parameters": [ "s", "typecode", "min_depth", "max_depth" ], "start_line": 4751, "end_line": 4808, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 58, "top_nesting_level": 0 }, { "name": "PyArray_ValidType", "long_name": "PyArray_ValidType( int type)", "filename": "arrayobject.c", "nloc": 7, "complexity": 2, "token_count": 30, "parameters": [ "type" ], "start_line": 4812, "end_line": 4819, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "_bufferedcast", "long_name": "_bufferedcast( PyArrayObject * out , PyArrayObject * in)", "filename": "arrayobject.c", "nloc": 75, "complexity": 16, "token_count": 477, "parameters": [ "out", "in" ], "start_line": 4825, "end_line": 4915, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 91, "top_nesting_level": 0 }, { "name": "PyArray_Cast", "long_name": "PyArray_Cast( PyArrayObject * mp , int type_num)", "filename": "arrayobject.c", "nloc": 10, "complexity": 1, "token_count": 56, "parameters": [ "mp", "type_num" ], "start_line": 4921, "end_line": 4932, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_CastToType", "long_name": "PyArray_CastToType( PyArrayObject * mp , PyArray_Typecode * at)", "filename": "arrayobject.c", "nloc": 31, "complexity": 13, "token_count": 233, "parameters": [ "mp", "at" ], "start_line": 4935, "end_line": 4970, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "PyArray_CastTo", "long_name": "PyArray_CastTo( PyArrayObject * out , PyArrayObject * mp)", "filename": "arrayobject.c", "nloc": 40, "complexity": 10, "token_count": 214, "parameters": [ "out", "mp" ], "start_line": 4977, "end_line": 5023, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "array_fromarray", "long_name": "array_fromarray( PyArrayObject * arr , PyArray_Typecode * typecode , int flags)", "filename": "arrayobject.c", "nloc": 116, "complexity": 35, "token_count": 721, "parameters": [ "arr", "typecode", "flags" ], "start_line": 5026, "end_line": 5157, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 132, "top_nesting_level": 0 }, { "name": "_array_typecode_fromstr", "long_name": "_array_typecode_fromstr( char * str , int * swap , PyArray_Typecode * type)", "filename": "arrayobject.c", "nloc": 94, "complexity": 36, "token_count": 533, "parameters": [ "str", "swap", "type" ], "start_line": 5161, "end_line": 5266, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 106, "top_nesting_level": 0 }, { "name": "array_frominterface", "long_name": "array_frominterface( PyObject * input , PyArray_Typecode * intype , int flags)", "filename": "arrayobject.c", "nloc": 113, "complexity": 26, "token_count": 715, "parameters": [ "input", "intype", "flags" ], "start_line": 5269, "end_line": 5392, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 124, "top_nesting_level": 0 }, { "name": "array_fromattr", "long_name": "array_fromattr( PyObject * op , PyArray_Typecode * typecode , int flags)", "filename": "arrayobject.c", "nloc": 30, "complexity": 5, "token_count": 181, "parameters": [ "op", "typecode", "flags" ], "start_line": 5395, "end_line": 5426, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "array_fromobject", "long_name": "array_fromobject( PyObject * op , PyArray_Typecode * typecode , int min_depth , int max_depth , int flags)", "filename": "arrayobject.c", "nloc": 49, "complexity": 14, "token_count": 291, "parameters": [ "op", "typecode", "min_depth", "max_depth", "flags" ], "start_line": 5430, "end_line": 5495, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 66, "top_nesting_level": 0 }, { "name": "PyArray_ArrayType", "long_name": "PyArray_ArrayType( PyObject * op , PyArray_Typecode * intype , PyArray_Typecode * outtype)", "filename": "arrayobject.c", "nloc": 6, "complexity": 1, "token_count": 29, "parameters": [ "op", "intype", "outtype" ], "start_line": 5498, "end_line": 5503, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "PyArray_ObjectType", "long_name": "PyArray_ObjectType( PyObject * op , int minimum_type)", "filename": "arrayobject.c", "nloc": 7, "complexity": 1, "token_count": 40, "parameters": [ "op", "minimum_type" ], "start_line": 5506, "end_line": 5512, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "PyArray_FromAny", "long_name": "PyArray_FromAny( PyObject * op , PyArray_Typecode * typecode , int min_depth , int max_depth , int requires)", "filename": "arrayobject.c", "nloc": 24, "complexity": 9, "token_count": 165, "parameters": [ "op", "typecode", "min_depth", "max_depth", "requires" ], "start_line": 5566, "end_line": 5596, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "PyArray_EnsureArray", "long_name": "PyArray_EnsureArray( PyObject * op)", "filename": "arrayobject.c", "nloc": 14, "complexity": 5, "token_count": 87, "parameters": [ "op" ], "start_line": 5607, "end_line": 5623, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "PyArray_FromObject", "long_name": "PyArray_FromObject( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 7, "complexity": 1, "token_count": 51, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5629, "end_line": 5635, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "PyArray_ContiguousFromObject", "long_name": "PyArray_ContiguousFromObject( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 8, "complexity": 1, "token_count": 51, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5638, "end_line": 5645, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_CopyFromObject", "long_name": "PyArray_CopyFromObject( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 8, "complexity": 1, "token_count": 51, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5648, "end_line": 5655, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_ContiguousFromAny", "long_name": "PyArray_ContiguousFromAny( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 8, "complexity": 1, "token_count": 49, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5660, "end_line": 5667, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_CanCastSafely", "long_name": "PyArray_CanCastSafely( int fromtype , int totype)", "filename": "arrayobject.c", "nloc": 81, "complexity": 39, "token_count": 476, "parameters": [ "fromtype", "totype" ], "start_line": 5670, "end_line": 5753, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 84, "top_nesting_level": 0 }, { "name": "PyArray_CanCastTo", "long_name": "PyArray_CanCastTo( PyArray_Typecode * from , PyArray_Typecode * to)", "filename": "arrayobject.c", "nloc": 24, "complexity": 7, "token_count": 134, "parameters": [ "from", "to" ], "start_line": 5756, "end_line": 5780, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 }, { "name": "PyArray_IterNew", "long_name": "PyArray_IterNew( PyObject * obj)", "filename": "arrayobject.c", "nloc": 34, "complexity": 6, "token_count": 258, "parameters": [ "obj" ], "start_line": 5790, "end_line": 5827, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "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": 5832, "end_line": 5842, "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": 6, "complexity": 1, "token_count": 25, "parameters": [ "it" ], "start_line": 5845, "end_line": 5850, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "arrayiter_traverse", "long_name": "arrayiter_traverse( PyArrayIterObject * it , visitproc visit , * arg)", "filename": "arrayobject.c", "nloc": 6, "complexity": 2, "token_count": 42, "parameters": [ "it", "visit", "arg" ], "start_line": 5853, "end_line": 5858, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "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": 5862, "end_line": 5865, "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": 42, "complexity": 7, "token_count": 272, "parameters": [ "self", "ind" ], "start_line": 5869, "end_line": 5917, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "iter_subscript_int", "long_name": "iter_subscript_int( PyArrayIterObject * self , PyArrayObject * ind)", "filename": "arrayobject.c", "nloc": 51, "complexity": 8, "token_count": 347, "parameters": [ "self", "ind" ], "start_line": 5920, "end_line": 5973, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 0 }, { "name": "iter_subscript", "long_name": "iter_subscript( PyArrayIterObject * self , PyObject * ind)", "filename": "arrayobject.c", "nloc": 97, "complexity": 20, "token_count": 593, "parameters": [ "self", "ind" ], "start_line": 5977, "end_line": 6096, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 120, "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": 176, "parameters": [ "self", "ind", "val", "swap" ], "start_line": 6100, "end_line": 6132, "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": 289, "parameters": [ "self", "ind", "val", "swap" ], "start_line": 6135, "end_line": 6177, "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": 103, "complexity": 24, "token_count": 636, "parameters": [ "self", "ind", "val" ], "start_line": 6181, "end_line": 6303, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 123, "top_nesting_level": 0 }, { "name": "iter_array", "long_name": "iter_array( PyArrayIterObject * it , PyObject * op)", "filename": "arrayobject.c", "nloc": 30, "complexity": 5, "token_count": 221, "parameters": [ "it", "op" ], "start_line": 6316, "end_line": 6358, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "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": 6363, "end_line": 6367, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "fancy_indexing_check", "long_name": "fancy_indexing_check( PyObject * args)", "filename": "arrayobject.c", "nloc": 55, "complexity": 22, "token_count": 293, "parameters": [ "args" ], "start_line": 6432, "end_line": 6493, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 62, "top_nesting_level": 0 }, { "name": "_convert_obj", "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", "filename": "arrayobject.c", "nloc": 15, "complexity": 5, "token_count": 105, "parameters": [ "obj", "iter" ], "start_line": 6501, "end_line": 6516, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "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": 6522, "end_line": 6591, "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": 261, "parameters": [ "mit" ], "start_line": 6595, "end_line": 6632, "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": 296, "parameters": [ "mit" ], "start_line": 6638, "end_line": 6682, "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": 102, "complexity": 22, "token_count": 690, "parameters": [ "mit", "arr" ], "start_line": 6700, "end_line": 6836, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 137, "top_nesting_level": 0 }, { "name": "_nonzero_indices", "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", "filename": "arrayobject.c", "nloc": 57, "complexity": 15, "token_count": 454, "parameters": [ "myBool", "iters" ], "start_line": 6842, "end_line": 6911, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 70, "top_nesting_level": 0 }, { "name": "PyArray_MapIterNew", "long_name": "PyArray_MapIterNew( PyObject * indexobj)", "filename": "arrayobject.c", "nloc": 111, "complexity": 24, "token_count": 745, "parameters": [ "indexobj" ], "start_line": 6914, "end_line": 7047, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 134, "top_nesting_level": 0 }, { "name": "arraymapiter_new", "long_name": "arraymapiter_new( PyTypeObject * type , PyObject * args , PyObject * kwds)", "filename": "arrayobject.c", "nloc": 26, "complexity": 5, "token_count": 130, "parameters": [ "type", "args", "kwds" ], "start_line": 7053, "end_line": 7083, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "arraymapiter_dealloc", "long_name": "arraymapiter_dealloc( PyArrayMapIterObject * mit)", "filename": "arrayobject.c", "nloc": 10, "complexity": 2, "token_count": 60, "parameters": [ "mit" ], "start_line": 7104, "end_line": 7113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "arraymapiter_traverse", "long_name": "arraymapiter_traverse( PyArrayMapIterObject * mit , visitproc visit , * arg)", "filename": "arrayobject.c", "nloc": 16, "complexity": 9, "token_count": 146, "parameters": [ "mit", "visit", "arg" ], "start_line": 7116, "end_line": 7134, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 } ], "methods_before": [ { "name": "PyArray_PyIntAsIntp", "long_name": "PyArray_PyIntAsIntp( PyObject * o)", "filename": "arrayobject.c", "nloc": 59, "complexity": 19, "token_count": 385, "parameters": [ "o" ], "start_line": 40, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 64, "top_nesting_level": 0 }, { "name": "PyArray_PyIntAsInt", "long_name": "PyArray_PyIntAsInt( PyObject * o)", "filename": "arrayobject.c", "nloc": 57, "complexity": 19, "token_count": 389, "parameters": [ "o" ], "start_line": 109, "end_line": 169, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 61, "top_nesting_level": 0 }, { "name": "PyArray_GetPriority", "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", "filename": "arrayobject.c", "nloc": 17, "complexity": 5, "token_count": 86, "parameters": [ "obj", "default_" ], "start_line": 173, "end_line": 191, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "PyArray_Zero", "long_name": "PyArray_Zero( PyArrayObject * arr)", "filename": "arrayobject.c", "nloc": 34, "complexity": 6, "token_count": 190, "parameters": [ "arr" ], "start_line": 208, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "PyArray_One", "long_name": "PyArray_One( PyArrayObject * arr)", "filename": "arrayobject.c", "nloc": 40, "complexity": 7, "token_count": 222, "parameters": [ "arr" ], "start_line": 246, "end_line": 289, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "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": 295, "end_line": 345, "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": 368, "end_line": 399, "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": 213, "parameters": [ "src" ], "start_line": 402, "end_line": 436, "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": 449, "end_line": 471, "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": 474, "end_line": 495, "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": 499, "end_line": 537, "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": 542, "end_line": 562, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "index2ptr", "long_name": "index2ptr( PyArrayObject * mp , intp i)", "filename": "arrayobject.c", "nloc": 10, "complexity": 7, "token_count": 86, "parameters": [ "mp", "i" ], "start_line": 570, "end_line": 580, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "PyArray_Size", "long_name": "PyArray_Size( PyObject * op)", "filename": "arrayobject.c", "nloc": 9, "complexity": 2, "token_count": 33, "parameters": [ "op" ], "start_line": 583, "end_line": 591, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "PyArray_CopyInto", "long_name": "PyArray_CopyInto( PyArrayObject * dest , PyArrayObject * src)", "filename": "arrayobject.c", "nloc": 71, "complexity": 16, "token_count": 427, "parameters": [ "dest", "src" ], "start_line": 604, "end_line": 684, "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": 16, "complexity": 2, "token_count": 98, "parameters": [ "dest", "src_object" ], "start_line": 688, "end_line": 707, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "PyArray_FromDimsAndDataAndDescr", "long_name": "PyArray_FromDimsAndDataAndDescr( int nd , int * d , PyArray_Descr * descr , char * data)", "filename": "arrayobject.c", "nloc": 15, "complexity": 3, "token_count": 121, "parameters": [ "nd", "d", "descr", "data" ], "start_line": 715, "end_line": 734, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "PyArray_FromDimsAndData", "long_name": "PyArray_FromDimsAndData( int nd , int * d , int type , char * data)", "filename": "arrayobject.c", "nloc": 14, "complexity": 3, "token_count": 112, "parameters": [ "nd", "d", "type", "data" ], "start_line": 738, "end_line": 755, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "PyArray_FromDims", "long_name": "PyArray_FromDims( int nd , int * d , int type)", "filename": "arrayobject.c", "nloc": 14, "complexity": 5, "token_count": 133, "parameters": [ "nd", "d", "type" ], "start_line": 759, "end_line": 776, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "PyArray_Copy", "long_name": "PyArray_Copy( PyArrayObject * m1)", "filename": "arrayobject.c", "nloc": 11, "complexity": 2, "token_count": 77, "parameters": [ "m1" ], "start_line": 782, "end_line": 794, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "PyArray_Scalar", "long_name": "PyArray_Scalar( char * data , int type_num , int itemsize , int swap)", "filename": "arrayobject.c", "nloc": 48, "complexity": 8, "token_count": 289, "parameters": [ "data", "type_num", "itemsize", "swap" ], "start_line": 800, "end_line": 849, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "top_nesting_level": 0 }, { "name": "PyArray_ToScalar", "long_name": "PyArray_ToScalar( char * data , PyArrayObject * arr)", "filename": "arrayobject.c", "nloc": 7, "complexity": 1, "token_count": 51, "parameters": [ "data", "arr" ], "start_line": 856, "end_line": 863, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_Return", "long_name": "PyArray_Return( PyArrayObject * mp)", "filename": "arrayobject.c", "nloc": 17, "complexity": 5, "token_count": 85, "parameters": [ "mp" ], "start_line": 869, "end_line": 888, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "PyArray_RegisterDataType", "long_name": "PyArray_RegisterDataType( PyTypeObject * type)", "filename": "arrayobject.c", "nloc": 31, "complexity": 6, "token_count": 177, "parameters": [ "type" ], "start_line": 899, "end_line": 931, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "PyArray_RegisterDescrForType", "long_name": "PyArray_RegisterDescrForType( int typenum , PyArray_Descr * descr)", "filename": "arrayobject.c", "nloc": 32, "complexity": 3, "token_count": 167, "parameters": [ "typenum", "descr" ], "start_line": 941, "end_line": 984, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "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": 16, "token_count": 577, "parameters": [ "self", "fp", "sep", "format" ], "start_line": 988, "end_line": 1079, "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": 24, "complexity": 5, "token_count": 151, "parameters": [ "self" ], "start_line": 1082, "end_line": 1110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "PyArray_ToString", "long_name": "PyArray_ToString( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 34, "complexity": 6, "token_count": 191, "parameters": [ "self" ], "start_line": 1113, "end_line": 1148, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "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": 1157, "end_line": 1194, "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": 1201, "end_line": 1209, "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": 22, "complexity": 4, "token_count": 150, "parameters": [ "self", "i" ], "start_line": 1213, "end_line": 1237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "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": 1240, "end_line": 1243, "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": 27, "complexity": 8, "token_count": 177, "parameters": [ "self", "i", "v" ], "start_line": 1247, "end_line": 1277, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "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": 1283, "end_line": 1286, "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 , int * v)", "filename": "arrayobject.c", "nloc": 9, "complexity": 2, "token_count": 40, "parameters": [ "o", "v" ], "start_line": 1292, "end_line": 1300, "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 , int length , int * start , int * stop , int * step , intp * slicelength)", "filename": "arrayobject.c", "nloc": 45, "complexity": 24, "token_count": 376, "parameters": [ "r", "length", "start", "stop", "step", "slicelength" ], "start_line": 1306, "end_line": 1356, "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 , int * step_size , intp * n_steps , int max)", "filename": "arrayobject.c", "nloc": 45, "complexity": 11, "token_count": 223, "parameters": [ "op", "step_size", "n_steps", "max" ], "start_line": 1363, "end_line": 1408, "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": 89, "complexity": 20, "token_count": 540, "parameters": [ "self", "op", "dimensions", "strides", "offset_ptr" ], "start_line": 1412, "end_line": 1507, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 96, "top_nesting_level": 0 }, { "name": "_swap_axes", "long_name": "_swap_axes( PyArrayMapIterObject * mit , PyArrayObject ** ret)", "filename": "arrayobject.c", "nloc": 24, "complexity": 4, "token_count": 187, "parameters": [ "mit", "ret" ], "start_line": 1510, "end_line": 1544, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "PyArray_GetMap", "long_name": "PyArray_GetMap( PyArrayMapIterObject * mit)", "filename": "arrayobject.c", "nloc": 36, "complexity": 8, "token_count": 252, "parameters": [ "mit" ], "start_line": 1549, "end_line": 1598, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "top_nesting_level": 0 }, { "name": "PyArray_SetMap", "long_name": "PyArray_SetMap( PyArrayMapIterObject * mit , PyObject * op)", "filename": "arrayobject.c", "nloc": 50, "complexity": 12, "token_count": 392, "parameters": [ "mit", "op" ], "start_line": 1601, "end_line": 1660, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 60, "top_nesting_level": 0 }, { "name": "array_subscript", "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", "filename": "arrayobject.c", "nloc": 62, "complexity": 19, "token_count": 420, "parameters": [ "self", "op" ], "start_line": 1681, "end_line": 1757, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 77, "top_nesting_level": 0 }, { "name": "array_ass_sub", "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", "filename": "arrayobject.c", "nloc": 44, "complexity": 9, "token_count": 252, "parameters": [ "self", "index", "op" ], "start_line": 1770, "end_line": 1823, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "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": 1831, "end_line": 1834, "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": 1853, "end_line": 1865, "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": 1868, "end_line": 1883, "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": 1887, "end_line": 1896, "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": 1899, "end_line": 1910, "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": 1978, "end_line": 2011, "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": 2018, "end_line": 2057, "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": 23, "complexity": 5, "token_count": 136, "parameters": [ "m1", "op", "axis", "rtype" ], "start_line": 2060, "end_line": 2082, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "PyArray_GenericAccumulateFunction", "long_name": "PyArray_GenericAccumulateFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", "filename": "arrayobject.c", "nloc": 23, "complexity": 5, "token_count": 136, "parameters": [ "m1", "op", "axis", "rtype" ], "start_line": 2086, "end_line": 2108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "PyArray_GenericBinaryFunction", "long_name": "PyArray_GenericBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", "filename": "arrayobject.c", "nloc": 12, "complexity": 2, "token_count": 69, "parameters": [ "m1", "m2", "op" ], "start_line": 2112, "end_line": 2123, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_GenericUnaryFunction", "long_name": "PyArray_GenericUnaryFunction( PyArrayObject * m1 , PyObject * op)", "filename": "arrayobject.c", "nloc": 12, "complexity": 2, "token_count": 63, "parameters": [ "m1", "op" ], "start_line": 2126, "end_line": 2137, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_GenericInplaceBinaryFunction", "long_name": "PyArray_GenericInplaceBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", "filename": "arrayobject.c", "nloc": 13, "complexity": 2, "token_count": 71, "parameters": [ "m1", "m2", "op" ], "start_line": 2140, "end_line": 2152, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 2155, "end_line": 2158, "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": 2161, "end_line": 2164, "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": 2167, "end_line": 2170, "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": 2173, "end_line": 2176, "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": 2179, "end_line": 2182, "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": 2185, "end_line": 2188, "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": 2191, "end_line": 2194, "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": 2197, "end_line": 2200, "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": 2203, "end_line": 2206, "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": 2209, "end_line": 2212, "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": 2215, "end_line": 2218, "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": 2221, "end_line": 2224, "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": 2227, "end_line": 2230, "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": 2233, "end_line": 2236, "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": 2239, "end_line": 2242, "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": 2245, "end_line": 2248, "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": 2251, "end_line": 2254, "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": 2257, "end_line": 2260, "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": 2263, "end_line": 2266, "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": 2269, "end_line": 2272, "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": 2275, "end_line": 2278, "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": 2281, "end_line": 2284, "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": 2287, "end_line": 2290, "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": 2293, "end_line": 2296, "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": 2299, "end_line": 2302, "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": 2305, "end_line": 2308, "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": 2311, "end_line": 2314, "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": 2317, "end_line": 2321, "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": 2324, "end_line": 2328, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "array_all_nonzero", "long_name": "array_all_nonzero( PyArrayObject * mp)", "filename": "arrayobject.c", "nloc": 18, "complexity": 4, "token_count": 93, "parameters": [ "mp" ], "start_line": 2332, "end_line": 2350, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "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": 2353, "end_line": 2368, "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": 143, "parameters": [ "v" ], "start_line": 2372, "end_line": 2398, "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": 143, "parameters": [ "v" ], "start_line": 2401, "end_line": 2426, "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": 124, "parameters": [ "v" ], "start_line": 2429, "end_line": 2451, "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": 124, "parameters": [ "v" ], "start_line": 2454, "end_line": 2476, "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": 124, "parameters": [ "v" ], "start_line": 2479, "end_line": 2501, "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": 2504, "end_line": 2508, "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": 34, "complexity": 11, "token_count": 258, "parameters": [ "self", "ilow", "ihigh" ], "start_line": 2569, "end_line": 2607, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "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": 2611, "end_line": 2632, "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": 4, "complexity": 1, "token_count": 26, "parameters": [ "self", "el" ], "start_line": 2635, "end_line": 2640, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "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": 308, "parameters": [ "string", "n", "max_n", "data", "nd", "dimensions", "strides", "self" ], "start_line": 2661, "end_line": 2708, "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": 222, "parameters": [ "self" ], "start_line": 2711, "end_line": 2747, "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": 2753, "end_line": 2770, "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": 2773, "end_line": 2785, "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": 2788, "end_line": 2800, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "array_richcompare", "long_name": "array_richcompare( PyArrayObject * self , PyObject * other , int cmp_op)", "filename": "arrayobject.c", "nloc": 61, "complexity": 13, "token_count": 273, "parameters": [ "self", "other", "cmp_op" ], "start_line": 2804, "end_line": 2881, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 78, "top_nesting_level": 0 }, { "name": "_check_axis", "long_name": "_check_axis( PyArrayObject * arr , int * axis , int flags)", "filename": "arrayobject.c", "nloc": 29, "complexity": 8, "token_count": 164, "parameters": [ "arr", "axis", "flags" ], "start_line": 2884, "end_line": 2913, "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": 17, "complexity": 4, "token_count": 91, "parameters": [ "len", "vals" ], "start_line": 2919, "end_line": 2935, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "PyArray_IntpFromSequence", "long_name": "PyArray_IntpFromSequence( PyObject * seq , intp * vals , int maxvals)", "filename": "arrayobject.c", "nloc": 21, "complexity": 7, "token_count": 161, "parameters": [ "seq", "vals", "maxvals" ], "start_line": 2940, "end_line": 2963, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "_IsContiguous", "long_name": "_IsContiguous( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 14, "complexity": 6, "token_count": 109, "parameters": [ "ap" ], "start_line": 2969, "end_line": 2985, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_IsFortranContiguous", "long_name": "_IsFortranContiguous( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 14, "complexity": 6, "token_count": 107, "parameters": [ "ap" ], "start_line": 2989, "end_line": 3005, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_IsAligned", "long_name": "_IsAligned( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 14, "complexity": 4, "token_count": 110, "parameters": [ "ap" ], "start_line": 3008, "end_line": 3024, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "_IsWriteable", "long_name": "_IsWriteable( PyArrayObject * ap)", "filename": "arrayobject.c", "nloc": 16, "complexity": 8, "token_count": 109, "parameters": [ "ap" ], "start_line": 3027, "end_line": 3060, "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": 22, "complexity": 9, "token_count": 129, "parameters": [ "ret", "flagmask" ], "start_line": 3064, "end_line": 3086, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "PyArray_CheckStrides", "long_name": "PyArray_CheckStrides( int elsize , int nd , intp numbytes , intp * dims , intp * newstrides)", "filename": "arrayobject.c", "nloc": 13, "complexity": 4, "token_count": 84, "parameters": [ "elsize", "nd", "numbytes", "dims", "newstrides" ], "start_line": 3093, "end_line": 3108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "_array_fill_strides", "long_name": "_array_fill_strides( intp * strides , intp * dims , int nd , intp itemsize , int inflag , int * objflags)", "filename": "arrayobject.c", "nloc": 24, "complexity": 9, "token_count": 171, "parameters": [ "strides", "dims", "nd", "itemsize", "inflag", "objflags" ], "start_line": 3128, "end_line": 3152, "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 , char * data , int itemsize , int flags , PyObject * obj)", "filename": "arrayobject.c", "nloc": 117, "complexity": 27, "token_count": 713, "parameters": [ "subtype", "nd", "dims", "type_num", "strides", "data", "itemsize", "flags", "obj" ], "start_line": 3156, "end_line": 3306, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 151, "top_nesting_level": 0 }, { "name": "PyArray_Resize", "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape)", "filename": "arrayobject.c", "nloc": 87, "complexity": 15, "token_count": 501, "parameters": [ "self", "newshape" ], "start_line": 3311, "end_line": 3416, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 106, "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": 3421, "end_line": 3438, "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": 47, "complexity": 7, "token_count": 261, "parameters": [ "arr", "obj" ], "start_line": 3441, "end_line": 3493, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "top_nesting_level": 0 }, { "name": "array_new", "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", "filename": "arrayobject.c", "nloc": 100, "complexity": 20, "token_count": 589, "parameters": [ "subtype", "args", "kwds" ], "start_line": 3496, "end_line": 3611, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 116, "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": 3618, "end_line": 3621, "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": 10, "complexity": 3, "token_count": 57, "parameters": [ "self" ], "start_line": 3624, "end_line": 3634, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "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": 3707, "end_line": 3710, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "array_shape_set", "long_name": "array_shape_set( PyArrayObject * self , PyObject * val)", "filename": "arrayobject.c", "nloc": 33, "complexity": 6, "token_count": 206, "parameters": [ "self", "val" ], "start_line": 3714, "end_line": 3748, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "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": 3752, "end_line": 3755, "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": 32, "complexity": 7, "token_count": 209, "parameters": [ "self", "obj" ], "start_line": 3758, "end_line": 3791, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "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": 3795, "end_line": 3802, "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": 3805, "end_line": 3813, "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": 3817, "end_line": 3823, "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": 3826, "end_line": 3840, "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": 3843, "end_line": 3887, "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": 19, "parameters": [ "self" ], "start_line": 3891, "end_line": 3894, "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": 8, "complexity": 3, "token_count": 42, "parameters": [ "self" ], "start_line": 3897, "end_line": 3904, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "array_typechar_get", "long_name": "array_typechar_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 8, "complexity": 2, "token_count": 47, "parameters": [ "self" ], "start_line": 3908, "end_line": 3915, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "array_typestr_get", "long_name": "array_typestr_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 19, "complexity": 7, "token_count": 141, "parameters": [ "self" ], "start_line": 3918, "end_line": 3938, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "array_descr_get", "long_name": "array_descr_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 19, "complexity": 5, "token_count": 128, "parameters": [ "self" ], "start_line": 3941, "end_line": 3963, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "array_type_get", "long_name": "array_type_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 4, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 3967, "end_line": 3970, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "array_type_set", "long_name": "array_type_set( PyArrayObject * self , PyObject * arg)", "filename": "arrayobject.c", "nloc": 41, "complexity": 10, "token_count": 294, "parameters": [ "self", "arg" ], "start_line": 3982, "end_line": 4040, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 59, "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": 4045, "end_line": 4055, "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": 4059, "end_line": 4084, "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": 31, "complexity": 4, "token_count": 177, "parameters": [ "self", "val" ], "start_line": 4088, "end_line": 4120, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "array_imag_get", "long_name": "array_imag_get( PyArrayObject * self)", "filename": "arrayobject.c", "nloc": 34, "complexity": 3, "token_count": 200, "parameters": [ "self" ], "start_line": 4123, "end_line": 4158, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "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": 203, "parameters": [ "self", "val" ], "start_line": 4161, "end_line": 4198, "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": 4201, "end_line": 4204, "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": 51, "complexity": 9, "token_count": 368, "parameters": [ "self", "val" ], "start_line": 4207, "end_line": 4261, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 55, "top_nesting_level": 0 }, { "name": "discover_depth", "long_name": "discover_depth( PyObject * s , int max , int stop_at_string)", "filename": "arrayobject.c", "nloc": 23, "complexity": 14, "token_count": 169, "parameters": [ "s", "max", "stop_at_string" ], "start_line": 4436, "end_line": 4461, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "discover_itemsize", "long_name": "discover_itemsize( PyObject * s , int nd , int * itemsize)", "filename": "arrayobject.c", "nloc": 21, "complexity": 9, "token_count": 161, "parameters": [ "s", "nd", "itemsize" ], "start_line": 4464, "end_line": 4486, "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": 4493, "end_line": 4519, "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( int chktype , int mintype , int chksize , int minsize , PyArray_Typecode * outtype)", "filename": "arrayobject.c", "nloc": 19, "complexity": 5, "token_count": 100, "parameters": [ "chktype", "mintype", "chksize", "minsize", "outtype" ], "start_line": 4522, "end_line": 4542, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "_array_find_type", "long_name": "_array_find_type( PyObject * op , PyArray_Typecode * minitype , PyArray_Typecode * outtype , int max)", "filename": "arrayobject.c", "nloc": 126, "complexity": 28, "token_count": 671, "parameters": [ "op", "minitype", "outtype", "max" ], "start_line": 4545, "end_line": 4686, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 142, "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": 4689, "end_line": 4712, "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_Typecode * typecode)", "filename": "arrayobject.c", "nloc": 21, "complexity": 5, "token_count": 132, "parameters": [ "op", "typecode" ], "start_line": 4716, "end_line": 4742, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 0 }, { "name": "Array_FromSequence", "long_name": "Array_FromSequence( PyObject * s , PyArray_Typecode * typecode , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 51, "complexity": 17, "token_count": 313, "parameters": [ "s", "typecode", "min_depth", "max_depth" ], "start_line": 4746, "end_line": 4803, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 58, "top_nesting_level": 0 }, { "name": "PyArray_ValidType", "long_name": "PyArray_ValidType( int type)", "filename": "arrayobject.c", "nloc": 7, "complexity": 2, "token_count": 30, "parameters": [ "type" ], "start_line": 4807, "end_line": 4814, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "_bufferedcast", "long_name": "_bufferedcast( PyArrayObject * out , PyArrayObject * in)", "filename": "arrayobject.c", "nloc": 75, "complexity": 16, "token_count": 477, "parameters": [ "out", "in" ], "start_line": 4820, "end_line": 4910, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 91, "top_nesting_level": 0 }, { "name": "PyArray_Cast", "long_name": "PyArray_Cast( PyArrayObject * mp , int type_num)", "filename": "arrayobject.c", "nloc": 10, "complexity": 1, "token_count": 56, "parameters": [ "mp", "type_num" ], "start_line": 4916, "end_line": 4927, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "PyArray_CastToType", "long_name": "PyArray_CastToType( PyArrayObject * mp , PyArray_Typecode * at)", "filename": "arrayobject.c", "nloc": 31, "complexity": 13, "token_count": 233, "parameters": [ "mp", "at" ], "start_line": 4930, "end_line": 4965, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "PyArray_CastTo", "long_name": "PyArray_CastTo( PyArrayObject * out , PyArrayObject * mp)", "filename": "arrayobject.c", "nloc": 40, "complexity": 10, "token_count": 214, "parameters": [ "out", "mp" ], "start_line": 4972, "end_line": 5018, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "array_fromarray", "long_name": "array_fromarray( PyArrayObject * arr , PyArray_Typecode * typecode , int flags)", "filename": "arrayobject.c", "nloc": 116, "complexity": 35, "token_count": 721, "parameters": [ "arr", "typecode", "flags" ], "start_line": 5021, "end_line": 5152, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 132, "top_nesting_level": 0 }, { "name": "_array_typecode_fromstr", "long_name": "_array_typecode_fromstr( char * str , int * swap , PyArray_Typecode * type)", "filename": "arrayobject.c", "nloc": 94, "complexity": 36, "token_count": 533, "parameters": [ "str", "swap", "type" ], "start_line": 5156, "end_line": 5261, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 106, "top_nesting_level": 0 }, { "name": "array_frominterface", "long_name": "array_frominterface( PyObject * input , PyArray_Typecode * intype , int flags)", "filename": "arrayobject.c", "nloc": 113, "complexity": 26, "token_count": 715, "parameters": [ "input", "intype", "flags" ], "start_line": 5264, "end_line": 5387, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 124, "top_nesting_level": 0 }, { "name": "array_fromattr", "long_name": "array_fromattr( PyObject * op , PyArray_Typecode * typecode , int flags)", "filename": "arrayobject.c", "nloc": 30, "complexity": 5, "token_count": 181, "parameters": [ "op", "typecode", "flags" ], "start_line": 5390, "end_line": 5421, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "array_fromobject", "long_name": "array_fromobject( PyObject * op , PyArray_Typecode * typecode , int min_depth , int max_depth , int flags)", "filename": "arrayobject.c", "nloc": 49, "complexity": 14, "token_count": 291, "parameters": [ "op", "typecode", "min_depth", "max_depth", "flags" ], "start_line": 5425, "end_line": 5490, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 66, "top_nesting_level": 0 }, { "name": "PyArray_ArrayType", "long_name": "PyArray_ArrayType( PyObject * op , PyArray_Typecode * intype , PyArray_Typecode * outtype)", "filename": "arrayobject.c", "nloc": 6, "complexity": 1, "token_count": 29, "parameters": [ "op", "intype", "outtype" ], "start_line": 5493, "end_line": 5498, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "PyArray_ObjectType", "long_name": "PyArray_ObjectType( PyObject * op , int minimum_type)", "filename": "arrayobject.c", "nloc": 7, "complexity": 1, "token_count": 40, "parameters": [ "op", "minimum_type" ], "start_line": 5501, "end_line": 5507, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "PyArray_FromAny", "long_name": "PyArray_FromAny( PyObject * op , PyArray_Typecode * typecode , int min_depth , int max_depth , int requires)", "filename": "arrayobject.c", "nloc": 24, "complexity": 9, "token_count": 165, "parameters": [ "op", "typecode", "min_depth", "max_depth", "requires" ], "start_line": 5561, "end_line": 5591, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "PyArray_EnsureArray", "long_name": "PyArray_EnsureArray( PyObject * op)", "filename": "arrayobject.c", "nloc": 14, "complexity": 5, "token_count": 87, "parameters": [ "op" ], "start_line": 5602, "end_line": 5618, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "PyArray_FromObject", "long_name": "PyArray_FromObject( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 7, "complexity": 1, "token_count": 51, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5624, "end_line": 5630, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "PyArray_ContiguousFromObject", "long_name": "PyArray_ContiguousFromObject( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 8, "complexity": 1, "token_count": 51, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5633, "end_line": 5640, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_CopyFromObject", "long_name": "PyArray_CopyFromObject( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 8, "complexity": 1, "token_count": 51, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5643, "end_line": 5650, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_ContiguousFromAny", "long_name": "PyArray_ContiguousFromAny( PyObject * op , int type , int min_depth , int max_depth)", "filename": "arrayobject.c", "nloc": 8, "complexity": 1, "token_count": 49, "parameters": [ "op", "type", "min_depth", "max_depth" ], "start_line": 5655, "end_line": 5662, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "PyArray_CanCastSafely", "long_name": "PyArray_CanCastSafely( int fromtype , int totype)", "filename": "arrayobject.c", "nloc": 81, "complexity": 39, "token_count": 476, "parameters": [ "fromtype", "totype" ], "start_line": 5665, "end_line": 5748, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 84, "top_nesting_level": 0 }, { "name": "PyArray_CanCastTo", "long_name": "PyArray_CanCastTo( PyArray_Typecode * from , PyArray_Typecode * to)", "filename": "arrayobject.c", "nloc": 24, "complexity": 7, "token_count": 134, "parameters": [ "from", "to" ], "start_line": 5751, "end_line": 5775, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 }, { "name": "PyArray_IterNew", "long_name": "PyArray_IterNew( PyObject * obj)", "filename": "arrayobject.c", "nloc": 34, "complexity": 6, "token_count": 258, "parameters": [ "obj" ], "start_line": 5785, "end_line": 5822, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "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": 5827, "end_line": 5837, "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": 6, "complexity": 1, "token_count": 25, "parameters": [ "it" ], "start_line": 5840, "end_line": 5845, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "arrayiter_traverse", "long_name": "arrayiter_traverse( PyArrayIterObject * it , visitproc visit , * arg)", "filename": "arrayobject.c", "nloc": 6, "complexity": 2, "token_count": 42, "parameters": [ "it", "visit", "arg" ], "start_line": 5848, "end_line": 5853, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "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": 5857, "end_line": 5860, "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": 42, "complexity": 7, "token_count": 272, "parameters": [ "self", "ind" ], "start_line": 5864, "end_line": 5912, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "iter_subscript_int", "long_name": "iter_subscript_int( PyArrayIterObject * self , PyArrayObject * ind)", "filename": "arrayobject.c", "nloc": 51, "complexity": 8, "token_count": 347, "parameters": [ "self", "ind" ], "start_line": 5915, "end_line": 5968, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 0 }, { "name": "iter_subscript", "long_name": "iter_subscript( PyArrayIterObject * self , PyObject * ind)", "filename": "arrayobject.c", "nloc": 97, "complexity": 20, "token_count": 593, "parameters": [ "self", "ind" ], "start_line": 5972, "end_line": 6091, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 120, "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": 176, "parameters": [ "self", "ind", "val", "swap" ], "start_line": 6095, "end_line": 6127, "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": 289, "parameters": [ "self", "ind", "val", "swap" ], "start_line": 6130, "end_line": 6172, "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": 103, "complexity": 24, "token_count": 636, "parameters": [ "self", "ind", "val" ], "start_line": 6176, "end_line": 6298, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 123, "top_nesting_level": 0 }, { "name": "iter_array", "long_name": "iter_array( PyArrayIterObject * it , PyObject * op)", "filename": "arrayobject.c", "nloc": 30, "complexity": 5, "token_count": 221, "parameters": [ "it", "op" ], "start_line": 6311, "end_line": 6353, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "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": 6358, "end_line": 6362, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "fancy_indexing_check", "long_name": "fancy_indexing_check( PyObject * args)", "filename": "arrayobject.c", "nloc": 55, "complexity": 22, "token_count": 293, "parameters": [ "args" ], "start_line": 6427, "end_line": 6488, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 62, "top_nesting_level": 0 }, { "name": "_convert_obj", "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", "filename": "arrayobject.c", "nloc": 15, "complexity": 5, "token_count": 105, "parameters": [ "obj", "iter" ], "start_line": 6496, "end_line": 6511, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "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": 6517, "end_line": 6586, "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": 261, "parameters": [ "mit" ], "start_line": 6590, "end_line": 6627, "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": 296, "parameters": [ "mit" ], "start_line": 6633, "end_line": 6677, "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": 102, "complexity": 22, "token_count": 690, "parameters": [ "mit", "arr" ], "start_line": 6695, "end_line": 6831, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 137, "top_nesting_level": 0 }, { "name": "_nonzero_indices", "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", "filename": "arrayobject.c", "nloc": 57, "complexity": 15, "token_count": 454, "parameters": [ "myBool", "iters" ], "start_line": 6837, "end_line": 6906, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 70, "top_nesting_level": 0 }, { "name": "PyArray_MapIterNew", "long_name": "PyArray_MapIterNew( PyObject * indexobj)", "filename": "arrayobject.c", "nloc": 111, "complexity": 24, "token_count": 745, "parameters": [ "indexobj" ], "start_line": 6909, "end_line": 7042, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 134, "top_nesting_level": 0 }, { "name": "arraymapiter_new", "long_name": "arraymapiter_new( PyTypeObject * type , PyObject * args , PyObject * kwds)", "filename": "arrayobject.c", "nloc": 26, "complexity": 5, "token_count": 130, "parameters": [ "type", "args", "kwds" ], "start_line": 7048, "end_line": 7078, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "arraymapiter_dealloc", "long_name": "arraymapiter_dealloc( PyArrayMapIterObject * mit)", "filename": "arrayobject.c", "nloc": 10, "complexity": 2, "token_count": 60, "parameters": [ "mit" ], "start_line": 7099, "end_line": 7108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "arraymapiter_traverse", "long_name": "arraymapiter_traverse( PyArrayMapIterObject * mit , visitproc visit , * arg)", "filename": "arrayobject.c", "nloc": 16, "complexity": 9, "token_count": 146, "parameters": [ "mit", "visit", "arg" ], "start_line": 7111, "end_line": 7129, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "index2ptr", "long_name": "index2ptr( PyArrayObject * mp , intp i)", "filename": "arrayobject.c", "nloc": 15, "complexity": 7, "token_count": 98, "parameters": [ "mp", "i" ], "start_line": 570, "end_line": 585, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 } ], "nloc": 5655, "complexity": 1234, "token_count": 33763, "diff_parsed": { "added": [ "\tif(mp->nd == 0) {", "\t\tPyErr_SetString(PyExc_IndexError,", "\t\t\t\t\"0-d arrays can't be indexed\");", "\t\treturn NULL;", "\t}", "\tif (i==0 && mp->dimensions[0] > 0)" ], "deleted": [ "\tif (i==0 && (mp->nd == 0 || mp->dimensions[0] > 0))" ] } } ] } ]